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() names = await self.config.accessibility_announce_names()
await ctx.send( await ctx.send(
f"Accessibility mode is **{'ON' if on else 'OFF'}** (engine: `{engine}`).\n" 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 start`\n"
f"- `{ctx.clean_prefix}ttstoy accessibility stop`\n" f"- `{ctx.clean_prefix}ttstoy accessibility stop`\n"
f"- `{ctx.clean_prefix}ttstoy accessibility engine <dectalk|piper>`\n" f"- `{ctx.clean_prefix}ttstoy accessibility engine <dectalk|piper>`\n"
@@ -2098,7 +2098,8 @@ class TtsToy(Cog):
f"- Engine: `{engine}`\n" f"- Engine: `{engine}`\n"
"- Emoji SFX disabled (emojis read as text instead)\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" "- 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" "- 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`" f"- Change your own voice with `{ctx.clean_prefix}ttstoy accessibility voice`"
) )
@@ -2880,6 +2881,17 @@ class TtsToy(Cog):
except RuntimeError: except RuntimeError:
pass # no running loop (shouldn't happen in the listener path) 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]: 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. """Build the spoken text for an accessibility read of a VC side-chat message.
@@ -3016,12 +3028,17 @@ class TtsToy(Cog):
if ctx.valid: if ctx.valid:
return return
# Opt-in per message: ordinary chat is never spoken. Only a message # Opt-in per message: ordinary text is never spoken. Only a message
# a member marks with the '..' trigger is read aloud. # 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() raw = (message.content or "").lstrip()
if not raw.startswith(".."): if raw.startswith(".."):
return
requested = raw[2:].lstrip() requested = raw[2:].lstrip()
elif self._access_is_post_announcement(message):
requested = raw
else:
return
spoken = self._access_describe_message(message, requested) spoken = self._access_describe_message(message, requested)
if not spoken: if not spoken:
@@ -3031,7 +3048,14 @@ class TtsToy(Cog):
# else last spoke (i.e. they were "interrupted"), unless name # else last spoke (i.e. they were "interrupted"), unless name
# announcements are turned off. # announcements are turned off.
last = self._access_last_speaker.get(guild.id) 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}" spoken = f"{message.author.display_name} said: {spoken}"
self._access_last_speaker[guild.id] = message.author.id self._access_last_speaker[guild.id] = message.author.id
+7 -3
View File
@@ -14,7 +14,9 @@ Start and stop require the bot owner. Engine and name announcements also require
## The `..` trigger ## The `..` trigger
A message is spoken only when it starts with `..`. The trigger and the whitespace after it are dropped before speaking, so `..good game` is read as "good game". A message without the trigger is ignored, so normal conversation is never spoken. Plain text is spoken only when it starts with `..`. The trigger and the whitespace after it are dropped before speaking, so `..good game` is read as "good game".
Images, files, links and embeds are announced without the trigger, as "<name> sent an image", "<name> sent a file" or "<name> sent a link", so a listener still learns that something was posted. Every other message without the trigger is ignored, so normal conversation is never read aloud.
## Conditions for a message to be read ## Conditions for a message to be read
@@ -25,7 +27,7 @@ All of these must hold:
3. The message is in that voice channel's text chat, which Discord exposes as a text channel with the same ID as the voice channel. 3. The message is in that voice channel's text chat, which Discord exposes as a text channel with the same ID as the voice channel.
4. The message is not from a bot. 4. The message is not from a bot.
5. The message does not parse as a command, so `[p]tts` invocations are not read twice. 5. The message does not parse as a command, so `[p]tts` invocations are not read twice.
6. The message starts with `..`. 6. The message starts with `..`, or it carries an image, file, link or embed, which are announced without the trigger.
## What gets spoken ## What gets spoken
@@ -38,11 +40,13 @@ All of these must hold:
| `..` alone, only emoji after it, or only whitespace | Nothing | | `..` alone, only emoji after it, or only whitespace | Nothing |
| Obvious keyboard mash or spam | Nothing | | Obvious keyboard mash or spam | Nothing |
Attachments, links and embeds are announced whether or not the message carries the trigger. Plain text needs the trigger.
The nonsense filter is conservative. It drops messages with a single character repeated over most of the text, one short token repeated five or more times, a long alphabetic run with almost no vowels, very low character variety over a long message, or a short unit repeated to fill the message. Short real messages such as "ok", "lol" or "brb" pass through. The nonsense filter is conservative. It drops messages with a single character repeated over most of the text, one short token repeated five or more times, a long alphabetic run with almost no vowels, very low character variety over a long message, or a short unit repeated to fill the message. Short real messages such as "ok", "lol" or "brb" pass through.
## Name announcements ## Name announcements
The first message from a speaker since anyone else last spoke is prefixed with "Name said:". A speaker who sends several messages in a row is announced once. The tracker resets when the bot joins, leaves or moves voice channels, so a stale state does not carry into a new session. The first message from a speaker since anyone else last spoke is prefixed with "Name said:". A speaker who sends several messages in a row is announced once. Image, file and link announcements already contain the speaker's name, so they are not prefixed again. The tracker resets when the bot joins, leaves or moves voice channels, so a stale state does not carry into a new session.
`[p]ttstoy accessibility names off` removes the prefix. Names attached to attachments and links are part of the announcement text itself, so they are spoken regardless of this setting. `[p]ttstoy accessibility names off` removes the prefix. Names attached to attachments and links are part of the announcement text itself, so they are spoken regardless of this setting.