added start method to allow for non message logic
authorGeorgios Atheridis <atheridis@tutamail.com>
Mon, 18 Apr 2022 14:14:11 +0000 (17:14 +0300)
committerGeorgios Atheridis <atheridis@tutamail.com>
Mon, 18 Apr 2022 14:14:11 +0000 (17:14 +0300)
aptbot/__main__.py
aptbot/bot.py

index 40a5879b068f4613d2e5ad99c28886fbcd0cdd95..2d26607bc322ec070ca0d38949be56fcb6dedcc8 100644 (file)
@@ -40,19 +40,6 @@ def handle_message(bot: aptbot.bot.Bot, modules: dict[str, ModuleType]):
         time.sleep(0.1)
 
 
-def update_channel_events(bot: aptbot.bot.Bot, message: aptbot.bot.Message, modules: dict[str, ModuleType]):
-    try:
-        method = Thread(
-            target=modules[message.channel].main,
-            args=(bot, message, )
-        )
-    except KeyError:
-        pass
-    else:
-        method.daemon = True
-        method.start()
-
-
 def start(bot: aptbot.bot.Bot, modules: dict[str, ModuleType]):
     load_modules(modules)
     message_handler_thread = Thread(
@@ -61,19 +48,13 @@ def start(bot: aptbot.bot.Bot, modules: dict[str, ModuleType]):
     )
     message_handler_thread.daemon = True
     message_handler_thread.start()
-    while True:
-        for channel, _ in modules:
-            update_channel_thread = Thread(
-                target=update_channel_events,
-                args=(
-                    bot,
-                    aptbot.bot.Message({}, "", None, channel, ""),
-                    modules,
-                )
-            )
-            update_channel_thread.daemon = True
-            update_channel_thread.start()
-        time.sleep(10)
+    for channel in modules:
+        update_channel = Thread(
+            target=modules[channel].start,
+            args=(bot, )
+        )
+        update_channel.daemon = True
+        update_channel.start()
 
 
 def load_modules(modules: dict[str, ModuleType]):
index a7aee760f3ec065e3f358fc2666522517c10be0e..8719b442a4198648408a1c2a7d7d4ac4a55ea40b 100644 (file)
@@ -39,8 +39,8 @@ class Bot:
         self._connected_channels = []
 
     def send_command(self, command: str):
-        if "PASS" not in command:
-            print(f"< {command}")
+        if "PASS" not in command:
+            print(f"< {command}")
         self._irc.send((command + "\r\n").encode())
 
     def connect(self):
@@ -67,18 +67,17 @@ class Bot:
     def send_privmsg(self, channel: str, text: Union[list[str], str]):
         if isinstance(text, list):
             for t in text:
-                print(
-                    f"#{channel} ({Commands.PRIVMSG.value}) | {self._nick}: {t}")
+                print(
+                    f"#{channel} ({Commands.PRIVMSG.value}) | {self._nick}: {t}")
                 self.send_command(
                     f"{Commands.PRIVMSG.value} #{channel} :{t}")
-                time.sleep(1.5)
         else:
-            print(f"#{channel} ({Commands.PRIVMSG.value}) | {self._nick}: {text}")
+            print(f"#{channel} ({Commands.PRIVMSG.value}) | {self._nick}: {text}")
             self.send_command(f"{Commands.PRIVMSG.value} #{channel} :{text}")
 
     @staticmethod
     def parse_message(received_msg: str) -> Message:
-        print(received_msg)
+        print(received_msg)
         message = Message()
 
         value_start = received_msg.find(