From 2d6aec26553a8fee3b4f573a3146f88dff51abb0 Mon Sep 17 00:00:00 2001 From: Ow0cast Date: Thu, 31 Jul 2025 17:02:56 -0400 Subject: [PATCH 1/4] feat(command): allow irc users to use snippet command --- config/settings.yml.example | 6 ++++++ tux/handlers/event.py | 9 +++++++++ tux/utils/config.py | 3 +++ 3 files changed, 18 insertions(+) diff --git a/config/settings.yml.example b/config/settings.yml.example index 111ecf375..8e9074bc9 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,3 +114,9 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 + +IRC: # IDs of the IRC bridge webhooks + BRIDGE_WEBHOOK_IDS: + - 123456789012345679 + - 123456789012345679 + - 123456789012345679 diff --git a/tux/handlers/event.py b/tux/handlers/event.py index 7067e1f16..4bcbe92bc 100644 --- a/tux/handlers/event.py +++ b/tux/handlers/event.py @@ -4,6 +4,7 @@ from tux.bot import Tux from tux.database.controllers import DatabaseController from tux.ui.embeds import EmbedCreator, EmbedType +from tux.utils.config import CONFIG from tux.utils.functions import is_harmful, strip_formatting @@ -68,6 +69,14 @@ async def on_message_edit(self, before: discord.Message, after: discord.Message) @commands.Cog.listener() async def on_message(self, message: discord.Message) -> None: + # Allow the IRC bridge to use the snippet command only + if message.webhook_id in CONFIG.BRIDGE_WEBHOOK_IDS and ( + message.content.startswith(f"{CONFIG.DEFAULT_PREFIX}s ") + or message.content.startswith(f"{CONFIG.DEFAULT_PREFIX}snippet ") + ): + ctx = await self.bot.get_context(message) + await self.bot.invoke(ctx) + await self.handle_harmful_message(message) @commands.Cog.listener() diff --git a/tux/utils/config.py b/tux/utils/config.py index dd3cc7fc3..691542998 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -152,5 +152,8 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] + # IRC Bridges + BRIDGE_WEBHOOK_IDS: Final[list[int]] = config["IRC"]["BRIDGE_WEBHOOK_IDS"] + CONFIG = Config() From a7cfb9d2f581facc0952f7f1b08f240754203a25 Mon Sep 17 00:00:00 2001 From: owuh Date: Thu, 31 Jul 2025 17:45:24 -0400 Subject: [PATCH 2/4] Update tux/utils/config.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- tux/utils/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tux/utils/config.py b/tux/utils/config.py index 691542998..70737a419 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -153,7 +153,7 @@ def BOT_TOKEN(self) -> str: # noqa: N802 ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] # IRC Bridges - BRIDGE_WEBHOOK_IDS: Final[list[int]] = config["IRC"]["BRIDGE_WEBHOOK_IDS"] + BRIDGE_WEBHOOK_IDS: Final[list[int]] = [int(x) for x in config["IRC"]["BRIDGE_WEBHOOK_IDS"]] CONFIG = Config() From 9f4c5ed2d188387b99981a8b39a67a95e8319b49 Mon Sep 17 00:00:00 2001 From: owuh Date: Sat, 2 Aug 2025 20:29:12 -0400 Subject: [PATCH 3/4] Update settings.yml.example --- config/settings.yml.example | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 8e9074bc9..5eed2e360 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -115,7 +115,9 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel GIF_LIMITS_CHANNEL: "123456789012345": 3 -IRC: # IDs of the IRC bridge webhooks +# If you do not have an IRC bridge running, ignore these options +# Allows messages from these webhooks to use only the $s and $snippet commands (for now) +IRC: BRIDGE_WEBHOOK_IDS: - 123456789012345679 - 123456789012345679 From 804b26fe95255f9dfff3236bc5a763a3a2b54a07 Mon Sep 17 00:00:00 2001 From: owuh Date: Sat, 2 Aug 2025 20:31:49 -0400 Subject: [PATCH 4/4] Update test_main.py --- tests/unit/test_main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index 29b565ebe..c98fc7770 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -44,6 +44,8 @@ SNIPPETS: LIMIT_TO_ROLE_IDS: false ACCESS_ROLE_IDS: [] + IRC: + BRIDGE_WEBHOOK_IDS: [] """ mock_read_text.return_value = mock_config_content import tux.main