Add mention-only mode toggle (#12)

Adds ability to restrict Gurt responses to direct mentions

Reviewed-on: #12
Co-authored-by: Slipstream <me@slipstreamm.dev>
Co-committed-by: Slipstream <me@slipstreamm.dev>
This commit is contained in:
Slipstream 2025-06-12 11:15:10 -06:00 committed by slipstream
parent 2b75955c4f
commit 7cb1ec8589
3 changed files with 42 additions and 0 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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