botserver: Remove redundant message check.
Previously, the botserver `handle_bot` routine did two checks on an incoming message: * First, it checked if the bot email matches an email in the flaskbotrc. * Second, it checked if the bot name that corresponds to an email has a lib module loaded. However, this must be the case, because all lib modules for all emails are loaded on initialization. Thus, this commit removes the second check.
This commit is contained in:
parent
5c062cee0d
commit
f1bcf3b9a4
|
@ -56,10 +56,18 @@ class BotServerTests(BotServerTestCase):
|
||||||
bots_config=bots_config,
|
bots_config=bots_config,
|
||||||
check_success=True)
|
check_success=True)
|
||||||
|
|
||||||
def test_bot_module_not_exists(self) -> None:
|
def test_request_for_unkown_bot(self) -> None:
|
||||||
self.assert_bot_server_response(available_bots=[],
|
bots_config = {
|
||||||
|
'helloworld': {
|
||||||
|
'email': 'helloworld-bot@zulip.com',
|
||||||
|
'key': '123456789qwertyuiop',
|
||||||
|
'site': 'http://localhost',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
self.assert_bot_server_response(available_bots=['helloworld'],
|
||||||
event=dict(message={'content': "test message"},
|
event=dict(message={'content': "test message"},
|
||||||
bot_email='nonexistent-bot@zulip.com'),
|
bot_email='unknown-bot@zulip.com'),
|
||||||
|
bots_config=bots_config,
|
||||||
check_success=False)
|
check_success=False)
|
||||||
|
|
||||||
@mock.patch('logging.error')
|
@mock.patch('logging.error')
|
||||||
|
|
|
@ -116,10 +116,6 @@ def handle_bot() -> Union[str, BadRequest]:
|
||||||
lib_module = app.config.get("BOTS_LIB_MODULES", {}).get(bot)
|
lib_module = app.config.get("BOTS_LIB_MODULES", {}).get(bot)
|
||||||
bot_handler = app.config.get("BOT_HANDLERS", {}).get(bot)
|
bot_handler = app.config.get("BOT_HANDLERS", {}).get(bot)
|
||||||
message_handler = app.config.get("MESSAGE_HANDLERS", {}).get(bot)
|
message_handler = app.config.get("MESSAGE_HANDLERS", {}).get(bot)
|
||||||
if lib_module is None:
|
|
||||||
return BadRequest("Can't find the configuration or Bot Handler code for bot {}. "
|
|
||||||
"Make sure that the `zulip_bots` package is installed, and "
|
|
||||||
"that your flaskbotrc is set up correctly".format(bot))
|
|
||||||
|
|
||||||
message_handler.handle_message(message=event["message"], bot_handler=bot_handler)
|
message_handler.handle_message(message=event["message"], bot_handler=bot_handler)
|
||||||
return json.dumps("")
|
return json.dumps("")
|
||||||
|
|
Loading…
Reference in a new issue