From ed69bcf300a679e18f842124f8e7860de74ed943 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 3 Jul 2024 11:43:28 -0400 Subject: [PATCH] REF: Updated the twich module to hopefully fix alerts --- main.py | 1 + modules/social/twitch.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/main.py b/main.py index 1fd80f0..dbe8ac3 100644 --- a/main.py +++ b/main.py @@ -69,6 +69,7 @@ class Selena(discord.Client): from modules.social.twitch import Twitch twitch = Twitch(self) twitch.setup(self.tree) + self.twitch_module = twitch logging.info("Twitch module loaded") if config['modules']['update']['enabled']: diff --git a/modules/social/twitch.py b/modules/social/twitch.py index 9993753..c4255d7 100644 --- a/modules/social/twitch.py +++ b/modules/social/twitch.py @@ -103,9 +103,20 @@ class Twitch: embed.add_field(name="Game", value=channel_info['game_name'], inline=True) await channel.send(embed=embed) + async def is_channel_followed(self, channel_name): + conn = sqlite3.connect(self.db_path) + cursor = conn.cursor() + cursor.execute("SELECT 1 FROM twitch_channels WHERE channel_name = ?", (channel_name,)) + result = cursor.fetchone() + conn.close() + return result is not None + def setup(self, tree: app_commands.CommandTree): @tree.command(name="add_twitch_channel", description="Add a Twitch channel to monitor") async def add_twitch_channel_command(interaction: discord.Interaction, channel_name: str, alert_channel: discord.TextChannel): + if await self.is_channel_followed(channel_name): + await interaction.response.send_message(embed=discord.Embed(description=f"Twitch channel {channel_name} is already being monitored.", color=discord.Color.orange())) + return conn = sqlite3.connect(self.db_path) cursor = conn.cursor() cursor.execute("INSERT INTO twitch_channels (channel_name, alert_channel_id) VALUES (?, ?)", (channel_name, alert_channel.id)) @@ -115,6 +126,9 @@ class Twitch: @tree.command(name="remove_twitch_channel", description="Remove a Twitch channel from monitoring") async def remove_twitch_channel_command(interaction: discord.Interaction, channel_name: str): + if not await self.is_channel_followed(channel_name): + await interaction.response.send_message(embed=discord.Embed(description=f"Twitch channel {channel_name} is not being monitored.", color=discord.Color.red())) + return conn = sqlite3.connect(self.db_path) cursor = conn.cursor() cursor.execute("DELETE FROM twitch_channels WHERE channel_name = ?", (channel_name,))