Repository navigation
feat: better spam detection logging for different rule types - #5
Conversation
| contentString += `**Rule Broken:** ${options.reason}\n`; | ||
| contentString += `**User:** <@${options.messages[0].author.id}>\n`; |
There was a problem hiding this comment.
why did you not use the makeLogMessageTitleAndContent function here?
| 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; | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| 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"; | ||
| }; |
There was a problem hiding this comment.
i find this a bit confusing. what could a result look like if it isn't 0 seconds?
There was a problem hiding this comment.
No description provided.