Skip to content

Fix several link fixing bugs - #121

Open
seirenkr wants to merge 9 commits into
Kyrela:mainfrom
seirenkr:fix/link-fixing-bugs
Open

seirenkr wants to merge 9 commits into
Kyrela:mainfrom
seirenkr:fix/link-fixing-bugs

Conversation

@seirenkr

Copy link
Copy Markdown
Contributor

Summary

Nine small fixes found while reviewing the code for the three pull requests that follow (Components V2, subdomains of the custom websites, removal of the fixed links). They don't depend on them or on each other: one commit each, with the details in its message. No interface or database change.

Commit What was happening
Never mention anyone from a fixed link https://x.com/@everyone/status/1 is answered with [@@everyone](…): the space added after the @ only covers a username that starts with everyone or here. The bot now sends with allowed_mentions: only the member it replies to, and nobody through the webhook.
Ignore the messages sent through the bot's own webhook When replying as the original author with webhooks not ignored, the bot handled its own messages. With a custom website whose fixed link is fixable again, it answered itself endlessly.
Only accept a real label as the subdomain of a website [^.]+ also accepts # and /: https://16843009#.bilibili.com/video/BV1 was fixed into a link to the host 16843009.
Fix the author link of generic websites https://www.instagram.com/instagram/p/… gave the author link https://instagram, the URL being cut at the first occurrence of the username.
Apply the Instagram view setting The views were declared as params instead of subdomains: the setting was saved, but never applied.
Match the keywords that start or end with a symbol With \b, a keyword such as !nofix only matched when glued to the previous word.
Wait for the embed of a fixed link through the raw event message_edit is only dispatched for the last 1000 cached messages: on a busy instance, a fixed link could be deleted as not embedded although it was.
Check the permission to send messages in threads The links posted in a thread were not fixed when the bot has Send Messages in Threads but not Send Messages.
Don't raise on a handled error when there is no log channel safe_send_coro raised while reporting an error it had just handled.

One thing to know before merging: the Instagram view takes effect for the first time, so the servers that already chose another view than the normal one will start getting it.

Test plan

  • Each of the nine bugs reproduced on main, then checked as fixed on this branch, with a script that simulates the Discord side (no network).
  • Author links compared with main on 672 sample URLs (every route of every generic website): all identical, so only the wrong ones change.
  • Links fixed on a test server by a test bot running this branch merged with the three others (discord.py 2.7.1, MariaDB 12).

Not verified: whether Discord really pings for an @everyone placed in a link label. The fix doesn't depend on it.

Written with Claude Code (Claude Fable 5.2, credited as co-author of the commits).

🤖 Generated with Claude Code

seirenkr and others added 9 commits November 12, 2026 08:15
A fixed link is built from the URL a member posted, username included. The author label already gets a space when
the username starts with `everyone` or `here`, but the username can contain the mention itself, as in
`https://x.com/@everyone/status/1` or `https://x.com/x@here/status/1`: the label of the fixed link then holds it as
it is, and nothing told Discord not to read it as a mention.

The bot now only allows the mention of the member it replies to, and the messages it sends through a webhook
(reply as the original author) none at all.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
When the fixed links are sent as a replica of the original author, their author is a webhook and not the bot, so
the bot handled its own messages whenever webhooks are not ignored. With a custom website whose fixed link is
fixable again (its own domain, or two websites pointing at each other), each fixed link was fixed again, endlessly.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`[^.]+` accepts any character but a dot, `#` and `/` included: `https://16843009#.bilibili.com/video/BV1` was taken
for a BiliBili link whose subdomain is `16843009#`, and answered with `https://16843009#.vxbilibili.com/video/BV1`,
which is a link to the host `16843009` labelled as the fixer.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The link was rebuilt by cutting the original URL at the first occurrence of the username, which is wrong as soon as
the username also appears earlier in the URL: for `https://www.instagram.com/instagram/p/…`, the author link was
`https://instagram`. The URL is now cut where the route found the username, and written as the original link is
(`https`, without `www.`), so the author link of every other URL stays what it was.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The views were declared as `params` while `GenericWebsiteLink` reads `subdomains`, so the setting was saved and
displayed but every Instagram link was fixed with the normal view.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`\b` only matches between a word character and another kind of character, so a keyword such as `!nofix` was not
found at the start of a message or after a space: only when glued to the previous word. A keyword now matches when
it stands on its own (not glued to a letter, a digit or an underscore), whatever it is made of.
Nothing changes for the keywords made of word characters, such as the default `fxignore`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`message_edit` is only dispatched for the messages still in the message cache (the last 1000 received, all servers
together). When a fixed link has left the cache before Discord adds its embed, the wait times out: the link is then
deleted and reported as failed, although it was embedded. `raw_message_edit` is always dispatched.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
In a thread, `Send Messages in Threads` is the permission that applies, not `Send Messages`: the links posted in a
thread were not fixed when the bot is only granted the former.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`safe_send_coro` reports the rate limits and the missing permissions it handles to `log.channel`. When that channel
is not configured, or not found, the report itself raised (a `TypeError` for the missing setting, an
`AttributeError` for the missing channel), turning a handled error into an unhandled one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant