mattoufoutu/fatbotslim — Issue #3: command handlers should specify on which event type they should react
Author: mattoufoutu
Created: 2012-01-05 12:29:44+00:00
State: open
Labels: feature, handlers

By default, command handlers call the command method on all event types (private/public/notice message), making the developer having to write conditionnal statements in the methods to filter the event on which he wants his code to be called.

For example, to have a command that reacts only on public messages, one should have to write it like this:

```python
class HelloCommand(CommandHandler):
def hello(self, msg, irc):
if (msg.command == PRIVMSG) and (msg.dst != irc.nick):
irc.msg(msg.dst, "Hello, {0}!".format(msg.src.name))
```

This makes creating commands that react to only some events fastidious, it should be easier to define on what event the method should be called.

Something like this could be nice:

```python
class HelloCommand(CommandHandler):
triggers = {'hello': ('public',),} # where the value is a tuple containing one or more of ['public', 'private', 'notice']
def hello(self, msg, irc):
irc.msg(msg.dst, "Hello, {0}!".format(msg.src.name))
```