diff --git a/config/settings.yml.example b/config/settings.yml.example index 111ecf375..5eed2e360 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,3 +114,11 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 + +# 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 + - 123456789012345679 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 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..70737a419 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]] = [int(x) for x in config["IRC"]["BRIDGE_WEBHOOK_IDS"]] + CONFIG = Config()