Skip to content

Commit

Permalink
Remove timestamp from report
Browse files Browse the repository at this point in the history
  • Loading branch information
vcarl committed May 19, 2024
1 parent 7ed83f3 commit e2c5ed1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
19 changes: 6 additions & 13 deletions app/discord/automod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { Client, TextChannel } from "discord.js";

import { SETTINGS, fetchSettings } from "~/models/guilds.server";
import type { Client } from "discord.js";

import { isStaff } from "~/helpers/discord";
import { reportUser, ReportReasons } from "~/helpers/modLog";
Expand All @@ -18,7 +16,7 @@ const spamKeywords = [
"gift",
"\\d\\$",
"18+",
"nudes"
"nudes",
].map((x) => new RegExp(x));
const spamPings = ["@everyone", "@here"];
const safeKeywords = ["forhire", "hiring", "remote", "onsite"];
Expand Down Expand Up @@ -70,7 +68,7 @@ export default async (bot: Client) => {
}

if (isSpam(message.content)) {
const [{ warnings }] = await Promise.all([
const [{ warnings, message: logMessage }] = await Promise.all([
reportUser({
reason: ReportReasons.spam,
message: message,
Expand All @@ -80,16 +78,11 @@ export default async (bot: Client) => {
]);

if (warnings >= AUTO_SPAM_THRESHOLD) {
const { modLog: modLogId } = await fetchSettings(message.guild, [
SETTINGS.modLog,
]);
const modLog = (await message.guild.channels.fetch(
modLogId,
)) as unknown as TextChannel;
if (!modLog) throw new Error("Failed to load mod log when automodding");
await Promise.all([
member.kick("Autokicked for spamming"),
modLog.send(`Automatically kicked <@${message.author.id}> for spam`),
logMessage.reply(
`Automatically kicked <@${message.author.id}> for spam`,
),
]);
}
}
Expand Down
23 changes: 9 additions & 14 deletions app/helpers/modLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ interface Report {
message: Message;
extra?: string;
staff: User | ClientUser | false;
date: Date;
}

const makeLogThread = (message: Message, user: User) => {
Expand Down Expand Up @@ -60,7 +59,7 @@ export const reportUser = async ({
message.author.id
}${simplifyString(message.content)}`;
const cached = warningMessages.get(simplifiedContent);
const newReport = { message, reason, staff, date: new Date() };
const newReport: Report = { message, reason, staff };

if (cached) {
// If we already logged for ~ this message, post to the existing thread
Expand All @@ -75,7 +74,7 @@ export const reportUser = async ({
}

const [latestReport] = await Promise.all([
thread.send({ content: await makeReportString(newReport) }),
thread.send({ content: makeReportString(newReport) }),
cachedMessage.edit(
cachedMessage.content?.replace(
/warned \d times/,
Expand All @@ -93,20 +92,17 @@ export const reportUser = async ({
// If this is new, send a new message
const { modLog: modLogId } = await fetchSettings(guild, [SETTINGS.modLog]);
const modLog = (await guild.channels.fetch(modLogId)) as TextChannel;
const newLogs = [{ message, reason, staff, date: new Date() }];
const newLogs: Report[] = [{ message, reason, staff }];

const logBody = await constructLog({
extra,
logs: newLogs,
staff,
});

const [warningMessage, reportString] = await Promise.all([
modLog.send(logBody),
makeReportString(newReport),
]);
const warningMessage = await modLog.send(logBody);
const thread = await makeLogThread(warningMessage, message.author);
const latestReport = await thread.send(reportString);
const latestReport = await thread.send(makeReportString(newReport));

warningMessages.set(simplifiedContent, {
logMessage: warningMessage,
Expand All @@ -116,10 +112,10 @@ export const reportUser = async ({
}
};

const makeReportString = ({ message, reason, staff, date }: Report) =>
const makeReportString = ({ message, reason, staff }: Report) =>
`- ${constructDiscordLink(message)} ${staff ? ` ${staff.username} ` : ""}${
ReadableReasons[reason]
} on ${format(date, "Pp")}`;
}`;

const constructLog = async ({
logs,
Expand All @@ -134,15 +130,14 @@ const constructLog = async ({
}) warned ${logs.length} times, posted ${formatDistanceToNowStrict(
lastReport.message.createdAt,
)} ago`;
const extra = origExtra ? `\n${origExtra}\n` : "";
const extra = origExtra ? `${origExtra}\n` : "";

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

return {
content: truncateMessage(`${preface}
${extra}
${reportedMessage}`).trim(),
${extra}${reportedMessage}`).trim(),
embeds: attachments ? [{ description: `\n\n${attachments}` }] : undefined,
};
};

0 comments on commit e2c5ed1

Please sign in to comment.