diff --git a/contrib_bots/lib/commute_bot.py b/contrib_bots/lib/commute_bot.py index 8c77216..cdf03cf 100644 --- a/contrib_bots/lib/commute_bot.py +++ b/contrib_bots/lib/commute_bot.py @@ -75,7 +75,7 @@ class CommuteHandler(object): you can use the timezone bot. ''' - def triage_message(self, message): + def triage_message(self, message, client): # return True iff we want to (possibly) response to this message original_content = message['content'] # This next line of code is defensive, as we diff --git a/contrib_bots/lib/define_bot.py b/contrib_bots/lib/define_bot.py index 10bd3ee..269b7fc 100644 --- a/contrib_bots/lib/define_bot.py +++ b/contrib_bots/lib/define_bot.py @@ -21,7 +21,7 @@ class DefineHandler(object): messages with "@define". ''' - def triage_message(DefineHandler, message): + def triage_message(DefineHandler, message, client): # return True if we want to (possibly) response to this message original_content = message['content'] # This next line of code is defensive, as we diff --git a/contrib_bots/lib/followup.py b/contrib_bots/lib/followup.py index 9042ab4..b5413cd 100644 --- a/contrib_bots/lib/followup.py +++ b/contrib_bots/lib/followup.py @@ -22,7 +22,7 @@ class FollowupHandler(object): called "followup" that your API user can send to. ''' - def triage_message(self, message): + def triage_message(self, message, client): # return True iff we want to (possibly) response to this message original_content = message['content'] diff --git a/contrib_bots/lib/git_hub_comment.py b/contrib_bots/lib/git_hub_comment.py index 3f08e0b..8383b86 100644 --- a/contrib_bots/lib/git_hub_comment.py +++ b/contrib_bots/lib/git_hub_comment.py @@ -31,7 +31,7 @@ class GitHubHandler(object): '/////'. ''' - def triage_message(self, message): + def triage_message(self, message, client): # return True iff we want to (possibly) response to this message original_content = message['content'] diff --git a/contrib_bots/lib/github_issues.py b/contrib_bots/lib/github_issues.py index c8864fd..348b749 100644 --- a/contrib_bots/lib/github_issues.py +++ b/contrib_bots/lib/github_issues.py @@ -52,7 +52,7 @@ class IssueHandler(object): github_token (The personal access token for the github bot) ''' - def triage_message(self, message): + def triage_message(self, message, client): # return True if we want to (possibly) respond to this message original_content = message['content'] # This next line of code is defensive, as we diff --git a/contrib_bots/lib/help.py b/contrib_bots/lib/help.py index ad5982c..e29b6ec 100644 --- a/contrib_bots/lib/help.py +++ b/contrib_bots/lib/help.py @@ -11,7 +11,7 @@ class HelpHandler(object): your Zulip instance. ''' - def triage_message(self, message): + def triage_message(self, message, client): # return True if we think the message may be of interest original_content = message['content'] diff --git a/contrib_bots/lib/howdoi_bot.py b/contrib_bots/lib/howdoi_bot.py index 3eb78c0..ae30dfb 100644 --- a/contrib_bots/lib/howdoi_bot.py +++ b/contrib_bots/lib/howdoi_bot.py @@ -56,7 +56,7 @@ class HowdoiHandler(object): * @howdowe! OR @howdoi! > Full answer from SO ''' - def triage_message(self, message): + def triage_message(self, message, client): cmd_list = ['@howdowe', '@howdoi', '@howdowe!', '@howdoi!'] question = message['content'] diff --git a/contrib_bots/lib/virtual_fs.py b/contrib_bots/lib/virtual_fs.py index 7a116f9..21d1004 100644 --- a/contrib_bots/lib/virtual_fs.py +++ b/contrib_bots/lib/virtual_fs.py @@ -7,7 +7,7 @@ class VirtualFsHandler(object): def usage(self): return get_help() - def triage_message(self, message): + def triage_message(self, message, client): # return True iff we want to (possibly) response to this message if message['type'] != 'stream': return False @@ -16,7 +16,7 @@ class VirtualFsHandler(object): return original_content.startswith('fs ') def handle_message(self, message, client, state_handler): - assert self.triage_message(message) + assert self.triage_message(message, client) original_content = message['content'] command = original_content[len('fs '):] diff --git a/contrib_bots/lib/wikipedia.py b/contrib_bots/lib/wikipedia.py index 2fd0536..e980408 100644 --- a/contrib_bots/lib/wikipedia.py +++ b/contrib_bots/lib/wikipedia.py @@ -27,7 +27,7 @@ class WikipediaHandler(object): "@wiki". ''' - def triage_message(self, message): + def triage_message(self, message, client): # return True iff we want to (possibly) response to this message original_content = message['content'] diff --git a/contrib_bots/run.py b/contrib_bots/run.py index f351eda..384a5d4 100755 --- a/contrib_bots/run.py +++ b/contrib_bots/run.py @@ -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,