StrawbrryFlurry / watson

🚀 Fast, scalable framework for building Discord applications
MIT License
32 stars 1 forks source link

Command rate-limiting #12

Open StrawbrryFlurry opened 3 years ago

StrawbrryFlurry commented 3 years ago

Feature rate-limiting for commands on a user/guild-based context.

SemiShogun commented 3 years ago

Does the Watson library contain any user/guild classes for retrieving user metadata? I think we could check on every request whether or not a specific user has exceeded a rate limit during a specific timespan.

StrawbrryFlurry commented 3 years ago

Yeah, I think we could implement this pretty easily. The data doesn't really need to be persistent so we just store it in memory. A map should work just fine for this but redis might also be worth a try.

A very basic implementation would look something like this: In the RouteHandlerFactory, we add a map for caching command calls for each user as well as their guild. In the createCommandHandler, which basically creates the function that is called once we match a certain command from a user message, we add an additional step that handles the rate-limiting.

I've created a new branch with an example implementation of how this could look like on a per guild/user basis: Commit