From 71b10eaba165542a1bc1a81c2922c415bb338447 Mon Sep 17 00:00:00 2001 From: Yuuki Chan Date: Thu, 22 Feb 2024 19:34:28 +0900 Subject: [PATCH] Updated bot.py and sasl.py --- src/bot.py | 5 +++-- src/sasl.py | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/bot.py b/src/bot.py index 93cba71..0c1c92e 100644 --- a/src/bot.py +++ b/src/bot.py @@ -196,9 +196,9 @@ class Bot: await plugin.handle_message(source_nick, channel, message) case 'CAP': if args[1] == 'ACK' and 'sasl' in args[2]: - handle_sasl(self.config, self.ircsend) + await handle_sasl(self.config, self.ircsend) case 'AUTHENTICATE': - handle_authenticate(args, self.config, self.ircsend) + await handle_authenticate(args, self.config, self.ircsend) case 'INVITE': channel = args[1] await self.ircsend(f'JOIN {channel}') @@ -206,6 +206,7 @@ class Bot: case 'VERSION': await self.ircsend(f'NOTICE {source_nick} :I am a bot version 1.0.0') case '001': + await asyncio.sleep(1) await self.ircsend('JOIN #YuukiTest') # for channel in self.channel_manager.get_channels(): # await self.ircsend(f'JOIN {channel}') diff --git a/src/sasl.py b/src/sasl.py index 3581224..c32666f 100644 --- a/src/sasl.py +++ b/src/sasl.py @@ -5,7 +5,7 @@ NULL_BYTE = '\x00' ENCODING = 'UTF-8' -def handle_sasl(config, ircsend): +async def handle_sasl(config, ircsend): """ Handles SASL authentication by sending an AUTHENTICATE command. @@ -13,10 +13,10 @@ def handle_sasl(config, ircsend): config (dict): Configuration dictionary ircsend (function): Function to send IRC commands """ - ircsend('AUTHENTICATE PLAIN') + await ircsend('AUTHENTICATE PLAIN') -def handle_authenticate(args, config, ircsend): +async def handle_authenticate(args, config, ircsend): """ Handles the AUTHENTICATE command response. @@ -31,7 +31,7 @@ def handle_authenticate(args, config, ircsend): f'{config["SASL"]["SASLNick"]}{NULL_BYTE}' f'{config["SASL"]["SASLPassword"]}') ap_encoded = base64.b64encode(authpass.encode(ENCODING)).decode(ENCODING) - ircsend(f'AUTHENTICATE {ap_encoded}') + await ircsend(f'AUTHENTICATE {ap_encoded}') else: raise KeyError('SASLNICK and/or SASLPASS not found in config') @@ -43,4 +43,4 @@ async def handle_903(ircsend): Parameters: ircsend (function): Function to send IRC commands """ - ircsend('CAP END') + await ircsend('CAP END')