コード例 #1
0
    def on_invite(self, element):
        """
        Handler that responds to channel invites from other users. This will acknowledge
        the request by joining the room indicated in the xml payload.

        :param element: A <message/> element, instance of `twisted.words.xish.domish.Element`
        """
        channel = ''
        password = ''

        # NOTE: check for either http://xmpp.org/extensions/xep-0045.html#invite
        # or direct invites http://xmpp.org/extensions/xep-0249.html
        if xpath.matches('/message/x/invite', element):
            from_jid = jid.JID(element['from'])
            to_jid = jid.JID(element['to'])

            if from_jid.host == self.conference_host:
                channel = from_jid.userhost()
            else:
                channel = to_jid.userhost()

            # This is a hack around a unicode bug in twisted queryForString
            strings = xpath.queryForStringList('/message/x/password', element)
            if strings:
                password = strings[0]
        elif xpath.matches('/message/x[@xmlns="jabber:x:conference"]', element):
            # Direct invite
            x = xpath.queryForNodes('/message/x', element)[0]
            channel = x['jid']
            password = x.attributes.get('password', '')
        else:
            # Probably not an invite, but the overly greedy xpath matched it. Ignore.
            return

        self.join(channel, password=password)
コード例 #2
0
 def testStaticMethods(self):
     self.assertEquals(xpath.matches("/foo/bar", self.e), True)
     self.assertEquals(xpath.queryForNodes("/foo/bar", self.e),
                       [self.bar1, self.bar2, self.bar4])
     self.assertEquals(xpath.queryForString("/foo", self.e), "somecontent")
     self.assertEquals(xpath.queryForStringList("/foo", self.e),
                       ["somecontent", "somemorecontent"])
コード例 #3
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
    def test_oneToOneChat(self):
        """Converting a one to one chat to a multi-user chat.
        """
        archive = []
        thread = "e0ffe42b28561960c6b12b944a092794b9683a38"
        # create messages
        msg = domish.Element((None, 'message'))
        msg['to'] = '*****@*****.**'
        msg['type'] = 'chat'
        msg.addElement('body', None, 'test')
        msg.addElement('thread', None, thread)

        archive.append(msg)

        msg = domish.Element((None, 'message'))
        msg['to'] = '*****@*****.**'
        msg['type'] = 'chat'
        msg.addElement('body', None, 'yo')
        msg.addElement('thread', None, thread)

        archive.append(msg)

        self.protocol.history(self.room_jid, archive)


        while len(self.stub.output)>0:
            m = self.stub.output.pop()
            # check for delay element
            self.failUnless(m.name=='message', 'Wrong stanza')
            self.failUnless(xpath.matches("/message/delay", m), 'Invalid history stanza')
コード例 #4
0
    def test_kick(self):
        """Kick an entity from a room.
        """
        kicked = JID('[email protected]/TroubleMakger')

        def cb(kicked):
            self.failUnless(kicked, 'Did not kick user')

        d = self.protocol.kick(self.room_jid,
                               kicked,
                               self.user_jid,
                               reason='Spam')
        d.addCallback(cb)

        iq = self.stub.output[-1]

        self.failUnless(
            xpath.matches(
                "/iq[@type='set' and @to='%s']/query/item[@affiliation='none']"
                % (self.room_jid.userhost(), ), iq), 'Wrong kick stanza')

        response = toResponse(iq, 'result')

        self.stub.send(response)

        return d
コード例 #5
0
    def test_oneToOneChat(self):
        """Converting a one to one chat to a multi-user chat.
        """
        archive = []
        thread = "e0ffe42b28561960c6b12b944a092794b9683a38"
        # create messages
        msg = domish.Element((None, 'message'))
        msg['to'] = '*****@*****.**'
        msg['type'] = 'chat'
        msg.addElement('body', None, 'test')
        msg.addElement('thread', None, thread)

        archive.append(msg)

        msg = domish.Element((None, 'message'))
        msg['to'] = '*****@*****.**'
        msg['type'] = 'chat'
        msg.addElement('body', None, 'yo')
        msg.addElement('thread', None, thread)

        archive.append(msg)

        self.protocol.history(self.room_jid, archive)

        while len(self.stub.output) > 0:
            m = self.stub.output.pop()
            # check for delay element
            self.failUnless(m.name == 'message', 'Wrong stanza')
            self.failUnless(xpath.matches("/message/delay", m),
                            'Invalid history stanza')
コード例 #6
0
    def test_ban(self):
        """Ban an entity in a room.
        """
        banned = JID('[email protected]/TroubleMakger')

        def cb(banned):
            self.failUnless(banned, 'Did not ban user')

        d = self.protocol.ban(self.room_jid,
                              banned,
                              self.user_jid,
                              reason='Spam')
        d.addCallback(cb)

        iq = self.stub.output[-1]

        self.failUnless(
            xpath.matches(
                "/iq[@type='set' and @to='%s']/query/item[@affiliation='outcast']"
                % (self.room_jid.userhost(), ), iq), 'Wrong ban stanza')

        response = toResponse(iq, 'result')

        self.stub.send(response)

        return d
コード例 #7
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
    def test_voice(self):
        """ Client requesting voice for a room.
        """
        self.protocol.voice(self.room_jid.userhost())

        m = self.stub.output[-1]
        
        self.failUnless(xpath.matches("/message/x[@type='submit']/field/value[text()='%s']" % (muc.NS_MUC_REQUEST,), m), 'Invalid voice message stanza')
コード例 #8
0
 def testStaticMethods(self):
     self.assertEquals(xpath.matches("/foo/bar", self.e),
                       True)
     self.assertEquals(xpath.queryForNodes("/foo/bar", self.e),
                       [self.bar1, self.bar2, self.bar4])
     self.assertEquals(xpath.queryForString("/foo", self.e),
                       "somecontent")
     self.assertEquals(xpath.queryForStringList("/foo", self.e),
                       ["somecontent", "somemorecontent"])
コード例 #9
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
 def test_password(self):
     """Sending a password via presence to a password protected room.
     """
     
     self.protocol.password(self.room_jid, 'secret')
     
     prs = self.stub.output[-1]
     
     self.failUnless(xpath.matches("/presence[@to='%s']/x/password[text()='secret']" % (self.room_jid.full(),), prs), 'Wrong presence stanza')
コード例 #10
0
 def test_staticMethods(self):
     """
     Test basic operation of the static methods.
     """
     self.assertEquals(xpath.matches("/foo/bar", self.e), True)
     self.assertEquals(
         xpath.queryForNodes("/foo/bar", self.e), [self.bar1, self.bar2, self.bar4, self.bar5, self.bar6, self.bar7]
     )
     self.assertEquals(xpath.queryForString("/foo", self.e), "somecontent")
     self.assertEquals(xpath.queryForStringList("/foo", self.e), ["somecontent", "somemorecontent"])
コード例 #11
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
    def test_invite(self):
        """Invite a user to a room
        """
        other_jid = '*****@*****.**'

        self.protocol.invite(other_jid, 'This is a test')

        msg = self.stub.output[-1]

        self.failUnless(xpath.matches("/message[@to='%s']/x/invite/reason" % (other_jid,), msg), 'Wrong message type')
コード例 #12
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
    def test_privateMessage(self):
        """Send private messages to muc entities.
        """
        other_nick = self.room_jid.userhost()+'/OtherNick'

        self.protocol.chat(other_nick, 'This is a test')

        msg = self.stub.output[-1]

        self.failUnless(xpath.matches("/message[@type='chat' and @to='%s']/body" % (other_nick,), msg), 'Wrong message type')
コード例 #13
0
    def test_voice(self):
        """ Client requesting voice for a room.
        """
        self.protocol.voice(self.room_jid.userhost())

        m = self.stub.output[-1]

        self.failUnless(
            xpath.matches(
                "/message/x[@type='submit']/field/value[text()='%s']" %
                (muc.NS_MUC_REQUEST, ), m), 'Invalid voice message stanza')
コード例 #14
0
 def test_staticMethods(self):
     """
     Test basic operation of the static methods.
     """
     self.assertEqual(xpath.matches("/foo/bar", self.e), True)
     self.assertEqual(
         xpath.queryForNodes("/foo/bar", self.e),
         [self.bar1, self.bar2, self.bar4, self.bar5, self.bar6, self.bar7])
     self.assertEqual(xpath.queryForString("/foo", self.e), "somecontent")
     self.assertEqual(xpath.queryForStringList("/foo", self.e),
                      ["somecontent", "somemorecontent"])
コード例 #15
0
    def test_invite(self):
        """Invite a user to a room
        """
        other_jid = '*****@*****.**'

        self.protocol.invite(other_jid, 'This is a test')

        msg = self.stub.output[-1]

        self.failUnless(
            xpath.matches("/message[@to='%s']/x/invite/reason" % (other_jid, ),
                          msg), 'Wrong message type')
コード例 #16
0
    def test_password(self):
        """Sending a password via presence to a password protected room.
        """

        self.protocol.password(self.room_jid, 'secret')

        prs = self.stub.output[-1]

        self.failUnless(
            xpath.matches(
                "/presence[@to='%s']/x/password[text()='secret']" %
                (self.room_jid.full(), ), prs), 'Wrong presence stanza')
