From 6c29fa04dce8745f5c61c6a6b43c303c49275d57 Mon Sep 17 00:00:00 2001 From: Florian SYLVAIN Date: Mon, 8 Feb 2021 22:40:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20-=20Overall=20code=20cleaning=20?= =?UTF-8?q?#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index e04bdc3..de9ba8f 100644 --- a/main.py +++ b/main.py @@ -15,20 +15,20 @@ chats = dict() class ChatObj: - def __init__(self, twitch_chan, discord_chan): + def __init__(self, twitch_user, discord_channel): self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.twitch_chan = twitch_chan - self.discord_chan = discord_chan - chats[discord_chan] = self + self.twitch_user = twitch_user + self.discord_channel = discord_channel + chats[discord_channel] = self def chat_init(self): try: self.sock.connect((SERVER, PORT)) self.sock.send(f"PASS {TOKEN_TWITCH}\n".encode('utf-8')) self.sock.send(f"NICK {NICKNAME}\n".encode('utf-8')) - self.sock.send(f"JOIN {'#' + self.twitch_chan}\n".encode('utf-8')) + self.sock.send(f"JOIN {'#' + self.twitch_user}\n".encode('utf-8')) self.sock.settimeout(0.0) - self.sock.setblocking(0) + self.sock.setblocking(False) return 1 except OSError: return 0 @@ -50,7 +50,7 @@ class ChatObj: username = chain.group(1) message = chain.group(3) msg = f"**__{username}__ :** {message}" - await self.discord_chan.send(msg) + await self.discord_channel.send(msg) except discord.DiscordException: pass except AttributeError: @@ -82,12 +82,12 @@ async def on_ready(): @bot.command() async def chat_set(ctx, arg1): await ctx.message.delete() - chan = ctx.channel - if chan in list(chats): + what_channel = ctx.channel + if what_channel in list(chats): await ctx.send("```A chat is already active, you have to stop it before with the cmd $chat_stop !```") else: if check_user(arg1): - obj = ChatObj(arg1, chan) + obj = ChatObj(arg1, what_channel) if obj.chat_init(): await ctx.send(f'```Now connected to {arg1}\'s twitch channel !```') obj.twitch.start()