- #bot.add_event_handler("muc::%s::got_online" % self.bot.room, self.muc_online)
-
- def muc_message(self, msg):
- """
- Process incoming message stanzas from any chat room. Be aware
- that if you also have any handlers for the 'message' event,
- message stanzas may be processed by both handlers, so check
- the 'type' attribute when using a 'message' event handler.
-
- Whenever the bot's nickname is mentioned, respond to
- the message.
-
- IMPORTANT: Always check that a message is not from yourself,
- otherwise you will create an infinite loop responding
- to your own messages.
-
- This handler will reply to messages that mention
- the bot's nickname.
-
- Arguments:
- msg -- The received message stanza. See the documentation
- for stanza objects and the Message stanza to see
- how it may be used.
- """
- if msg['mucnick'] != self.bot.nick and self.bot.nick in msg['body']:
- self.bot.send_message(mto=msg['from'].bare,
- mbody='I heard that, %s.' % msg['mucnick'],
- mtype='groupchat')
-
- def muc_online(self, presence):
- """
- Process a presence stanza from a chat room. In this case,
- presences from users that have just come online are
- handled by sending a welcome message that includes
- the user's nickname and role in the room.
-
- Arguments:
- presence -- The received presence stanza. See the
- documentation for the Presence stanza
- to see how else it may be used.
- """
- if presence['muc']['nick'] != self.bot.nick:
- self.bot.send_message(mto=presence['from'].bare,
- mbody='Hello, %s %s' % (presence['muc']['role'],
- presence['muc']['nick']),
- mtype='groupchat')
+ bot.add_event_handler("muc::%s::presence" %
+ self.bot.room, self.log_presence)
+
+ def log_presence(self, pres):
+ """Handler method registering MUC participants presence"""
+ self.log.debug('%s: %s', pres['muc']['nick'], pres['type'])
+ nick = pres['muc']['nick']
+ self.presence.update({nick: (pres['muc']['role'], pres['type'])})
+ self.log.debug(self.presence)
+ if pres['type'] == 'available':
+ while self.inbox.get(nick, []):
+ self.send(self.bot.room,
+ self.inbox.get(nick).pop(),
+ mtype='groupchat')
+ self.inbox.pop(nick)