contrib_bots: Expose some information about user profile

- Expose some information about user profile in `RestrictedClient`
class, like `full_name` and `email` of the user.

- Add `client` argument to `triage_message()`, now it's possible to
call bot with another method instead of calling the specified
keyword.
This commit is contained in:
Rafid Aslam 2016-12-15 14:38:39 +07:00 committed by showell
parent 6df2450b60
commit 8d35f25fd6
10 changed files with 20 additions and 11 deletions

View file

@ -18,7 +18,15 @@ from zulip import Client
class RestrictedClient(object):
def __init__(self, client):
# Only expose a subset of our Client's functionality
user_profile = client.get_profile()
self.send_message = client.send_message
try:
self.full_name = user_profile['full_name']
self.email = user_profile['email']
except KeyError:
logging.error('Cannot fetch user profile, make sure you have set'
' up the zuliprc file correctly.')
sys.exit(1)
def get_lib_module(lib_fn):
lib_fn = os.path.abspath(lib_fn)
@ -60,7 +68,8 @@ def run_message_handler_for_bot(lib_module, quiet, config_file):
def handle_message(message):
logging.info('waiting for next message')
if message_handler.triage_message(message=message):
if message_handler.triage_message(message=message,
client=restricted_client):
message_handler.handle_message(
message=message,
client=restricted_client,