Esempio n. 1
0
    def receiveMessage(self, user, multiparts, flags):
        #print user.name, multiparts, flags

        username = singleton.format_name('AIM', user.name)
        message  = multiparts[0][0]

        # Sanitize the user's message.
        message = re.sub(r'<(.|\n)+?>', '', message)
        message = re.sub(r'\t+', '', message)
        message = message.strip()

        #print "%s> %s" % (user.name, message)
        reply = singleton.get_reply(self.agent, username, message)

        # Format it with the bot's font settings.
        settings = singleton.get_listener(self.agent)
        formatted = settings['font'][0] + reply + settings['font'][1]

        # Queue the reply.
        output = [(formatted.encode('utf8'),)]
#        self.sendMessage(user.name, output, wantAck = 1).addCallback(self.messageAck)
        singleton.add_queue(
            agent   = self.agent,
            func    = self._sendMessage,
            args    = (user.name, output),
            recover = 3
        )
Esempio n. 2
0
    def receiveMessage(self, user, multiparts, flags):
        #print user.name, multiparts, flags

        username = singleton.format_name('AIM', user.name)
        message = multiparts[0][0]

        # Sanitize the user's message.
        message = re.sub(r'<(.|\n)+?>', '', message)
        message = re.sub(r'\t+', '', message)
        message = message.strip()

        #print "%s> %s" % (user.name, message)
        reply = singleton.get_reply(self.agent, username, message)

        # Format it with the bot's font settings.
        settings = singleton.get_listener(self.agent)
        formatted = settings['font'][0] + reply + settings['font'][1]

        # Queue the reply.
        output = [(formatted.encode('utf8'), )]
        #        self.sendMessage(user.name, output, wantAck = 1).addCallback(self.messageAck)
        singleton.add_queue(agent=self.agent,
                            func=self._sendMessage,
                            args=(user.name, output),
                            recover=3)
Esempio n. 3
0
    def on_presence(self, el):
        #print "Received presence!"

        # The sender.
        source = str(el['from'])
        username = singleton.format_name('XMPP', source.split("/")[0])

        # What type of presence message is this?
        if el['type'] == 'subscribe':
            # Somebody added us to their buddy list. Allow this.
            print "Allowing subscription by {}".format(source)
            self.allow_subscribe(source)
        elif el['type'] == 'unsubscribe':
            # They removed us from their list. Revoke the subscription.
            print "{} deleted us, removing subscription.".format(source)
            self.deny_subscribe(source)
Esempio n. 4
0
    def on_presence(self, el):
        #print "Received presence!"

        # The sender.
        source   = str(el['from'])
        username = singleton.format_name('XMPP', source.split("/")[0])

        # What type of presence message is this?
        if el['type'] == 'subscribe':
            # Somebody added us to their buddy list. Allow this.
            print "Allowing subscription by {}".format(source)
            self.allow_subscribe(source)
        elif el['type'] == 'unsubscribe':
            # They removed us from their list. Revoke the subscription.
            print "{} deleted us, removing subscription.".format(source)
            self.deny_subscribe(source)
Esempio n. 5
0
    def on_message(self, el):
        #print "Received message!"

        # The sender.
        source = str(el['from'])
        username = singleton.format_name('XMPP', source.split("/")[0])

        # Get the chat body.
        body = None
        for e in el.elements():
            if e.name == 'body':
                if el['type'] == 'chat':
                    body = str(e)

        #print "body:", body
        if body is None:
            return

        reply = singleton.get_reply(self._id, username, body)
        self.send_message(source, reply)
Esempio n. 6
0
    def on_message(self, el):
        #print "Received message!"

        # The sender.
        source   = str(el['from'])
        username = singleton.format_name('XMPP', source.split("/")[0])

        # Get the chat body.
        body = None
        for e in el.elements():
            if e.name == 'body':
                if el['type'] == 'chat':
                    body = str(e)

        #print "body:", body
        if body is None:
            return

        reply = singleton.get_reply(self._id, username, body)
        self.send_message(source, reply)
Esempio n. 7
0
 def gotSelfInfo(self, user):
     #print user.__dict__
     self.agent = singleton.format_name('AIM', user.name)
     self.name = user.name
Esempio n. 8
0
 def gotSelfInfo(self, user):
     #print user.__dict__
     self.agent = singleton.format_name('AIM', user.name)
     self.name = user.name