def message(self, msg: Message) -> Optional[Future]: """Handle received message and submit the result to message worker. :param msg: Received message. :return: Optional Future instance that represent message sending result. """ if msg['delay']['stamp']: # Avoid answering to all past messages when joining the room. # xep_0203 plugin required. # http://xmpp.org/extensions/xep-0203.html # # FYI: When resource part of bot JabberID is 'bot' such as # [email protected]/bot, HipChat won't send us past messages return None if msg['type'] in ('normal', 'chat'): # msg.reply("Thanks for sending\n%(body)s" % msg).send() pass elif msg['type'] == 'groupchat': # Don't talk to yourself. It's freaking people out. group_plugin = self.client.plugin['xep_0045'] my_nick = group_plugin.ourNicks[msg.get_mucroom()] sender_nick = msg.get_mucnick() if my_nick == sender_nick: return None ret = self.respond(msg['from'], msg['body']) if ret: return self.enqueue_sending_message(lambda: msg.reply(ret).send())