def _message_event_handler(self, event): """Event handler for the 'message' event""" channel = event['channel'] if channel.startswith('C'): logging.debug("Handling message from a public channel") message_type = 'groupchat' elif channel.startswith('G'): logging.debug("Handling message from a private group") message_type = 'groupchat' elif channel.startswith('D'): logging.debug("Handling message from a user") message_type = 'chat' else: logging.warning("Unknown message type! Unable to handle") return msg = Message(event['text'], type_=message_type) msg.frm = SlackIdentifier( node=self.channelid_to_channelname(event['channel']), domain=self.sc.server.domain, resource=self.userid_to_username(event['user']) ) msg.to = SlackIdentifier( node=self.channelid_to_channelname(event['channel']), domain=self.sc.server.domain, resource=self.sc.server.username ) msg.nick = msg.frm.resource self.callback_message(msg)
def on_pubmsg(self, _, e): msg = Message(e.arguments[0], type_='groupchat') msg.frm = e.target msg.to = self.callback.jid msg.nick = e.source.split('!')[ 0] # FIXME find the real nick in the channel self.callback.callback_message(msg)
def on_pubmsg(self, _, e): msg = Message(e.arguments[0], type_='groupchat') nick = e.source.split('!')[0] room = e.target if room[0] != '#' and room[0] != '$': raise Exception('[%s] is not a room' % room) msg.frm = IRCMUCOccupant(nick, room) msg.to = self.callback.bot_identifier msg.nick = nick # FIXME find the real nick in the channel self.callback.callback_message(msg)
def on_pubmsg(self, _, e): msg = Message(e.arguments[0], type_='groupchat') nick = e.source.split('!')[0] room = e.target if room[0] != '#' and room[0] != '$': raise Exception('[%s] is not a room' % room) msg.frm = IRCMUCOccupant(nick, room) msg.to = self.callback.bot_identifier msg.nick = nick # FIXME find the real nick in the channel self.callback.callback_message(msg)
def incoming_message(self, xmppmsg): """Callback for message events""" msg = Message(xmppmsg['body']) if 'html' in xmppmsg.keys(): msg.html = xmppmsg['html'] msg.frm = xmppmsg['from'].full msg.to = xmppmsg['to'].full msg.type = xmppmsg['type'] msg.nick = xmppmsg['mucnick'] msg.delayed = bool(xmppmsg['delay']._get_attr('stamp')) # this is a bug in sleekxmpp it should be ['from'] self.callback_message(msg)
def _message_event_handler(self, event): """Event handler for the 'message' event""" channel = event['channel'] if channel.startswith('C'): log.debug("Handling message from a public channel") message_type = 'groupchat' elif channel.startswith('G'): log.debug("Handling message from a private group") message_type = 'groupchat' elif channel.startswith('D'): log.debug("Handling message from a user") message_type = 'chat' else: log.warning("Unknown message type! Unable to handle") return subtype = event.get('subtype', None) if subtype == "message_deleted": log.debug("Message of type message_deleted, ignoring this event") return if subtype == "message_changed" and 'attachments' in event['message']: # If you paste a link into Slack, it does a call-out to grab details # from it so it can display this in the chatroom. These show up as # message_changed events with an 'attachments' key in the embedded # message. We should completely ignore these events otherwise we # could end up processing bot commands twice (user issues a command # containing a link, it gets processed, then Slack triggers the # message_changed event and we end up processing it again as a new # message. This is not what we want). log.debug( "Ignoring message_changed event with attachments, likely caused " "by Slack auto-expanding a link" ) return if 'message' in event: text = event['message']['text'] user = event['message']['user'] else: text = event['text'] user = event['user'] msg = Message(text, type_=message_type) if message_type == 'chat': msg.frm = SlackIdentifier(self.sc, user, event['channel']) msg.to = SlackIdentifier(self.sc, self.username_to_userid(self.sc.server.username), event['channel']) else: msg.frm = SlackMUCOccupant(self.sc, user, event['channel']) msg.to = SlackMUCOccupant(self.sc, self.username_to_userid(self.sc.server.username), event['channel']) msg.nick = msg.frm.userid self.callback_message(msg)
def incoming_message(self, xmppmsg): """Callback for message events""" msg = Message(xmppmsg['body']) if 'html' in xmppmsg.keys(): msg.html = xmppmsg['html'] msg.frm = xmppmsg['from'].full msg.to = xmppmsg['to'].full msg.type = xmppmsg['type'] msg.nick = xmppmsg['mucnick'] msg.delayed = bool(xmppmsg['delay']._get_attr('stamp')) # this is a bug in sleekxmpp it should be ['from'] self.callback_message(msg)
def incoming_message(self, xmppmsg): """Callback for message events""" msg = Message(xmppmsg['body']) if 'html' in xmppmsg.keys(): msg.html = xmppmsg['html'] msg.frm = self.build_identifier(xmppmsg['from'].full) msg.to = self.build_identifier(xmppmsg['to'].full) log.debug("incoming_message frm : %s" % msg.frm) if xmppmsg['type'] == 'groupchat': room = XMPPRoom(msg.frm.node + '@' + msg.frm.domain, self) msg.frm = XMPPRoomOccupant(msg.frm.node, msg.frm.domain, msg.frm.resource, room) msg.to = room msg.nick = xmppmsg['mucnick'] msg.delayed = bool(xmppmsg['delay']._get_attr('stamp')) # this is a bug in sleekxmpp it should be ['from'] self.callback_message(msg)
def on_pubmsg(self, _, e): msg = Message(e.arguments[0], type_='groupchat') room = e.target if room[0] != '#' and room[0] != '$': raise Exception('[%s] is not a room' % room) msg.frm = IRCMUCOccupant(e.source, room) msg.to = self.callback.bot_identifier msg.nick = msg.frm.nick # FIXME find the real nick in the channel self.callback.callback_message(msg) possible_mentions = re.findall(IRC_NICK_REGEX, e.arguments[0]) room_users = self.channels[room].users() mentions = filter(lambda x: x in room_users, possible_mentions) if mentions: mentions = [self.build_identifier(mention) for mention in mentions] self.callback.callback_mention(msg, mentions)
def on_pubmsg(self, _, e): msg = Message(e.arguments[0], type_='groupchat') room = e.target if room[0] != '#' and room[0] != '$': raise Exception('[%s] is not a room' % room) msg.frm = IRCMUCOccupant(e.source, room) msg.to = self.callback.bot_identifier msg.nick = msg.frm.nick # FIXME find the real nick in the channel self.callback.callback_message(msg) possible_mentions = re.findall(IRC_NICK_REGEX, e.arguments[0]) room_users = self.channels[room].users() mentions = filter(lambda x: x in room_users, possible_mentions) if mentions: mentions = [self.build_identifier(mention) for mention in mentions] self.callback.callback_mention(msg, mentions)
def _pubmsg(self, e, notice=False): msg = Message(e.arguments[0], extras={'notice': notice}) room_name = e.target if room_name[0] != '#' and room_name[0] != '$': raise Exception(f'[{room_name}] is not a room') room = IRCRoom(room_name, self.bot) msg.frm = IRCRoomOccupant(e.source, room) msg.to = room msg.nick = msg.frm.nick # FIXME find the real nick in the channel self.bot.callback_message(msg) possible_mentions = re.findall(IRC_NICK_REGEX, e.arguments[0]) room_users = self.channels[room_name].users() mentions = filter(lambda x: x in room_users, possible_mentions) if mentions: mentions = [self.bot.build_identifier(mention) for mention in mentions] self.bot.callback_mention(msg, mentions)
def incoming_message(self, xmppmsg): """Callback for message events""" msg = Message(xmppmsg['body']) if 'html' in xmppmsg.keys(): msg.html = xmppmsg['html'] msg.frm = self.build_identifier(xmppmsg['from'].full) msg.to = self.build_identifier(xmppmsg['to'].full) log.debug("incoming_message frm : %s" % msg.frm) log.debug("incoming_message frm node: %s" % msg.frm.node) log.debug("incoming_message frm domain: %s" % msg.frm.domain) log.debug("incoming_message frm resource: %s" % msg.frm.resource) msg.type = xmppmsg['type'] if msg.type == 'groupchat': # those are not simple identifiers, they are muc occupants. msg.frm = XMPPMUCOccupant(msg.frm.node, msg.frm.domain, msg.frm.resource) msg.to = XMPPMUCOccupant(msg.to.node, msg.to.domain, msg.to.resource) msg.nick = xmppmsg['mucnick'] msg.delayed = bool(xmppmsg['delay']._get_attr('stamp')) # this is a bug in sleekxmpp it should be ['from'] self.callback_message(msg)
def incoming_message(self, xmppmsg): """Callback for message events""" msg = Message(xmppmsg["body"]) if "html" in xmppmsg.keys(): msg.html = xmppmsg["html"] msg.frm = self.build_identifier(xmppmsg["from"].full) msg.to = self.build_identifier(xmppmsg["to"].full) log.debug("incoming_message frm : %s" % msg.frm) log.debug("incoming_message frm node: %s" % msg.frm.node) log.debug("incoming_message frm domain: %s" % msg.frm.domain) log.debug("incoming_message frm resource: %s" % msg.frm.resource) msg.type = xmppmsg["type"] if msg.type == "groupchat": # those are not simple identifiers, they are muc occupants. msg.frm = XMPPMUCOccupant(msg.frm.node, msg.frm.domain, msg.frm.resource) msg.to = XMPPMUCOccupant(msg.to.node, msg.to.domain, msg.to.resource) msg.nick = xmppmsg["mucnick"] msg.delayed = bool(xmppmsg["delay"]._get_attr("stamp")) # this is a bug in sleekxmpp it should be ['from'] self.callback_message(msg)
def incoming_message(self, xmppmsg): """Callback for message events""" if xmppmsg['type'] == "error": log.warning("Received error message: %s", xmppmsg) return msg = Message(xmppmsg['body']) if 'html' in xmppmsg.keys(): msg.html = xmppmsg['html'] log.debug("incoming_message from: %s", msg.frm) if xmppmsg['type'] == 'groupchat': msg.frm = self._build_room_occupant(xmppmsg['from'].full) msg.to = msg.frm.room else: msg.frm = self._build_person(xmppmsg['from'].full) msg.to = self._build_person(xmppmsg['to'].full) msg.nick = xmppmsg['mucnick'] msg.delayed = bool(xmppmsg['delay']._get_attr('stamp')) # this is a bug in sleekxmpp it should be ['from'] self.callback_message(msg)
def incoming_message(self, xmppmsg): """Callback for message events""" if xmppmsg['type'] == "error": log.warning("Received error message: %s", xmppmsg) return msg = Message(xmppmsg['body']) if 'html' in xmppmsg.keys(): msg.html = xmppmsg['html'] log.debug("incoming_message from: %s", msg.frm) if xmppmsg['type'] == 'groupchat': msg.frm = self._build_room_occupant(xmppmsg['from'].full) msg.to = msg.frm.room else: msg.frm = self._build_person(xmppmsg['from'].full) msg.to = self._build_person(xmppmsg['to'].full) msg.nick = xmppmsg['mucnick'] msg.delayed = bool(xmppmsg['delay']._get_attr( 'stamp')) # this is a bug in sleekxmpp it should be ['from'] self.callback_message(msg)
def incoming_message(self, xmppmsg): """Callback for message events""" if xmppmsg["type"] == "error": log.warning("Received error message: %s", xmppmsg) return msg = Message(xmppmsg["body"]) if "html" in xmppmsg.keys(): msg.html = xmppmsg["html"] log.debug("incoming_message from: %s", msg.frm) if xmppmsg["type"] == "groupchat": msg.frm = self._build_room_occupant(xmppmsg["from"].full) msg.to = msg.frm.room else: msg.frm = self._build_person(xmppmsg["from"].full) msg.to = self._build_person(xmppmsg["to"].full) msg.nick = xmppmsg["mucnick"] msg.delayed = bool(xmppmsg["delay"]._get_attr( "stamp")) # this is a bug in slixmpp it should be ['from'] self.callback_message(msg)
def incoming_message(self, xmppmsg): """Callback for message events""" msg = Message(xmppmsg['body']) if 'html' in xmppmsg.keys(): msg.html = xmppmsg['html'] msg.frm = self.build_identifier(xmppmsg['from'].full) msg.to = self.build_identifier(xmppmsg['to'].full) log.debug("incoming_message frm : %s" % msg.frm) log.debug("incoming_message frm node: %s" % msg.frm.node) log.debug("incoming_message frm domain: %s" % msg.frm.domain) log.debug("incoming_message frm resource: %s" % msg.frm.resource) msg.type = xmppmsg['type'] if msg.type == 'groupchat': # those are not simple identifiers, they are muc occupants. msg.frm = XMPPMUCOccupant(msg.frm.node, msg.frm.domain, msg.frm.resource) msg.to = XMPPMUCOccupant(msg.to.node, msg.to.domain, msg.to.resource) msg.nick = xmppmsg['mucnick'] msg.delayed = bool(xmppmsg['delay']._get_attr( 'stamp')) # this is a bug in sleekxmpp it should be ['from'] self.callback_message(msg)
def incoming_message(self, xmppmsg): """Callback for message events""" if xmppmsg['type'] == "error": log.warning("Received error message: %s", xmppmsg) return msg = Message(xmppmsg['body']) if 'html' in xmppmsg.keys(): msg.html = xmppmsg['html'] msg.frm = self.build_identifier(xmppmsg['from'].full) msg.to = self.build_identifier(xmppmsg['to'].full) log.debug("incoming_message from: %s", msg.frm) if xmppmsg['type'] == 'groupchat': room = self.room_factory(msg.frm.node + '@' + msg.frm.domain, self) msg.frm = self.roomoccupant_factory(msg.frm.node, msg.frm.domain, msg.frm.resource, room) msg.to = room msg.nick = xmppmsg['mucnick'] msg.delayed = bool(xmppmsg['delay']._get_attr( 'stamp')) # this is a bug in sleekxmpp it should be ['from'] self.callback_message(msg)
def incoming_message(self, xmppmsg: dict) -> None: """Callback for message events""" if xmppmsg["type"] == "error": log.warning("Received error message: %s", xmppmsg) return msg = Message(xmppmsg["body"]) if "html" in xmppmsg.keys(): msg.html = xmppmsg["html"] log.debug("incoming_message from: %s", msg.frm) if xmppmsg["type"] == "groupchat": msg.frm = self._build_room_occupant(xmppmsg["from"].full) msg.to = msg.frm.room else: msg.frm = self._build_person(xmppmsg["from"].full) msg.to = self._build_person(xmppmsg["to"].full) msg.nick = xmppmsg["mucnick"] now = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") delay = xmppmsg["delay"]._get_attr( "stamp") # this is a bug in sleekxmpp it should be ['from'] msg.delayed = bool(delay and delay != now) self.callback_message(msg)
def on_pubmsg(self, _, e): msg = Message(e.arguments[0], type_='groupchat') msg.frm = Identifier(node=e.target) msg.to = self.callback.jid msg.nick = e.source.split('!')[0] # FIXME find the real nick in the channel self.callback.callback_message(msg)