freeCodeCamp / camperchan

Discord bot running in our freeCodeCamp Discord server
https://discord.gg/KVUmVXA
BSD 3-Clause "New" or "Revised" License
29 stars 26 forks source link

[FEATURE] Add command throttling #126

Closed bradtaniguchi closed 2 years ago

bradtaniguchi commented 4 years ago

Is your feature request related to a problem? Please describe. Currently users can call commands as often as quickly as possible. This allows for easier spam situations.

Describe the solution you'd like We should throttle command calling by user to prevent spam.

Additional context Here are the docs on the subject: https://discordjs.guide/commando/throttling.html#throttling

naomi-lgbt commented 4 years ago

Those docs appear to require the use of discord.js-commando which hasn't been updated in two years.

It looks like it still might work, but would require a complete refactor of our code.

bradtaniguchi commented 4 years ago

could always re-engineer some other solution, either manually or some other way :)

naomi-lgbt commented 4 years ago

How about this?

I could create a variable that counts how many times the bot has detected a command, have the bot reject the call if that variable hits 10, and set an interval to clear that count every minute. That would effectively mean the bot would only respond to 10 command calls a minute (across all users and commands), averaging to one call every six seconds.

bradtaniguchi commented 4 years ago

Taking the old unmaintained bot extesnions as an example, this code does something similar to what we should have: https://github.com/discordjs/Commando/blob/f80823ed6fc3887a8cfb74a9345c59c6c2658545/src/extensions/message.js#L179

where the bot will limit the same user + command from being spammed. Other user's aren't affected by any limiting.

naomi-lgbt commented 2 years ago

Discord automatically rate-limits slash commands so we no longer need this.