Browse Source

Merge branch 'hotfix/2019-03-28-endless-loop' of kirkleon/rollbot3 into master

kirkleon 6 years ago
parent
commit
aa134049d8
1 changed files with 16 additions and 12 deletions
  1. 16 12
      src/rollbot.py

+ 16 - 12
src/rollbot.py

@@ -78,7 +78,7 @@ class Rollbot:
     def run_command(self, message):
         if not message.is_command:
             self.logger.warn(f"Tried to run non-command message {message.message_id}")
-            return RollbotResponse(msg, failure=RollbotFailure.INTERNAL_ERROR)
+            return RollbotResponse(message, failure=RollbotFailure.INTERNAL_ERROR)
 
         plugin = self.commands.get(message.command, None)
 
@@ -95,31 +95,35 @@ class Rollbot:
 
         return response
 
-    def handle_command(self, msg):
-        if msg.group_id not in self.bot_lookup:
-            self.logger.warning(f"Received message from unknown group ID {msg.group_id}")
+    def handle_command(self, message):
+        if not message.is_command:
+            self.logger.debug("Ignoring non-command message")
+            return
+
+        if message.group_id not in self.bot_lookup:
+            self.logger.warning(f"Received message from unknown group ID {message.group_id}")
             return
 
-        self.logger.info(f"Handling message {msg.message_id}")
+        self.logger.info(f"Handling message {message.message_id}")
         t = time.time()
         try:
-            response = self.run_command(msg)
+            response = self.run_command(message)
         except Exception as e:
-            self.logger.exception(f"Exception during command execution for message {msg.message_id}")
-            response = RollbotResponse(msg, failure=RollbotFailure.INTERNAL_ERROR)
+            self.logger.exception(f"Exception during command execution for message {message.message_id}")
+            response = RollbotResponse(message, failure=RollbotFailure.INTERNAL_ERROR)
 
         if not response.respond:
-            self.logger.info(f"Skipping response to message {msg.message_id}")
+            self.logger.info(f"Skipping response to message {message.message_id}")
             return
 
-        self.logger.info(f"Responding to message {msg.message_id}")
+        self.logger.info(f"Responding to message {message.message_id}")
 
         sleep = self.sleep_time - time.time() + t
         if sleep > 0:
             self.logger.info(f"Sleeping for {sleep:.3f}s before responding")
             time.sleep(sleep)
 
-        bot_id = self.bot_lookup[msg.group_id]
+        bot_id = self.bot_lookup[message.group_id]
         if response.is_success:
             if response.txt is not None:
                 self.callback(response.txt, bot_id)
@@ -130,7 +134,7 @@ class Rollbot:
             self.logger.warning(f"Failed command response: {response}")
 
         t = time.time() - t
-        self.logger.info(f"Exiting command thread for {msg.message_id} after {t:.3f}s")
+        self.logger.info(f"Exiting command thread for {message.message_id} after {t:.3f}s")
 
     def handle_command_threaded(self, message):
         t = Thread(target=lambda: self.handle_command(message))