Przeglądaj źródła

Fix delete_message

Librellium 3 miesięcy temu
rodzic
commit
26b1cfca9e
1 zmienionych plików z 11 dodań i 11 usunięć
  1. 11 11
      podslv21_bot/moderation/executor.py

+ 11 - 11
podslv21_bot/moderation/executor.py

@@ -31,25 +31,25 @@ class ModerationExecutor:
         Do not use it for moderation or automatic cleanup.
         """
         parsed_url = URL(message_link)
-        parsed_path = parsed_url.path.strip().split("/")
+        parsed_path = parsed_url.path.strip("/").split("/")
 
-        intermediate_chat_id = self.config.forwarding.intermediate_chat_id
-        target_chat_id = self.config.forwarding.target_chat_id
+        moderation_chat_id = self.config.forwarding.moderation_chat_id
+        publication_chat_id = self.config.forwarding.publication_chat_id
 
         if len(parsed_path) == 3 and parsed_path[0] == "c"\
-            and parsed_path[1].replace("-100", "") == str(target_chat_id).replace("-100", ""):
-                message_id = parsed_path[3]
+            and parsed_path[1].replace("-100", "") == str(publication_chat_id).replace("-100", ""):
+                message_id = parsed_path[2]
                 try:
-                    await self.bot.delete_message(target_chat_id, message_id)
+                    await self.bot.delete_message(publication_chat_id, message_id)
                     await self.bot.send_message(
-                        intermediate_chat_id,
+                        moderation_chat_id,
                         f"<b>Исполнитель</b>: Удаление успешно для {message_id}.",
                         parse_mode="HTML"
                     )
                     return ModerationEvent(type="delete_message", result=True)
                 except TelegramBadRequest:
                     await self.bot.send_message(
-                        intermediate_chat_id,
+                        moderation_chat_id,
                         f"<b>Исполнитель</b>: Удаление окончилось ошибкой для {message_id}.",
                         parse_mode="HTML"
                     )
@@ -61,11 +61,11 @@ class ModerationExecutor:
         This function must be called whenever there is no exact user request or no other available function 
         matching the user's intent. Status must be either "PASS" if the message is allowed, or "REJECT" if it should be blocked.
         """
-        intermediate_chat_id = self.config.forwarding.intermediate_chat_id
+        moderation_chat_id = self.config.forwarding.moderation_chat_id
         human_status = "отправлено" if status == "PASS" else "отклонено"
 
         await self.bot.send_message(
-            intermediate_chat_id,
+            moderation_chat_id,
             f"<b>Исполнитель</b>: Сообщение {human_status}.\n\nОбъяснение: {explanation}",
             parse_mode="HTML"
         )
@@ -86,4 +86,4 @@ class ModerationExecutor:
                     self._logger.info(f"Executing {func_name}({', '.join(map(str, func.get('args')))})")
                     yield await getattr(self, func_name)(*func.get("args"))
                 except Exception:
-                    self._logger.info(f"Failed to execute {func_name}({', '.join(map(str, func.get('args')))})")
+                    self._logger.exception(f"Failed to execute {func_name}({', '.join(map(str, func.get('args')))})")