コード例 #17
0
    def test_privateMessage(self):
        """Send private messages to muc entities.
        """
        other_nick = self.room_jid.userhost() + '/OtherNick'

        self.protocol.chat(other_nick, 'This is a test')

        msg = self.stub.output[-1]

        self.failUnless(
            xpath.matches(
                "/message[@type='chat' and @to='%s']/body" % (other_nick, ),
                msg), 'Wrong message type')
コード例 #18
0
ファイル: xmpp.py プロジェクト: manueldelreal/helga
    def parse_message(self, message):
        """
        Parses the message body from a <message/> element, ignoring any delayed messages.
        If a message is indeed a delayed message, an empty string is returned

        :param message: A <message/> element, instance of `twisted.words.xish.domish.Element`
        :returns: The contents of the message, empty string if the message is delayed
        """
        if xpath.matches('/message/delay', message):
            return u''

        # This is a hack around a unicode bug in twisted queryForString
        strings = xpath.queryForStringList('/message/body', message)
        if strings:
            return strings[0]
        return u''
コード例 #19
0
ファイル: xmpp.py プロジェクト: bigjust/helga
    def parse_message(self, message):
        """
        Parses the message body from a <message/> element, ignoring any delayed messages.
        If a message is indeed a delayed message, an empty string is returned

        :param message: A <message/> element, instance of `twisted.words.xish.domish.Element`
        :returns: The contents of the message, empty string if the message is delayed
        """
        if xpath.matches('/message/delay', message):
            return u''

        # This is a hack around a unicode bug in twisted queryForString
        strings = xpath.queryForStringList('/message/body', message)
        if strings:
            return strings[0]
        return u''
コード例 #20
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
    def test_roomDestroy(self):
        """ Destroy a room.
        """

        def cb(destroyed):
            self.failUnless(destroyed==True, 'Room not destroyed.')
                   
        d = self.protocol.destroy(self.room_jid)
        d.addCallback(cb)

        iq = self.stub.output[-1]
        self.failUnless(xpath.matches("/iq/query[@xmlns='%s']/destroy"% (muc.NS_MUC_OWNER,), iq), 'Bad configure request')
        
        response = toResponse(iq, 'result')
        self.stub.send(response)
        return d
コード例 #21
0
    def test_roomDestroy(self):
        """ Destroy a room.
        """
        def cb(destroyed):
            self.failUnless(destroyed == True, 'Room not destroyed.')

        d = self.protocol.destroy(self.room_jid)
        d.addCallback(cb)

        iq = self.stub.output[-1]
        self.failUnless(
            xpath.matches(
                "/iq/query[@xmlns='%s']/destroy" % (muc.NS_MUC_OWNER, ), iq),
            'Bad configure request')

        response = toResponse(iq, 'result')
        self.stub.send(response)
        return d
コード例 #22
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
    def test_register(self):
        """Client registering with a room. http://xmpp.org/extensions/xep-0045.html#register

        """
        
        def cb(iq):
            # check for a result
            self.failUnless(iq['type']=='result', 'We did not get a result')
        
        d = self.protocol.register(self.room_jid)
        d.addCallback(cb)

        iq = self.stub.output[-1]
        self.failUnless(xpath.matches("/iq/query[@xmlns='%s']" % (muc.NS_REQUEST), iq), 'Invalid iq register request')
        
        response = toResponse(iq, 'result')
        
        self.stub.send(response)
        return d
コード例 #23
0
    def test_register(self):
        """Client registering with a room. http://xmpp.org/extensions/xep-0045.html#register

        """
        def cb(iq):
            # check for a result
            self.failUnless(iq['type'] == 'result', 'We did not get a result')

        d = self.protocol.register(self.room_jid)
        d.addCallback(cb)

        iq = self.stub.output[-1]
        self.failUnless(
            xpath.matches("/iq/query[@xmlns='%s']" % (muc.NS_REQUEST), iq),
            'Invalid iq register request')

        response = toResponse(iq, 'result')

        self.stub.send(response)
        return d
コード例 #24
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
    def test_kick(self):
        """Kick an entity from a room.
        """
        kicked = JID('[email protected]/TroubleMakger')
        def cb(kicked):
            self.failUnless(kicked, 'Did not kick user')

            
        d = self.protocol.kick(self.room_jid, kicked, self.user_jid, reason='Spam')
        d.addCallback(cb)

        iq = self.stub.output[-1]
        
        self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@affiliation='none']" % (self.room_jid.userhost(),), iq), 'Wrong kick stanza')

        response = toResponse(iq, 'result')

        self.stub.send(response)

        return d
