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 d45d9c9ab5
commit 68777e93a0
4 changed files with 11 additions and 11 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.

View File

@@ -6,7 +6,7 @@ import sys
import os import os
sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../api'))) sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../api')))
from bots_api.bot_lib import BotHandlerApi, StateHandler from bots_api.bot_lib import ExternalBotHandler, StateHandler
from django.conf import settings from django.conf import settings
from django.core.handlers.wsgi import WSGIRequest from django.core.handlers.wsgi import WSGIRequest
from django.core.handlers.base import BaseHandler from django.core.handlers.base import BaseHandler
@@ -455,12 +455,12 @@ class OutgoingWebhookWorker(QueueProcessingWorker):
class EmbeddedBotWorker(QueueProcessingWorker): class EmbeddedBotWorker(QueueProcessingWorker):
def get_bot_api_client(self, user_profile): def get_bot_api_client(self, user_profile):
# type: (UserProfile) -> BotHandlerApi # type: (UserProfile) -> ExternalBotHandler
raw_client = Client( raw_client = Client(
email=str(user_profile.email), email=str(user_profile.email),
api_key=str(user_profile.api_key), api_key=str(user_profile.api_key),
site=str(user_profile.realm.uri)) site=str(user_profile.realm.uri))
return BotHandlerApi(raw_client) return ExternalBotHandler(raw_client)
def get_bot_handler(self, service): def get_bot_handler(self, service):
# type: (Service) -> Any # type: (Service) -> Any