From 3593c70be5129ddc06c7a7901334716a34a3412e Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Thu, 21 Sep 2023 15:06:13 -0700 Subject: [PATCH] TrackReact: do not react in the support channel (#78) --- cogs/track_react.py | 13 +++++++++++++ conf.py | 1 + exercism_discord_bot.py | 1 + 3 files changed, 15 insertions(+) diff --git a/cogs/track_react.py b/cogs/track_react.py index 715d1ac..b079486 100755 --- a/cogs/track_react.py +++ b/cogs/track_react.py @@ -25,6 +25,7 @@ def __init__( self, aliases: dict[str, str], case_sensitive: set[str], + no_react_channels: list[str], **kwargs, ) -> None: super().__init__(**kwargs) @@ -32,6 +33,7 @@ def __init__( self.messages: dict[int, discord.Message] = {} self.aliases = aliases self.case_sensitive = case_sensitive + self.no_react_channels = [c.removeprefix("#") for c in no_react_channels] @commands.Cog.listener() async def on_ready(self) -> None: @@ -93,6 +95,17 @@ async def add_reacts(self, message: discord.Message, content: str) -> None: """Add reactions to a Message object based on content.""" if not message.guild: return + if isinstance(message.channel, discord.TextChannel): + channel_name = message.channel.name + elif isinstance(message.channel, discord.Thread) and isinstance( + message.channel.parent, discord.TextChannel + ): + channel_name = message.channel.parent.name + else: + channel_name = "Unhandled" + logger.debug("Adding reacts to message in channel %s", channel_name) + if channel_name in self.no_react_channels: + logger.debug("Not reacting to message in %s", channel_name) if not message.channel.permissions_for(message.guild.me).add_reactions: logger.warning( "Missing add_reactions permission for %s in %s.", diff --git a/conf.py b/conf.py index 3956064..e6bdff0 100644 --- a/conf.py +++ b/conf.py @@ -84,6 +84,7 @@ "elisp": "emacs_lisp", "cl": "common_lisp", } +NO_REACT_CHANNELS = ["support"] # mentor_requests.py MENTOR_REQUEST_CHANNEL = 1091036025737986098 diff --git a/exercism_discord_bot.py b/exercism_discord_bot.py index f59580d..51ed181 100755 --- a/exercism_discord_bot.py +++ b/exercism_discord_bot.py @@ -113,6 +113,7 @@ def get_cogs(self) -> dict[commands.CogMeta, dict[str, Any]]: cogs.TrackReact: { "aliases": conf.ALIASES, "case_sensitive": conf.CASE_SENSITIVE, + "no_react_channels": conf.NO_REACT_CHANNELS, }, } # Optionally filter Cogs.