Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/commands/track.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const handler = async (
) => {
const { targetMessage: message, user } = interaction;

const { message: logMessage } = await reportUser({
const reportPromise = reportUser({
reason: ReportReasons.track,
message,
staff: user,
Expand All @@ -30,11 +30,15 @@ export const handler = async (
label="Delete message"
style="danger"
onClick={async () => {
// Need to ensure that we've finished reporting before we try to
// respond to a click event.
// Initiating at the top level and waiting here is a big UX win.
const { message: logMessage } = await reportPromise;
await Promise.allSettled([
message.delete(),
logMessage.reply({
allowedMentions: { users: [] },
content: `Messaged deleted by <@${user.id}>`,
content: `Message in <#${message.channelId}> deleted by <@${user.id}>`,
}),
]);
instance.render("Tracked");
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/discord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ test("escapeDisruptiveContent", () => {
expect(escapeDisruptiveContent("https://example.com")).toBe(
"<https://example.com>",
);
expect(
escapeDisruptiveContent(
"some dumb text https://example.com with a link and text",
),
).toBe("some dumb text <https://example.com> with a link and text");
expect(escapeDisruptiveContent("some dumb text https://example.com")).toBe(
"some dumb text <https://example.com>",
);
});
3 changes: 2 additions & 1 deletion app/helpers/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const describeAttachments = (attachments: Message["attachments"]) => {
.join("\n");
};

const urlRegex = /(https?:\/\/\S+)\b/g;
/*
* Escape content that Discord would otherwise do undesireable things with.
* Sepecifically, suppresses @-mentions and link previews.
Expand All @@ -94,7 +95,7 @@ export const escapeDisruptiveContent = (content: string) => {
// Silence pings
.replace(/@(\S*)(\s)?/g, "@ $1$2")
// Wrap links in <> so they don't make a preview
.replace(/(https?:\/\/.*)\s?/g, "<$1>")
.replace(urlRegex, "<$1>")
);
};

Expand Down
8 changes: 5 additions & 3 deletions app/helpers/modLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export const reportUser = async ({
});

const warningMessage = await modLog.send(logBody);
const thread = await warningMessage.startThread({
name: message.content.slice(0, 50).toLocaleLowerCase().trim(),
});
await thread.send(quoteAndEscape(message.content).trim().slice(0, 2000));

warningMessages.set(simplifiedContent, {
logMessage: warningMessage,
Expand Down Expand Up @@ -124,15 +128,13 @@ const constructLog = async ({
)} ago`;
const extra = origExtra ? `\n${origExtra}\n` : "";

const reportedMessage = quoteAndEscape(lastReport.message.content).trim();
const attachments = describeAttachments(lastReport.message.attachments);

return {
content: truncateMessage(`${preface}

${reports}
${extra}
${reportedMessage}`),
${extra}`),
embeds: attachments ? [{ description: `\n\n${attachments}` }] : undefined,
};
};