ttstoy: speak only ..-triggered messages in accessibility mode

Accessibility mode read every message in the voice channel side chat and
treated `..` as an opt-out, so ordinary chat was always spoken. Members now
trigger speech explicitly with `..`, and messages without the trigger are
never read.
This commit is contained in:
2026-11-04 18:33:30 -06:00
parent 5ca8cea1a7
commit 84feec2e2a
4 changed files with 32 additions and 20 deletions
+19 -11
View File
@@ -2069,13 +2069,14 @@ class TtsToy(Cog):
@ttstoy_group.group(name="accessibility", aliases=["access"], invoke_without_command=True)
async def accessibility_group(self, ctx: commands.Context):
"""Accessibility mode: auto-read the VC side chat with per-speaker voices."""
"""Accessibility mode: speak VC side-chat messages marked with `..`, per-speaker voices."""
if ctx.invoked_subcommand is None:
on = await self.config.accessibility_mode()
engine = await self.config.accessibility_engine()
names = await self.config.accessibility_announce_names()
await ctx.send(
f"Accessibility mode is **{'ON' if on else 'OFF'}** (engine: `{engine}`).\n"
f"Start a message with `..` to have it read aloud.\n"
f"- `{ctx.clean_prefix}ttstoy accessibility start`\n"
f"- `{ctx.clean_prefix}ttstoy accessibility stop`\n"
f"- `{ctx.clean_prefix}ttstoy accessibility engine <dectalk|piper>`\n"
@@ -2096,7 +2097,8 @@ class TtsToy(Cog):
"**Accessibility mode started.**\n"
f"- Engine: `{engine}`\n"
"- Emoji SFX disabled (emojis read as text instead)\n"
"- Auto-reads the side chat of the voice channel the bot is in (no command prefix needed)\n"
"- Reads the side chat of the voice channel the bot is in, but only messages that start with `..`\n"
"- Ordinary chat is never spoken\n"
"- Each speaker keeps a distinct voice so they can be told apart (saved between sessions)\n"
f"- Change your own voice with `{ctx.clean_prefix}ttstoy accessibility voice`"
)
@@ -2757,7 +2759,7 @@ class TtsToy(Cog):
return self.tts_queues[guild_id]
# ---------------------------------------------------------------------
# ACCESSIBILITY AUTO-READ (VC side-chat, no command prefix)
# ACCESSIBILITY SPEECH ('..' trigger in the VC side chat)
# ---------------------------------------------------------------------
def _access_voice_pool(self, engine: str) -> list:
"""Return the list of selectable voices for the given accessibility engine."""
@@ -2878,15 +2880,18 @@ class TtsToy(Cog):
except RuntimeError:
pass # no running loop (shouldn't happen in the listener path)
def _access_describe_message(self, message: discord.Message) -> Optional[str]:
"""Build the spoken text for an accessibility auto-read of a VC side-chat message.
def _access_describe_message(self, message: discord.Message, text: Optional[str] = None) -> Optional[str]:
"""Build the spoken text for an accessibility read of a VC side-chat message.
Returns the raw content to speak, or None if there is nothing to read.
`text` is the message content after the '..' trigger, which the listener
strips before calling this. When it is omitted the whole message content
is used. Returns the text to speak, or None if there is nothing to read.
Attachments/embeds/links are announced instead of read:
"<username> sent a link" / "sent an image" / "sent a file"
No emoji, no em-dash.
"""
name = message.author.display_name
text = message.content if text is None else text
# Attachments take priority: classify image vs generic file
if message.attachments:
@@ -2901,10 +2906,10 @@ class TtsToy(Cog):
return f"{name} sent a file"
# A link in the text (or a link-only embed) is announced, not read
if URL_PATTERN.search(message.content or "") or message.embeds:
if URL_PATTERN.search(text or "") or message.embeds:
return f"{name} sent a link"
content = (message.content or "").strip()
content = (text or "").strip()
if not content:
return None
# No emoji anywhere: strip unicode emoji and custom/named emoji tokens.
@@ -3011,11 +3016,14 @@ class TtsToy(Cog):
if ctx.valid:
return
# Messages starting with '..' are intentionally not read aloud.
if (message.content or "").lstrip().startswith(".."):
# Opt-in per message: ordinary chat is never spoken. Only a message
# a member marks with the '..' trigger is read aloud.
raw = (message.content or "").lstrip()
if not raw.startswith(".."):
return
requested = raw[2:].lstrip()
spoken = self._access_describe_message(message)
spoken = self._access_describe_message(message, requested)
if not spoken:
return