Skip to content

feat: better spam detection logging for different rule types - #5

Merged
hmd-ali merged 4 commits into
mainfrom
feat/better-spam-detection-logging
Nov 8, 2025
Merged

hmd-ali merged 4 commits into
mainfrom
feat/better-spam-detection-logging

Conversation

@hmd-ali

@hmd-ali hmd-ali commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@hmd-ali
hmd-ali requested a review from wiktoriavh November 7, 2025 17:17
Comment thread src/events/spam-detection/logs.ts Outdated
Comment on lines +33 to +34
contentString += `**Rule Broken:** ${options.reason}\n`;
contentString += `**User:** <@${options.messages[0].author.id}>\n`;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you not use the makeLogMessageTitleAndContent function here?

Comment on lines +47 to +65
case "crossChannel": {
if (options.rule.isBrokenBy.name === "isCrossPost") {
contentString += `Posted in **${options.rule.channelCount}** channels within **${timeToString(options.rule.timeframe)} **\n`;
const flaggedMessage = options.messages[0];
const affectedChannels = new Set(options.messages.map((message) => message.channelId));
contentString += makeLogMessageTitleAndContent(
"Flagged Message",
`\n\n${flaggedMessage.content}\n`
);
contentString += SPACER;
contentString += makeLogMessageTitleAndContent(
"Channels Involved",
Array.from(affectedChannels)
.map((id) => `<#${id}>`)
.join(", ")
);
}
break;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there an if statement inside the switch rule? and no else? so what is the scenario of running into this switch statement, but the if statement is false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we could later have another rule that's based on posting in multiple channels, but not being a crossPost, in the case of crossPost, we know that the messages are the same, so we just log 1 message.
But a new rule could be something like "Posting ANY message in 10 channels", so we might want to use another log.

Comment thread src/utils/time.ts
Comment on lines +3 to +32
export const timeToString = (ms: number): string => {
const timeUnits = [
{ label: "day", value: DAY },
{ label: "hour", value: HOUR },
{ label: "minute", value: MINUTE },
{ label: "second", value: SECOND },
];

const formatTime = (remaining: number, units: typeof timeUnits): string => {
if (remaining === 0 || units.length === 0) {
return "";
}

const [currentUnit, ...restUnits] = units;
const count = Math.floor(remaining / currentUnit.value);
const remainder = remaining % currentUnit.value;

if (count === 0) {
return formatTime(remainder, restUnits);
}

const currentString = `${count} ${currentUnit.label}${count === 1 ? "" : "s"}`;
const restString = formatTime(remainder, restUnits);

return restString ? `${currentString}, ${restString}` : currentString;
};

const result = formatTime(ms, timeUnits);
return result || "0 seconds";
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i find this a bit confusing. what could a result look like if it isn't 0 seconds?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hmd-ali
hmd-ali merged commit 093479d into main Nov 8, 2025
1 check passed
@hmd-ali
hmd-ali deleted the feat/better-spam-detection-logging branch November 8, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants