Skip to content

Commit

Permalink
Fix Track for replies (#81)
Browse files Browse the repository at this point in the history
The logic for tracking forwarded messages accidentally started tracking
the wrong message in replies. This checks that it’s not a reply when
fetching the referenced message.
  • Loading branch information
vcarl authored Oct 22, 2024
1 parent 7f1faed commit b3afa1d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/helpers/modLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type {
User,
ClientUser,
} from "discord.js";
import { ChannelType } from "discord.js";
import { MessageType, ChannelType } from "discord.js";
import { format, formatDistanceToNowStrict } from "date-fns";
import TTLCache from "@isaacs/ttlcache";

import { fetchSettings, SETTINGS } from "~/models/guilds.server";
Expand All @@ -15,7 +16,6 @@ import {
quoteAndEscapePoll,
} from "~/helpers/discord";
import { simplifyString, truncateMessage } from "~/helpers/string";
import { format, formatDistanceToNowStrict } from "date-fns";

export const enum ReportReasons {
anonReport = "anonReport",
Expand Down Expand Up @@ -165,10 +165,16 @@ const constructLog = async ({
SETTINGS.moderator,
]);
let { message } = lastReport;
if (lastReport.message.reference) {
if (
// If there's a reference and it's not a reply, it's a forwarded message.
// Fetch the reference and track that message.
lastReport.message.type !== MessageType.Reply &&
lastReport.message.reference
) {
message = await message.fetchReference();
}

// This should never be possible but we gotta satisfy types
if (!moderator) {
throw new Error("No role configured to be used as moderator");
}
Expand All @@ -180,6 +186,7 @@ const constructLog = async ({
} channels ${formatDistanceToNowStrict(lastReport.message.createdAt)} ago`;
const extra = origExtra ? `${origExtra}\n` : "";

// If it has the data for a poll, use a specialized formatting function
const reportedMessage = message.poll
? quoteAndEscapePoll(message.poll)
: quoteAndEscape(message.content).trim();
Expand Down

0 comments on commit b3afa1d

Please sign in to comment.