cinchrb / cinch

The IRC Bot Building Framework
http://www.rubydoc.info/gems/cinch
MIT License
1k stars 180 forks source link

Support for bot response throttling / cooldowns. #79

Closed bhaberer closed 12 years ago

bhaberer commented 12 years ago

I'm going to see what I can do on this issue myself. However, it's your bot so I figured I would drop a feature request to see if you have a better idea of how to do this or if was supported somewhere in the code that I've overlooked.

Basically I'm making a bot for a fairly active channel, and several of the commands have a tendency to incite many people to spam them which unfortunately causes the bot to fill up people's screens pretty quickly. In the past we had a bot that was rate limited, but that didn't help as much as when we added a internal cooldown. The cooldown discouraged people from spamming commands too quickly because their commands just got dropped on the floor.

I'm going to try and find a way that I can essentially flag plugins as cooldown applicable and have them inherit a config value for duration of the cooldown. Assuming it works I'll send a pull.

dominikh commented 12 years ago

While I appreciate your effort, I don't think I would pull it. While it is a nice feature, it seems to be something that should be distributed as an extension and not with the core of Cinch, mainly because there are many different ways to implement this.

To aid you in implementing it: Look into extending Cinch::Plugin::ClassMethods to add a method that configures the cooldown and sets up a filter (i.e. a hook) which will drop messages as appropriate. pre-hooks that return false will drop a message and prevent it from further being processed in the plugin the hook belongs to. (The same approach can be used for things like ACLs. An example of that can be found here: https://gist.github.com/2e42f9d4768515175366 – Don't worry about the specifics of the ACL mechanism and just see how the message dropping and dynamic filtering is being done.)

bhaberer commented 12 years ago

Thanks, I'll take a look. I was mainly looking for things that might be baked in to avoid doing anything gross.

Just trying to avoid having to manage my own fork unless absolutely necessary.

dominikh commented 12 years ago

Well, all the APIs necessary to implement your cooldown already exist, so yeah, a fork should not be needed.

bhaberer commented 12 years ago

Works like a charm; thanks for the help.