bots: Add empty message support in Wikipedia bot.

This commit is contained in:
Krzysztof Krzysztof 2017-05-24 12:23:50 -07:00 committed by Tim Abbott
parent 6d2a82ee3c
commit 5bc719ebbb
1 changed files with 15 additions and 12 deletions

View File

@ -21,24 +21,27 @@ def get_clean_response(m, method):
return response return response
elif isinstance(response, list): elif isinstance(response, list):
return ', '.join(response) return ', '.join(response)
else:
return "Sorry, no result found! Please check the word."
def get_thesaurus_result(original_content): def get_thesaurus_result(original_content):
search_keyword = original_content.strip().split(' ', 1)[1] help_message = "To use this bot, start messages with either \
if search_keyword == 'help': @mention-bot synonym (to get the synonyms of a given word) \
help_message = "To use this bot, start messages with either \ or @mention-bot antonym (to get the antonyms of a given word). \
@mention-bot synonym (to get the synonyms of a given word) \ Phrases are not accepted so only use single words \
or @mention-bot antonym (to get the antonyms of a given word). \ to search. For example you could search '@mention-bot synonym hello' \
Phrases are not accepted so only use single words \ or '@mention-bot antonym goodbye'."
to search. For example you could search '@mention-bot synonym hello' \ query = original_content.strip().split(' ', 1)
or '@mention-bot antonym goodbye'." if len(query) < 2:
return help_message return help_message
elif original_content.startswith('synonym'): else:
search_keyword = query[1]
if original_content.startswith('synonym'):
result = get_clean_response(search_keyword, method = Dictionary.synonym) result = get_clean_response(search_keyword, method = Dictionary.synonym)
elif original_content.startswith('antonym'): elif original_content.startswith('antonym'):
result = get_clean_response(search_keyword, method = Dictionary.antonym) result = get_clean_response(search_keyword, method = Dictionary.antonym)
else:
if result is None: result = help_message
result = "Sorry, no result found! Please check the word."
return result return result
class ThesaurusHandler(object): class ThesaurusHandler(object):