Skip to content

Commit 6f66c29

Browse files
authored
fix(on_message): adjust x replacement reply (#57)
* fix(on_message): adjust link replies - When someone posts a link to x.com, always reply inline with xcancel link * fix(on_message): adjust link advisor - Suppress replied message's embeds * chore: address feedback
1 parent 6c849ec commit 6f66c29

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

src/events/on_message/_advise.ts

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Message, hideLinkEmbed, codeBlock } from 'discord.js';
1+
import { type Message } from 'discord.js';
22
import urlRegex from 'url-regex';
33

44
export default async function mutate_content(message: Message) {
@@ -15,36 +15,17 @@ export default async function mutate_content(message: Message) {
1515
return;
1616
}
1717

18-
const updated_phrase: string =
19-
links.length > 1
20-
? 'Here are the updated links:'
21-
: 'Here is the updated link:';
18+
const updated_link_list = links.map((link) => `- ${link}`).join('\n');
2219

23-
const updated_link_list = links
24-
.map((link) => `- ${hideLinkEmbed(link)}`)
25-
.join('\n');
20+
const link_term = updated_link_list.length === 1 ? 'link' : 'links';
2621

27-
const updated_content = message.content.replace(urlRegex(), (match) => {
28-
return match.startsWith('https://x.com')
29-
? match.replace(/^https:\/\/x\.com/, 'https://xcancel.com')
30-
: match;
31-
});
32-
33-
try {
34-
await message.author.send(
35-
`Re: ${message.url}\n\nI see you've provided a link to \`x.com\`. Please consider posting a new message having \`x.com\` replaced with \`xcancel.com\`, that way server members may view the message and thread without requiring an account.\n\n${updated_phrase}\n${updated_link_list}\n\nHere is your entire message with adjusted links:\n${codeBlock(updated_content)}`,
36-
);
37-
38-
return; // mission complete
39-
} catch {
40-
// assume user disabled DMs upon error
41-
}
42-
43-
// Plan B: inline reply
22+
// Reply inline
4423
try {
4524
await message.reply(
46-
`I converted your \`x.com\` links to use \`xcancel.com\` so that server members won't require an account to view content and threads:\n${updated_link_list}`,
25+
`I converted your \`x.com\` ${link_term} to use \`xcancel.com\` so that server members won't require an account to view content and threads:\n${updated_link_list}`,
4726
);
27+
28+
await message.suppressEmbeds(true);
4829
} catch {
4930
// don't handle failures
5031
}

0 commit comments

Comments
 (0)