botserver: Make handle_bot logic more concise.
MODIFY
zulip_botserver/zulip_botserver/server.py
zulip_botserver/zulip_botserver/server.py
@@ -104,15 +104,14 @@ bots_config = {} # type: Dict[str, Dict[str, str]]
@app.route('/', methods=['POST'])
def handle_bot() -> Union[str, BadRequest]:
event = request.get_json(force=True)
- bot = None
for bot_name, config in bots_config.items():
if config['email'] == event['bot_email']:
bot = bot_name
- if bot is None:
+ break
+ else:
return BadRequest("Cannot find a bot with email {} in the bot server "
"configuration file. Do the emails in your flaskbotrc "
"match the bot emails on the server?".format(event['bot_email']))
- else:
lib_module = app.config.get("BOTS_LIB_MODULES", {})[bot]
bot_handler = app.config.get("BOT_HANDLERS", {})[bot]
message_handler = app.config.get("MESSAGE_HANDLERS", {})[bot]

botserver: Make handle_bot logic more concise.