feat: adjust spam filter detection - #77
Conversation
- Add multi-channel spam rate limit - Add logging utilities for mods-logs channels - Adjust rate limit checks for single-channel and multi-channel spam
| message.author.id, | ||
| message.channelId, | ||
| true, | ||
| ); |
There was a problem hiding this comment.
I don't know we should ban people who post messages within the limit without links, maybe time them out?
There was a problem hiding this comment.
It's super rare for someone within 10 seconds to post to 4 channels. Since this comes with a log message and preview of the last-sent message, it's straightforward to undo false positives.
With timeouts, the messages may linger before action is taken, but it's still an option.
We did recently have 1 false positive with the current logic (3 links shared in a single channel within 10 seconds), but it's unclear how many caught cases it had.
- Add `SPAM_FILTER_MULTI_CHANNEL_ACTION` config flag for opt-in banning for experimental multi-channel spam detection. Defaults to timing out the user and sending a mod notification. - Add `wait` general utility - Fix `ban()` function to wait 1 second in between retries
|
I added a |
| export async function wait(delay = 1000) { | ||
| return new Promise((res) => setTimeout(res, delay)); | ||
| } |
There was a problem hiding this comment.
You can do import { setTimeout } from 'node:timers/promises'; and then await setTimeout(n)
There was a problem hiding this comment.
looks like this was being used before but was removed?
| warn: 'warn', | ||
| ban: 'ban', | ||
| }); | ||
| type Bot_Actions_Type = (typeof BOT_ACTIONS)[keyof typeof BOT_ACTIONS]; |
There was a problem hiding this comment.
| type Bot_Actions_Type = (typeof BOT_ACTIONS)[keyof typeof BOT_ACTIONS]; | |
| type BotActionsType = (typeof BOT_ACTIONS)[keyof typeof BOT_ACTIONS]; |
|
|
||
| // Flags | ||
| const spam_filter_multi_channel_action: Bot_Actions_Type | string | undefined = | ||
| process.env.SPAM_FILTER_MULTI_CHANNEL_ACTION; |
There was a problem hiding this comment.
Curious of the motivation of this? If we keep it then it should probably just go in the config.ts as well as the constant should be screaming snake (e.g. SPAM_FILTER...)
| const BOT_ACTIONS = Object.freeze({ | ||
| warn: 'warn', | ||
| ban: 'ban', | ||
| }); | ||
| type Bot_Actions_Type = (typeof BOT_ACTIONS)[keyof typeof BOT_ACTIONS]; |
There was a problem hiding this comment.
Could this also just be type BotAction = 'warn' | 'ban';?
- Move `SPAM_FILTER_MULTI_CHANNEL_ACTION` variable to the central config. - Remove unnecessary `wait` util
Closes #76