diff options
author | Sean B. Palmer <http://inamidst.com/sbp/> | 2008-02-29 15:36:18 +0000 |
---|---|---|
committer | Sean B. Palmer <http://inamidst.com/sbp/> | 2008-02-29 15:36:18 +0000 |
commit | 3d920f431789ac53596933785b5fe61463335e3b (patch) | |
tree | 654b01dfb141aba551d400393263fa6914ba9310 /bot.py | |
parent | cbdf9ebd7312bf570a212057ad793ae520bac38f (diff) | |
download | bot-3d920f431789ac53596933785b5fe61463335e3b.tar.gz bot-3d920f431789ac53596933785b5fe61463335e3b.tar.bz2 bot-3d920f431789ac53596933785b5fe61463335e3b.zip |
Some more little fixes, and added a Makefile.
Diffstat (limited to 'bot.py')
-rwxr-xr-x | bot.py | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -79,17 +79,16 @@ class Phenny(irc.Bot): def bind(self, priority, regexp, func): print priority, regexp.pattern.encode('utf-8'), func - self.commands[priority].setdefault(regexp, []).append(func) - # @@ register documentation + # register documentation + if not hasattr(func, 'name'): + func.name = func.__name__ if func.__doc__: - if hasattr(func, 'name'): - name = func.name - else: name = func.__name__ if hasattr(func, 'example'): example = func.example example = example.replace('$nickname', self.nick) else: example = None - self.doc[name] = (func.__doc__, example) + self.doc[func.name] = (func.__doc__, example) + self.commands[priority].setdefault(regexp, []).append(func) def sub(pattern, self=self): # These replacements have significant order @@ -127,8 +126,8 @@ class Phenny(irc.Bot): prefix = self.config.prefix commands, pattern = func.rule for command in commands: - command = r'(%s) +' % command - regexp = re.compile(prefix + command + pattern) + command = r'(%s)(?: +(?:%s))?' % (command, pattern) + regexp = re.compile(prefix + command) bind(self, func.priority, regexp, func) # 3) e.g. ('$nick', ['p', 'q'], '(.*)') @@ -196,8 +195,6 @@ class Phenny(irc.Bot): match = regexp.match(text) if match: - # print 'STATS:', origin.sender, func.__name__ - phenny = self.wrapped(origin, text, match) input = self.input(origin, text, bytes, match, event) @@ -207,5 +204,10 @@ class Phenny(irc.Bot): t.start() else: self.call(func, origin, phenny, input) + for source in [origin.sender, origin.nick]: + try: self.stats[(func.name, source)] += 1 + except KeyError: + self.stats[(func.name, source)] = 1 + if __name__ == '__main__': print __doc__ |