From b406150a5643deec270a2b44b950016468f98ad2 Mon Sep 17 00:00:00 2001 From: Abhijeet Kaur Date: Thu, 8 Jun 2017 08:19:42 +0530 Subject: [PATCH] bots: Rename BotHandlerApi class to ExternalBotHandler. This change is done for better understanding of the class functionality from its class name. Now there will be 3 different classes for bots, namely 'ExternalBotHandler', 'FlaskBotHandler' and 'EmbeddedBotHandler'. --- bots_api/bot_lib.py | 8 ++++---- bots_api/bots_test_lib.py | 4 ++-- flask_bot_server.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bots_api/bot_lib.py b/bots_api/bot_lib.py index 51dc7bb..6b124b0 100644 --- a/bots_api/bot_lib.py +++ b/bots_api/bot_lib.py @@ -51,7 +51,7 @@ class RateLimit(object): sys.exit(1) -class BotHandlerApi(object): +class ExternalBotHandler(object): def __init__(self, client): # type: (Client) -> None # Only expose a subset of our Client's functionality @@ -129,7 +129,7 @@ def run_message_handler_for_bot(lib_module, quiet, config_file): # # Make sure you set up your ~/.zuliprc client = Client(config_file=config_file) - restricted_client = BotHandlerApi(client) + restricted_client = ExternalBotHandler(client) message_handler = lib_module.handler_class() if hasattr(message_handler, 'initialize'): @@ -141,7 +141,7 @@ def run_message_handler_for_bot(lib_module, quiet, config_file): print(message_handler.usage()) def extract_query_without_mention(message, client): - # type: (Dict[str, Any], BotHandlerApi) -> str + # type: (Dict[str, Any], ExternalBotHandler) -> str """ If the bot is the first @mention in the message, then this function returns the message with the bot's @mention removed. Otherwise, it returns None. @@ -154,7 +154,7 @@ def run_message_handler_for_bot(lib_module, quiet, config_file): return query_without_mention.lstrip() def is_private(message, client): - # type: (Dict[str, Any], BotHandlerApi) -> bool + # type: (Dict[str, Any], ExternalBotHandler) -> bool # bot will not reply if the sender name is the same as the bot name # to prevent infinite loop if message['type'] == 'private': diff --git a/bots_api/bots_test_lib.py b/bots_api/bots_test_lib.py index e9e552b..3572f24 100644 --- a/bots_api/bots_test_lib.py +++ b/bots_api/bots_test_lib.py @@ -43,8 +43,8 @@ class BotTestCase(TestCase): def setUp(self): # type: () -> None - # Mocking BotHandlerApi - self.patcher = patch('bots_api.bot_lib.BotHandlerApi') + # Mocking ExternalBotHandler + self.patcher = patch('bots_api.bot_lib.ExternalBotHandler') self.MockClass = self.patcher.start() self.message_handler = self.get_bot_message_handler() diff --git a/flask_bot_server.py b/flask_bot_server.py index 580fe6d..310bcc1 100644 --- a/flask_bot_server.py +++ b/flask_bot_server.py @@ -15,7 +15,7 @@ if os.path.exists(os.path.join(our_dir, '../api/zulip')): from zulip import Client from bots_api.run import get_lib_module -from bots_api.bot_lib import BotHandlerApi, StateHandler +from bots_api.bot_lib import ExternalBotHandler, StateHandler bots_config = {} # type: Dict[str, Mapping[str, str]] available_bots = [] # type: List[str] @@ -50,7 +50,7 @@ def handle_bot(bot): client = Client(email=bots_config[bot]["email"], api_key=bots_config[bot]["key"], site=bots_config[bot]["site"]) - restricted_client = BotHandlerApi(client) + restricted_client = ExternalBotHandler(client) message_handler = bots_lib_module[bot].handler_class() # TODO: Handle stateful bots properly.