--- a/rollbot.py Tue May 10 17:17:47 2016 +0800
+++ b/rollbot.py Wed May 11 00:04:29 2016 +0800
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_message', self.muc_message)
self.add_event_handler('groupchat_invite', self.muc_invite)
self.add_event_handler('groupchat_direct_invite', self.muc_direct_invite)
+ def message(self, msg):
+ if msg['type'] not in ('chat', 'normal'):
+ rbody = self.respond(msg['body'].strip())
+ def muc_message(self, msg):
+ if msg['mucnick'] == self.nick:
+ mbody = msg['body'].lstrip()
+ if mbody.startswith(self.nick):
+ mbody = mbody[len(self.nick):]
+ elif mbody.startswith(self.prefix):
+ mbody = mbody[len(self.prefix):]
+ mbody = mbody.lstrip(':, \t')
+ rbody = self.respond(mbody)
+ rbody = '%s: %s' % (msg['mucnick'], rbody)
def muc_invite(self, invite):
password = '' # https://github.com/fritzy/SleekXMPP/issues/409
password = invite['groupchat_invite']['password']
self.plugin['xep_0045'].joinMUC(room, self.nick, password=password, wait=True)
+ def respond(self, message, prefix=None):
+ for command in self.commands:
+ response = command.parse(message)
def lookup(key, args, config, default=None):