Skip to content

Commit

Permalink
Filter out linked roles and soundmoji from <> card search invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlul committed Feb 1, 2025
1 parent 579ab47 commit 5a7fff7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/events/message-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,21 @@ const parser = parserFor(ourRules);

// https://discord.com/developers/docs/reference#message-formatting-formats
const mentionPatterns = (
["UserWithOptionalNickname", "Channel", "Role", "SlashCommand", "Emoji", "Timestamp"] as const
[
"UserWithOptionalNickname",
"Channel",
"Role",
"SlashCommand",
"Emoji",
"Timestamp",
"GuildNavigation",
"LinkedRole"
] as const
).map(key => new RegExp(FormattingPatterns[key], `${FormattingPatterns[key].flags}g`));

const undocumentedPatterns = [
"<id:browse>", // "Browse Channels"
"<id:customize>", // "Customise Community"
"<id:home>", // links to community rules channel
"<id:guide>" // "Server Guide"
"<id:home>", // links to community rules channel, alias of Server Guide
/<sound:\d+:\d+>/g // Soundmoji https://github.com/discord/discord-api-docs/pull/7357
];

export function cleanMessageMarkup(message: string): string {
Expand Down
28 changes: 28 additions & 0 deletions test/unit/events/message-search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ describe("clean markup", () => {
const message = cleanMessageMarkup("<t:1618953630:d>");
expect(message.trim()).toBe("");
});
test("prunes Browse Channels guild navigation", () => {
const message = cleanMessageMarkup("<id:browse>");
expect(message.trim()).toBe("");
});
test("prunes Customise Community guild navigation", () => {
const message = cleanMessageMarkup("<id:customize>");
expect(message.trim()).toBe("");
});
test("prunes community rules channel guild navigation", () => {
const message = cleanMessageMarkup("<id:home>");
expect(message.trim()).toBe("");
});
test("prunes Server Guide guild navigation", () => {
const message = cleanMessageMarkup("<id:guide>");
expect(message.trim()).toBe("");
});
test("prunes Linked Roles guild navigation", () => {
const message = cleanMessageMarkup("<id:linked-roles>");
expect(message.trim()).toBe("");
});
test("prunes Linked Role connection guild navigation", () => {
const message = cleanMessageMarkup("<id:linked-roles:12345678901234567890>");
expect(message.trim()).toBe("");
});
test("prunes soundmoji", () => {
const message = cleanMessageMarkup("<sound:1207219133914288179:1311935506866770011>");
expect(message.trim()).toBe("");
});
});

describe("preprocess message to get inputs", () => {
Expand Down

0 comments on commit 5a7fff7

Please sign in to comment.