diff --git a/tools/test-bots b/tools/test-bots index f4400ce..7f27145 100755 --- a/tools/test-bots +++ b/tools/test-bots @@ -32,7 +32,7 @@ Running tests for all bots: Running tests for specific bots: -./test-bots define thesaurus +./test-bots define xkcd Running tests for all bots excluding certain bots (the following command would run tests for all bots except diff --git a/zulip_bots/setup.py b/zulip_bots/setup.py index 637abc3..9fd49b9 100755 --- a/zulip_bots/setup.py +++ b/zulip_bots/setup.py @@ -33,7 +33,6 @@ setuptools_info = dict( 'zulip>=0.3.1', 'mock>=2.0.0', 'html2text', # for bots/define - 'PyDictionary', # for bots/thesaurus ], ) diff --git a/zulip_bots/zulip_bots/bots/thesaurus/__init__.py b/zulip_bots/zulip_bots/bots/thesaurus/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/zulip_bots/zulip_bots/bots/thesaurus/requirements.txt b/zulip_bots/zulip_bots/bots/thesaurus/requirements.txt deleted file mode 100644 index d02d986..0000000 --- a/zulip_bots/zulip_bots/bots/thesaurus/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -PyDictionary diff --git a/zulip_bots/zulip_bots/bots/thesaurus/test_thesaurus.py b/zulip_bots/zulip_bots/bots/thesaurus/test_thesaurus.py deleted file mode 100755 index 9a4a8db..0000000 --- a/zulip_bots/zulip_bots/bots/thesaurus/test_thesaurus.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -from __future__ import absolute_import -from __future__ import print_function - -from zulip_bots.test_lib import BotTestCase - -class TestThesaurusBot(BotTestCase): - bot_name = "thesaurus" - - def test_bot(self): - expected = { - "synonym good": "great, satisfying, exceptional, positive, acceptable", - "synonym nice": "cordial, kind, good, okay, fair", - "synonym foo": "bar, thud, X, baz, corge", - "antonym dirty": "ordered, sterile, spotless, moral, clean", - "antonym bar": "loss, whole, advantage, aid, failure", - "": ("To use this bot, start messages with either " - "@mention-bot synonym (to get the synonyms of a given word) " - "or @mention-bot antonym (to get the antonyms of a given word). " - "Phrases are not accepted so only use single words " - "to search. For example you could search '@mention-bot synonym hello' " - "or '@mention-bot antonym goodbye'."), - } - self.check_expected_responses(expected) diff --git a/zulip_bots/zulip_bots/bots/thesaurus/thesaurus.py b/zulip_bots/zulip_bots/bots/thesaurus/thesaurus.py deleted file mode 100644 index 79cb720..0000000 --- a/zulip_bots/zulip_bots/bots/thesaurus/thesaurus.py +++ /dev/null @@ -1,67 +0,0 @@ -# See zulip/api/bots/readme.md for instructions on running this code. -from __future__ import print_function -import sys -import logging -from PyDictionary import PyDictionary as Dictionary - -#Uses Python's Dictionary module -# pip install PyDictionary - -def get_clean_response(m, method): - try: - response = method(m) - except Exception as e: - logging.exception(e) - return e - if isinstance(response, str): - return response - elif isinstance(response, list): - return ', '.join(response) - else: - return "Sorry, no result found! Please check the word." - -def get_thesaurus_result(original_content): - help_message = ("To use this bot, start messages with either " - "@mention-bot synonym (to get the synonyms of a given word) " - "or @mention-bot antonym (to get the antonyms of a given word). " - "Phrases are not accepted so only use single words " - "to search. For example you could search '@mention-bot synonym hello' " - "or '@mention-bot antonym goodbye'.") - query = original_content.strip().split(' ', 1) - if len(query) < 2: - return help_message - else: - search_keyword = query[1] - if original_content.startswith('synonym'): - result = get_clean_response(search_keyword, method = Dictionary.synonym) - elif original_content.startswith('antonym'): - result = get_clean_response(search_keyword, method = Dictionary.antonym) - else: - result = help_message - return result - -class ThesaurusHandler(object): - ''' - This plugin allows users to enter a word in zulip - and get synonyms, and antonyms, for that word sent - back to the context (stream or private) in which - it was sent. It looks for messages starting with - '@mention-bot synonym' or '@mention-bot @antonym'. - ''' - - def usage(self): - return ''' - This plugin will allow users to get both synonyms - and antonyms for a given word from zulip. To use this - plugin, users need to install the PyDictionary module - using 'pip install PyDictionary'.Use '@mention-bot synonym help' or - '@mention-bot antonym help' for more usage information. Users should - preface messages with @mention-bot synonym or @mention-bot antonym. - ''' - - def handle_message(self, message, bot_handler, state_handler): - original_content = message['content'].strip() - new_content = get_thesaurus_result(original_content) - bot_handler.send_reply(message, new_content) - -handler_class = ThesaurusHandler