--- a/rollbot.py Wed May 11 14:43:23 2016 +0800
+++ b/rollbot.py Sat May 14 14:05:49 2016 +0800
+ def __init__(self, rollbot):
+ return '(no help available, try experimenting)'
+ return '%s or %s <command>' % (self.name, self.name)
+ def respond(self, words, message):
+ if cmdname in self.rollbot.commands:
+ command = self.rollbot.commands[cmdname]
+ return '%s usage: %s' % (command.name, command.usage())
+ return 'no such command: %s' % cmdname
+ cmds = ' '.join(sorted(self.rollbot.commands.keys()))
+ return 'available commands: %s' % cmds
+ return '%s usage: %s' % (self.name, self.usage())
class RollBot(sleekxmpp.ClientXMPP):
def __init__(self, jid, password, nick, prefix):
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.add_event_handler('session_start', self.start)
self.add_event_handler('message', self.message)
self.add_event_handler('groupchat_invite', self.muc_invite)
self.add_event_handler('groupchat_direct_invite', self.muc_direct_invite)
+ def add_command(self, commandcls):
+ self.commands[commandcls.name] = commandcls(self)
def respond(self, message, prefix=None):
- for command in self.commands:
- response = command.parse(message)
+ words = message.split()
+ cmdname = words[0].lower()
+ if cmdname in self.commands:
+ command = self.commands[cmdname]
+ response = command.respond(words, message)