コード例 #25
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
    def test_ban(self):
        """Ban an entity in a room.
        """
        banned = JID('[email protected]/TroubleMakger')
        def cb(banned):
            self.failUnless(banned, 'Did not ban user')

            
        d = self.protocol.ban(self.room_jid, banned, self.user_jid, reason='Spam')
        d.addCallback(cb)

        iq = self.stub.output[-1]
        
        self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@affiliation='outcast']" % (self.room_jid.userhost(),), iq), 'Wrong ban stanza')

        response = toResponse(iq, 'result')

        self.stub.send(response)

        return d
コード例 #26
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
    def test_grantVoice(self):
        """Test granting voice to a user.

        """
        give_voice = JID('[email protected]/TroubleMakger')
        def cb(give_voice):
            self.failUnless(give_voice, 'Did not give voice user')

            
        d = self.protocol.grantVoice(self.user_jid, self.room_jid, give_voice)
        d.addCallback(cb)

        iq = self.stub.output[-1]
        
        self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@role='participant']" % (self.room_jid.userhost(),), iq), 'Wrong voice stanza')

        response = toResponse(iq, 'result')

        self.stub.send(response)

        return d
コード例 #27
0
ファイル: stenotype.py プロジェクト: mick/stenotype
    def onMessage(self, msg):
        """
        Called when a message stanza was received.
        """

        if xpath.matches("/message/x[@xmlns='jabber:x:delay']", msg) == 1:
            print "skip"
            return
        print "process"
#        if msg.x and msg.x.uri == "jabber:x:delay":
#            print "DELAYED "+str(msg.x) + msg.x.ur
#        if msg.x and msg.x.hasAttribute("xmlns") and msg.x['xmlns'] == "jabber:x:delay":
#            return

        if msg["type"] == 'groupchat' and hasattr(msg, "body"):
            print (msg.body)
            content = str(msg.body)
            if(content[:5].lower() == "call "):
                number = content[5:]
                print "GOT A NUMBER!! "+ number
#                if number  != self.number:
#                    self.number = number
                data = {
                    'Caller' : CALLER_ID,
                    'Called' : number,
                    'Url' : 'http://dmt.im/twilio/twilio.xml',
                    #            'SendDigits' : '965376#1'
                    }

                account = txilio.Account(ACCOUNT_SID, AUTH_TOKEN)
                d = account.request('Calls', 'POST', data)
                self.notify("CALLING "+number)
                def _done(res):
                    print str(res)
                    request.write(str(res))
                    request.finish()

                d.addBoth(_done)
                return NOT_DONE_YET
コード例 #28
0
ファイル: test_muc.py プロジェクト: Urthen/Legacy-FritBot
    def test_roomConfigure(self):
        """ Default configure and changing the room name.
        """

        def cb(iq):
            self.failUnless(iq['type']=='result', 'Not a result')
            

        fields = []

        fields.append(data_form.Field(label='Natural-Language Room Name',
                                      var='muc#roomconfig_roomname',
                                      value=self.test_room))
        
        d = self.protocol.configure(self.room_jid.userhost(), fields)
        d.addCallback(cb)

        iq = self.stub.output[-1]
        self.failUnless(xpath.matches("/iq/query[@xmlns='%s']/x"% (muc.NS_MUC_OWNER,), iq), 'Bad configure request')
        
        response = toResponse(iq, 'result')
        self.stub.send(response)
        return d
コード例 #29
0
    def test_roomConfigure(self):
        """ Default configure and changing the room name.
        """
        def cb(iq):
            self.failUnless(iq['type'] == 'result', 'Not a result')

        fields = []

        fields.append(
            data_form.Field(label='Natural-Language Room Name',
                            var='muc#roomconfig_roomname',
                            value=self.test_room))

        d = self.protocol.configure(self.room_jid.userhost(), fields)
        d.addCallback(cb)

        iq = self.stub.output[-1]
        self.failUnless(
            xpath.matches("/iq/query[@xmlns='%s']/x" % (muc.NS_MUC_OWNER, ),
                          iq), 'Bad configure request')

        response = toResponse(iq, 'result')
        self.stub.send(response)
        return d
コード例 #30
0
    def test_grantVoice(self):
        """Test granting voice to a user.

        """
        give_voice = JID('[email protected]/TroubleMakger')

        def cb(give_voice):
            self.failUnless(give_voice, 'Did not give voice user')

        d = self.protocol.grantVoice(self.user_jid, self.room_jid, give_voice)
        d.addCallback(cb)

        iq = self.stub.output[-1]

        self.failUnless(
            xpath.matches(
                "/iq[@type='set' and @to='%s']/query/item[@role='participant']"
                % (self.room_jid.userhost(), ), iq), 'Wrong voice stanza')

        response = toResponse(iq, 'result')

        self.stub.send(response)

        return d