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