Remove triage_message() function from all the contrib-bots.

To make all bots consistent add shared function in bot_lib.py
to check if this bot is called. All bots respond to at-mention of
the bot instead of their specific names.
This commit is contained in:
Abhijeet Kaur 2017-02-17 03:26:32 +05:30 committed by showell
parent a87ae4b1c4
commit 9a8dc7c622
18 changed files with 134 additions and 281 deletions

View file

@ -7,7 +7,7 @@ import html2text
class DefineHandler(object):
'''
This plugin define a word that the user inputs. It
looks for messages starting with '@define'.
looks for messages starting with '@mention-bot'.
'''
DEFINITION_API_URL = 'https://owlbot.info/api/v1/dictionary/{}?format=json'
@ -18,28 +18,19 @@ class DefineHandler(object):
def usage(DefineHandler):
return '''
This plugin will allow users to define a word. Users should preface
messages with "@define".
messages with @mention-bot.
'''
def triage_message(DefineHandler, message, client):
original_content = message['content']
# This next line of code is defensive, as we
# never want to get into an infinite loop of posting follow
# ups for own follow ups!
is_define = original_content.startswith('@define')
return is_define
def _handle_definition(DefineHandler, original_content):
# Remove '@define' from the message and extract the rest of the message, the
# word to define.
split_content = original_content.split(' ')
# If there are more than one word (a phrase)
if len(split_content) > 2:
if len(split_content) > 1:
return DefineHandler.PHRASE_ERROR_MESSAGE
to_define = split_content[1].strip()
to_define = split_content[0].strip()
to_define_lower = to_define.lower()
# No word was entered.