ttstoy: announce images, files and links without the accessibility trigger

Accessibility mode speaks only `..`-triggered messages, so a posted image or
link went unmentioned and listeners could not follow the side chat. Those
posts are now announced regardless of the trigger, and the name prefix is
skipped for them because the announcement already names the speaker.
This commit is contained in:
2026-11-04 18:51:28 -06:00
parent 84feec2e2a
commit f7538574c7
2 changed files with 38 additions and 10 deletions
+31 -7
View File
@@ -2076,7 +2076,7 @@ class TtsToy(Cog):
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"Start a message with `..` to have it read aloud (images, files and links are announced automatically).\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"
@@ -2098,7 +2098,8 @@ class TtsToy(Cog):
f"- Engine: `{engine}`\n"
"- Emoji SFX disabled (emojis read as text instead)\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"
"- Images, files and links are still announced without the trigger\n"
"- Ordinary text 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`"
)
@@ -2880,6 +2881,17 @@ class TtsToy(Cog):
except RuntimeError:
pass # no running loop (shouldn't happen in the listener path)
@staticmethod
def _access_is_post_announcement(message: discord.Message) -> bool:
"""True when a message is worth announcing without the '..' trigger.
Images, files, links and embeds are announced so a listener knows
something was posted. Ordinary text stays silent until it is triggered.
"""
if message.attachments or message.embeds:
return True
return bool(URL_PATTERN.search(message.content or ""))
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.
@@ -3016,12 +3028,17 @@ class TtsToy(Cog):
if ctx.valid:
return
# Opt-in per message: ordinary chat is never spoken. Only a message
# a member marks with the '..' trigger is read aloud.
# Opt-in per message: ordinary text is never spoken. Only a message
# a member marks with the '..' trigger is read aloud, except for
# images, files and links, which are announced without it so a
# listener still hears that something was posted.
raw = (message.content or "").lstrip()
if not raw.startswith(".."):
if raw.startswith(".."):
requested = raw[2:].lstrip()
elif self._access_is_post_announcement(message):
requested = raw
else:
return
requested = raw[2:].lstrip()
spoken = self._access_describe_message(message, requested)
if not spoken:
@@ -3031,7 +3048,14 @@ class TtsToy(Cog):
# else last spoke (i.e. they were "interrupted"), unless name
# announcements are turned off.
last = self._access_last_speaker.get(guild.id)
if await self.config.accessibility_announce_names() and last != message.author.id:
# Attachment and link announcements already carry the speaker's
# name, so prefixing "Name said:" would repeat it.
already_named = spoken.startswith(message.author.display_name)
if (
await self.config.accessibility_announce_names()
and last != message.author.id
and not already_named
):
spoken = f"{message.author.display_name} said: {spoken}"
self._access_last_speaker[guild.id] = message.author.id