From 7cb1ec8589b62363fa80ea1ad75c03bac97487b9 Mon Sep 17 00:00:00 2001 From: Slipstream Date: Thu, 12 Jun 2025 11:15:10 -0600 Subject: [PATCH] Add mention-only mode toggle (#12) Adds ability to restrict Gurt responses to direct mentions Reviewed-on: https://git.slipstreamm.dev/slipstream/discordbot/pulls/12 Co-authored-by: Slipstream Co-committed-by: Slipstream --- gurt/cog.py | 2 ++ gurt/commands.py | 37 +++++++++++++++++++++++++++++++++++++ gurt/listeners.py | 3 +++ 3 files changed, 42 insertions(+) diff --git a/gurt/cog.py b/gurt/cog.py index 030709b..67f7861 100644 --- a/gurt/cog.py +++ b/gurt/cog.py @@ -128,6 +128,7 @@ class GurtCog(commands.Cog, name="Gurt"): # Added explicit Cog name self.current_mood = random.choice(MOOD_OPTIONS) self.last_mood_change = time.time() self.needs_json_reminder = False # Flag to remind AI about JSON format + self.mention_only = False # If True, only respond when mentioned # Learning variables (Consider moving to a dedicated state/learning manager later) self.conversation_patterns = defaultdict(list) @@ -618,6 +619,7 @@ class GurtCog(commands.Cog, name="Gurt"): # Added explicit Cog name stats["runtime"]["gurt_message_reactions_tracked"] = len( self.gurt_message_reactions ) + stats["runtime"]["mention_only"] = self.mention_only # --- Memory (via MemoryManager) --- try: diff --git a/gurt/commands.py b/gurt/commands.py index f53836f..6ef9cec 100644 --- a/gurt/commands.py +++ b/gurt/commands.py @@ -1425,6 +1425,43 @@ def setup_commands(cog: "GurtCog"): command_functions.append(gurtgetmodel) + # --- Gurt Mention Mode Command --- + @cog.bot.tree.command( + name="gurtmention", + description="Toggle or check mention-only response mode.", + ) + @app_commands.describe(mode="Optional: set to 'on' or 'off'.") + @app_commands.choices( + mode=[ + app_commands.Choice(name="On", value="on"), + app_commands.Choice(name="Off", value="off"), + ] + ) + async def gurtmention( + interaction: discord.Interaction, + mode: Optional[app_commands.Choice[str]] = None, + ): + """Handles the /gurtmention command.""" + if mode and interaction.user.id != cog.bot.owner_id: + await interaction.response.send_message( + "⛔ Only the bot owner can change mention mode.", ephemeral=True + ) + return + + if mode: + cog.mention_only = mode.value == "on" + await interaction.response.send_message( + f"Mention-only mode {'enabled' if cog.mention_only else 'disabled' }.", + ephemeral=True, + ) + else: + await interaction.response.send_message( + f"Mention-only mode is currently {'enabled' if cog.mention_only else 'disabled' }.", + ephemeral=True, + ) + + command_functions.append(gurtmention) + # Get command names safely - Command objects don't have __name__ attribute command_names = [] for func in command_functions: diff --git a/gurt/listeners.py b/gurt/listeners.py index 36de9b0..03fa763 100644 --- a/gurt/listeners.py +++ b/gurt/listeners.py @@ -295,6 +295,9 @@ async def on_message_listener(cog: "GurtCog", message: discord.Message): ) gurt_in_message = "gurt" in message.content.lower() + if cog.mention_only and not (bot_mentioned or replied_to_bot or gurt_in_message): + return + if message.guild is None and (bot_mentioned or replied_to_bot or gurt_in_message): await message.channel.send("AI functionality is disabled in DMs.") return