Skip to content

feat: adjust spam filter detection - #77

Merged
ghostdevv merged 7 commits into
mainfrom
feat/antispam-enhancements
Jul 1, 2026
Merged

feat: adjust spam filter detection#77
ghostdevv merged 7 commits into
mainfrom
feat/antispam-enhancements

Conversation

@theetrain

Copy link
Copy Markdown
Collaborator

Closes #76

  • Add multi-channel spam rate limit
  • Add logging utilities for mods-logs channels
  • Adjust rate limit checks for single-channel and multi-channel spam

- Add multi-channel spam rate limit
- Add logging utilities for mods-logs channels
- Adjust rate limit checks for single-channel and multi-channel spam
Comment thread src/utils/ratelimit.ts
@theetrain
theetrain marked this pull request as ready for review June 27, 2026 04:15
@theetrain
theetrain requested a review from ghostdevv June 27, 2026 04:15
message.author.id,
message.channelId,
true,
);

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 don't know we should ban people who post messages within the limit without links, maybe time them out?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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
@theetrain

Copy link
Copy Markdown
Collaborator Author

I added a SPAM_FILTER_MULTI_CHANNEL_ACTION config flag. If unset, it will timeout users of multi-channel spam. If set to 'ban', it will ban offending users and clean up messages.

Comment thread src/utils/index.ts Outdated
Comment on lines +6 to +8
export async function wait(delay = 1000) {
return new Promise((res) => setTimeout(res, delay));
}

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.

You can do import { setTimeout } from 'node:timers/promises'; and then await setTimeout(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.

looks like this was being used before but was removed?

Comment thread src/events/on_message/_spam_filter.ts Outdated
warn: 'warn',
ban: 'ban',
});
type Bot_Actions_Type = (typeof BOT_ACTIONS)[keyof typeof BOT_ACTIONS];

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.

Suggested change
type Bot_Actions_Type = (typeof BOT_ACTIONS)[keyof typeof BOT_ACTIONS];
type BotActionsType = (typeof BOT_ACTIONS)[keyof typeof BOT_ACTIONS];

Comment thread src/events/on_message/_spam_filter.ts Outdated

// Flags
const spam_filter_multi_channel_action: Bot_Actions_Type | string | undefined =
process.env.SPAM_FILTER_MULTI_CHANNEL_ACTION;

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.

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...)

Comment thread src/events/on_message/_spam_filter.ts Outdated
Comment on lines +10 to +14
const BOT_ACTIONS = Object.freeze({
warn: 'warn',
ban: 'ban',
});
type Bot_Actions_Type = (typeof BOT_ACTIONS)[keyof typeof BOT_ACTIONS];

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.

Could this also just be type BotAction = 'warn' | 'ban';?

- Move `SPAM_FILTER_MULTI_CHANNEL_ACTION` variable to the central
  config.
- Remove unnecessary `wait` util
@theetrain
theetrain requested a review from ghostdevv July 1, 2026 01:36
@ghostdevv ghostdevv changed the title feat(spam_filter): adjust spam detection feat: adjust spam filter detection Jul 1, 2026
@ghostdevv
ghostdevv merged commit ad2ffc3 into main Jul 1, 2026
1 check passed
@ghostdevv
ghostdevv deleted the feat/antispam-enhancements branch July 1, 2026 13:38
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.

Anti spam

2 participants