浏览代码

Modifying delay behavior to be more consistent

Kirk Trombley 6 年之前
父节点
当前提交
28c54db36b
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      src/app.py

+ 5 - 2
src/app.py

@@ -76,8 +76,6 @@ def execute():
 
     def run_command_and_respond():
         app.logger.info(f"Entering command thread for {msg.message_id}")
-        app.logger.info(f"Sleeping for {SLEEP_TIME:.3f}s before executing command")
-        time.sleep(SLEEP_TIME)
         t = time.time()
         try:
             response = rollbot.run_command(msg)
@@ -91,6 +89,11 @@ def execute():
 
         app.logger.info(f"Responding to message {msg.message_id}")
 
+        sleep = SLEEP_TIME - time.time() + t
+        if sleep > 0:
+            app.logger.info(f"Sleeping for {sleep:.3f}s before responding")
+            time.sleep(sleep)
+
         bot_id = BOTS_LOOKUP[msg.group_id]
         if response.is_success:
             if response.txt is not None: