From f7538574c7474a0ac4193675f13dbb8f30d00dcf Mon Sep 17 00:00:00 2001 From: kingston Date: Wed, 4 Nov 2026 18:51:28 -0600 Subject: [PATCH] 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. --- ttstoy/ttstoy.py | 38 +++++++++++++++++++++++++++++------- wiki/TtsToy-Accessibility.md | 10 +++++++--- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/ttstoy/ttstoy.py b/ttstoy/ttstoy.py index 4a26477..662ff27 100644 --- a/ttstoy/ttstoy.py +++ b/ttstoy/ttstoy.py @@ -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 `\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 diff --git a/wiki/TtsToy-Accessibility.md b/wiki/TtsToy-Accessibility.md index 52a4a9a..78552bb 100644 --- a/wiki/TtsToy-Accessibility.md +++ b/wiki/TtsToy-Accessibility.md @@ -14,7 +14,9 @@ Start and stop require the bot owner. Engine and name announcements also require ## 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 " sent an image", " sent a file" or " 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 @@ -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. 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. -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 @@ -38,11 +40,13 @@ All of these must hold: | `..` alone, only emoji after it, or only whitespace | 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. ## 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.