From 0e4649033d870331837aebe54ebad64e657f5f0e Mon Sep 17 00:00:00 2001 From: Georgios Atheridis Date: Mon, 18 Apr 2022 17:14:11 +0300 Subject: [PATCH] added start method to allow for non message logic --- aptbot/__main__.py | 33 +++++++-------------------------- aptbot/bot.py | 13 ++++++------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/aptbot/__main__.py b/aptbot/__main__.py index 40a5879..2d26607 100644 --- a/aptbot/__main__.py +++ b/aptbot/__main__.py @@ -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]): diff --git a/aptbot/bot.py b/aptbot/bot.py index a7aee76..8719b44 100644 --- a/aptbot/bot.py +++ b/aptbot/bot.py @@ -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( -- 2.30.2