def _bot_message(self, msg, types=("chat", "normal")): """ Incoming message handler. """ msg_type = msg["type"] if msg_type == "error": error = msg["error"] logger.error( 'Received error message from=%s to=%s: type="%s", condition="%s"', msg["from"], msg["to"], error["type"], error["condition"], ) if msg_type not in types: if msg_type != "groupchat": # Groupchat is handled by muc_message() logger.warning("Unhandled %s message from %s: %s", msg_type, msg["from"], msg) return if self.is_msg_delayed(msg): return # Ignore delayed messages # Wrap around the Message object msg = IncomingLudolphMessage.wrap_msg(msg) # Fire the bot_message event (by default: self._run_command()) self._run_event_handlers("bot_message", msg)
def _bot_message(self, msg, types=('chat', 'normal')): """ Incoming message handler. """ msg_type = msg['type'] if msg_type == 'error': error = msg['error'] logger.error( 'Received error message from=%s to=%s: type="%s", condition="%s"', msg['from'], msg['to'], error['type'], error['condition']) if msg_type not in types: if msg_type != 'groupchat': # Groupchat is handled by muc_message() logger.warning('Unhandled %s message from %s: %s', msg_type, msg['from'], msg) return if self.is_msg_delayed(msg): return # Ignore delayed messages # Wrap around the Message object msg = IncomingLudolphMessage.wrap_msg(msg) # Fire the bot_message event (by default: self._run_command()) self._run_event_handlers('bot_message', msg)
def run(self): """Go!""" fun = self.fun try: if self.at: return fun(IncomingLudolphMessage.load(self.args[0])) else: return fun(*self.args, **self.kwargs) except CronJobError as e: logger.error('Error while running cron job "%s" (%s): %s', self.name, self.fqfn, e) return None
def _muc_message(self, msg): """ MUC Incoming message handler. """ if not self._muc_ready: return if msg["mucnick"] == self.nick: return # Loop protection if self.is_msg_delayed(msg): return # Ignore delayed messages # Respond to the message only if the bots nickname is mentioned # And only if we can get user's JID nick = self.nick + ":" if msg["body"].startswith(nick) and self.get_jid(msg): msg["body"] = msg["body"][len(nick) :].lstrip() self._bot_message(msg, types=("groupchat",)) else: # Fire the muc_message event (nothing by default) self._run_event_handlers("muc_message", IncomingLudolphMessage.wrap_msg(msg))
def _muc_message(self, msg): """ MUC Incoming message handler. """ if not self._muc_ready: return if msg['mucnick'] == self.nick: return # Loop protection if self.is_msg_delayed(msg): return # Ignore delayed messages # Respond to the message only if the bots nickname is mentioned # And only if we can get user's JID nick = self.nick + ':' if msg['body'].startswith(nick) and self.get_jid(msg): msg['body'] = msg['body'][len(nick):].lstrip() self._bot_message(msg, types=('groupchat', )) else: # Fire the muc_message event (nothing by default) self._run_event_handlers('muc_message', IncomingLudolphMessage.wrap_msg(msg))