|
@@ -1,5 +1,7 @@
|
|
|
import atexit
|
|
|
+import time
|
|
|
from logging.config import dictConfig
|
|
|
+from threading import Thread
|
|
|
|
|
|
from flask import Flask, request, render_template
|
|
|
|
|
@@ -57,25 +59,6 @@ def services():
|
|
|
return render_template("services.html", r=None)
|
|
|
|
|
|
|
|
|
-def run_command_and_respond(msg):
|
|
|
- response = rollbot.run_command(msg)
|
|
|
-
|
|
|
- if not response.respond:
|
|
|
- app.logger.info(f"Skipping response to message {msg.message_id}")
|
|
|
- return
|
|
|
-
|
|
|
- app.logger.info(f"Responding to message {msg.message_id}")
|
|
|
-
|
|
|
- bot_id = BOTS_LOOKUP[msg.group_id]
|
|
|
- if response.is_success:
|
|
|
- if response.txt is not None:
|
|
|
- post_message(response.txt, bot_id=bot_id)
|
|
|
- if response.img is not None:
|
|
|
- post_message(response.img, bot_id=bot_id)
|
|
|
- else:
|
|
|
- post_message(response.failure_msg, bot_id=bot_id)
|
|
|
-
|
|
|
-
|
|
|
|
|
|
@app.route("/rollbot", methods=["POST"])
|
|
|
def execute():
|
|
@@ -90,7 +73,32 @@ def execute():
|
|
|
app.logger.warn(f"Received message from unknown group ID {msg.group_id}")
|
|
|
return "Invalid group ID", 403
|
|
|
|
|
|
- run_command_and_respond(msg)
|
|
|
+
|
|
|
+ def run_command_and_respond():
|
|
|
+ app.logger.info(f"Entering command thread for {msg.message_id}")
|
|
|
+ t = time.time()
|
|
|
+ response = rollbot.run_command(msg)
|
|
|
+
|
|
|
+ if not response.respond:
|
|
|
+ app.logger.info(f"Skipping response to message {msg.message_id}")
|
|
|
+ return
|
|
|
+
|
|
|
+ app.logger.info(f"Responding to message {msg.message_id}")
|
|
|
+
|
|
|
+ bot_id = BOTS_LOOKUP[msg.group_id]
|
|
|
+ if response.is_success:
|
|
|
+ if response.txt is not None:
|
|
|
+ post_message(response.txt, bot_id=bot_id)
|
|
|
+ if response.img is not None:
|
|
|
+ post_message(response.img, bot_id=bot_id)
|
|
|
+ else:
|
|
|
+ post_message(response.failure_msg, bot_id=bot_id)
|
|
|
+
|
|
|
+ t = time.time() - t
|
|
|
+ app.logger.info(f"Exiting command thread for {msg.message_id} after {t:.3f}s")
|
|
|
+
|
|
|
+ t = Thread(target=run_command_and_respond)
|
|
|
+ t.start()
|
|
|
|
|
|
return "OK", 200
|
|
|
|