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'.
This commit is contained in:
Abhijeet Kaur 2017-06-08 08:19:42 +05:30 committed by showell
parent 08b4ebf597
commit b406150a56
3 changed files with 8 additions and 8 deletions

View file

@ -51,7 +51,7 @@ class RateLimit(object):
sys.exit(1) sys.exit(1)
class BotHandlerApi(object): class ExternalBotHandler(object):
def __init__(self, client): def __init__(self, client):
# type: (Client) -> None # type: (Client) -> None
# Only expose a subset of our Client's functionality # 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 # Make sure you set up your ~/.zuliprc
client = Client(config_file=config_file) client = Client(config_file=config_file)
restricted_client = BotHandlerApi(client) restricted_client = ExternalBotHandler(client)
message_handler = lib_module.handler_class() message_handler = lib_module.handler_class()
if hasattr(message_handler, 'initialize'): if hasattr(message_handler, 'initialize'):
@ -141,7 +141,7 @@ def run_message_handler_for_bot(lib_module, quiet, config_file):
print(message_handler.usage()) print(message_handler.usage())
def extract_query_without_mention(message, client): 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 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. 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() return query_without_mention.lstrip()
def is_private(message, client): 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 # bot will not reply if the sender name is the same as the bot name
# to prevent infinite loop # to prevent infinite loop
if message['type'] == 'private': if message['type'] == 'private':

View file

@ -43,8 +43,8 @@ class BotTestCase(TestCase):
def setUp(self): def setUp(self):
# type: () -> None # type: () -> None
# Mocking BotHandlerApi # Mocking ExternalBotHandler
self.patcher = patch('bots_api.bot_lib.BotHandlerApi') self.patcher = patch('bots_api.bot_lib.ExternalBotHandler')
self.MockClass = self.patcher.start() self.MockClass = self.patcher.start()
self.message_handler = self.get_bot_message_handler() self.message_handler = self.get_bot_message_handler()

View file

@ -15,7 +15,7 @@ if os.path.exists(os.path.join(our_dir, '../api/zulip')):
from zulip import Client from zulip import Client
from bots_api.run import get_lib_module 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]] bots_config = {} # type: Dict[str, Mapping[str, str]]
available_bots = [] # type: List[str] available_bots = [] # type: List[str]
@ -50,7 +50,7 @@ def handle_bot(bot):
client = Client(email=bots_config[bot]["email"], client = Client(email=bots_config[bot]["email"],
api_key=bots_config[bot]["key"], api_key=bots_config[bot]["key"],
site=bots_config[bot]["site"]) site=bots_config[bot]["site"])
restricted_client = BotHandlerApi(client) restricted_client = ExternalBotHandler(client)
message_handler = bots_lib_module[bot].handler_class() message_handler = bots_lib_module[bot].handler_class()
# TODO: Handle stateful bots properly. # TODO: Handle stateful bots properly.