botserver: Make handle_bot logic more concise.

This commit is contained in:
Robert Hönig 2018-05-29 10:03:59 +02:00
parent e6ef34a964
commit 3859bef05f

View file

@ -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]