Example #1
0
 def plugin_init(self):
     self.rooms = {}
     self.ourNicks = {}
     self.xep = '0045'
     # load MUC support in presence stanzas
     register_stanza_plugin(Presence, MUCPresence)
     self.xmpp.registerHandler(
         Callback(
             'MUCPresence',
             MatchXMLMask("<presence xmlns='%s' />" % self.xmpp.default_ns),
             self.handle_groupchat_presence))
     self.xmpp.registerHandler(
         Callback(
             'MUCMessage',
             MatchXMLMask(
                 "<message xmlns='%s' type='groupchat'><body/></message>" %
                 self.xmpp.default_ns), self.handle_groupchat_message))
     self.xmpp.registerHandler(
         Callback(
             'MUCSubject',
             MatchXMLMask(
                 "<message xmlns='%s' type='groupchat'><subject/></message>"
                 % self.xmpp.default_ns), self.handle_groupchat_subject))
     self.xmpp.registerHandler(
         Callback(
             'MUCInvite',
             MatchXPath(
                 "{%s}message/{http://jabber.org/protocol/muc#user}x/invite"
                 % self.xmpp.default_ns), self.handle_groupchat_invite))
Example #2
0
    def __init__(self, jid, secret, server, port):
        ComponentXMPP.__init__(self, jid, secret, server, port)
        self.backend = SimpleBackend()
        # You don't need a session_start handler, but that is
        # where you would broadcast initial presence.

        # The message event is triggered whenever a message
        # stanza is received. Be aware that that includes
        # MUC messages and error messages.

        self.add_event_handler("session_start", self.start)
        # self.add_event_handler("message", self.message)
        self.add_event_handler("changed_subscription",
                               self.handleXMPPPresenceSubscription)
        self.add_event_handler("got_presence_probe",
                               self.handleXMPPPresenceProbe)
        for event in [
                "message", "got_online", "got_offline", "changed_status"
        ]:
            self.add_event_handler(event, self.handleIncomingXMPPEvent)
        #
        self.backend.addMessageHandler(self.handleMessageAddedToBackend)

        xpath = "{%s}iq/{cnry:sleep:1}sleep" % self.default_ns

        self.registerHandler(
            Callback('Sleep command handler', MatchXPath(xpath),
                     self.handle_sleep))
Example #3
0
    def __init__(self, jid, password, callback, basename=None, ssl=False):

        self.plugin_config = {}

        self.jid = jid
        self.password = password
        self.callback = callback

        if basename is None:
            self.basename = self.jid
        else:
            self.basename = basename

        self._priority = 100
        self.botActive = False

        sleekxmpp.ClientXMPP.__init__(self, self.jid, self.password, ssl,
                                      self.plugin_config, {})

        self.registerPlugin('xep_0092', {
            'name': 'XMPP Daemon',
            'version': __version__
        })
        self.registerPlugin('xep_0004')
        self.registerPlugin('xep_0030')
        self.registerPlugin('xep_0060', {})
        self.registerPlugin('xep_0045', {})

        self.site_values = []
        self.auto_authorize = True
        self.auto_subscribe = True

        self.pubsub = self.plugin['xep_0060']
        self.muc = self.plugin['xep_0045']

        # [(room, nick, password)]
        self.roomlist = []

        self.lasterror = ''

        self.add_event_handler("session_start", self.on_start, threaded=True)
        self.add_event_handler("message", self.on_message, threaded=True)
        self.add_event_handler("groupchat_message", self.on_muc, threaded=True)

        self.add_handler("<iq type='error' />", self.handleError)

        self.registerHandler(
            Callback(
                "payload",
                MatchXPath(
                    "{jabber:client}message/{http://jabber.org/protocol/pubsub#event}event"
                ),
                self.on_payload,
                thread=True))

        self.rootnode = 'pubsub.%s' % self.getjidbare(jid).split('@')[1]
Example #4
0
    def plugin_init(self):
        self.xep = 'docker'

        self.xmpp.registerHandler(
            Callback(
                'Docker',
                MatchXPath('{%s}iq/{jabber:iq:docker}query' %
                           self.xmpp.default_ns), self._handle_name_of_pods))

        register_stanza_plugin(Iq, Docker)
Example #5
0
 def plugin_init(self):
     self.description = "upload files via http"
     self.xep = "0999"
     self.xmpp['xep_0030'].add_feature("eu:siacs:conversations:http:upload")
     self.xmpp.register_handler(
         Callback(
             'Upload request',
             MatchXPath(
                 '{%s}iq/{eu:siacs:conversations:http:upload}request' %
                 self.xmpp.default_ns), self._handleUpload))
     register_stanza_plugin(Iq, UploadRequest)
     register_stanza_plugin(Iq, UploadSlot)
Example #6
0
 def plugin_init(self):
     self.description = "upload files via http"
     self.xep = "0999"
     self.xmpp['xep_0030'].add_feature("urn:xmpp:http:upload")
     self.xmpp['xep_0030'].add_identity(category='store',
                                        itype='file',
                                        name='HTTP File Upload')
     self.xmpp.register_handler(
         Callback(
             'Upload request',
             MatchXPath('{%s}iq/{urn:xmpp:http:upload}request' %
                        self.xmpp.default_ns), self._handleUpload))
     register_stanza_plugin(Iq, UploadRequest)
     register_stanza_plugin(Iq, UploadSlot)
Example #7
0
    def plugin_init(self):
        self.xep = '0009'
        self.description = 'Jabber-RPC'
        #self.stanza = sleekxmpp.plugins.xep_0009.stanza

        register_stanza_plugin(Iq, RPCQuery)
        register_stanza_plugin(RPCQuery, MethodCall)
        register_stanza_plugin(RPCQuery, MethodResponse)

        self.xmpp.registerHandler(
            Callback(
                'RPC Call',
                MatchXPath('{%s}iq/{%s}query/{%s}methodCall' %
                           (self.xmpp.default_ns, RPCQuery.namespace,
                            RPCQuery.namespace)), self._handle_method_call))
        self.xmpp.registerHandler(
            Callback(
                'RPC Call',
                MatchXPath('{%s}iq/{%s}query/{%s}methodResponse' %
                           (self.xmpp.default_ns, RPCQuery.namespace,
                            RPCQuery.namespace)),
                self._handle_method_response))
        self.xmpp.registerHandler(
            Callback(
                'RPC Call',
                MatchXPath('{%s}iq/{%s}error' %
                           (self.xmpp.default_ns, self.xmpp.default_ns)),
                self._handle_error))
        self.xmpp.add_event_handler('jabber_rpc_method_call',
                                    self._on_jabber_rpc_method_call)
        self.xmpp.add_event_handler('jabber_rpc_method_response',
                                    self._on_jabber_rpc_method_response)
        self.xmpp.add_event_handler('jabber_rpc_method_fault',
                                    self._on_jabber_rpc_method_fault)
        self.xmpp.add_event_handler('jabber_rpc_error',
                                    self._on_jabber_rpc_error)
        self.xmpp.add_event_handler('error', self._handle_error)
Example #8
0
    def _start(self, _):
        self._xmpp.get_roster()
        self._xmpp.send_presence()

        try:
            xmpp = self._xmpp.plugin['xep_0045'].xmpp
            xmpp.registerHandler(
                Callback(
                    'MUCError',
                    MatchXPath("{%s}presence[@type='error']" %
                               xmpp.default_ns), self._error))
        except Exception as exception:
            print(exception)
            traceback.print_exc()
            raise

        self.join_mucs()
Example #9
0
    def plugin_init(self):
        self.xep = "0012"

        self.xmpp.registerHandler(
            Callback(
                'Last Activity',
                MatchXPath('{%s}iq/{%s}query' %
                           (self.xmpp.default_ns, LastActivity.namespace)),
                self.handle_last_activity_query))
        register_stanza_plugin(Iq, LastActivity)

        self.xmpp.add_event_handler('last_activity_request',
                                    self.handle_last_activity)

        if self.xmpp.is_component:
            # We are a component, so we track the uptime
            self.xmpp.add_event_handler("session_start", self._reset_uptime)
            self._start_datetime = datetime.now()
        self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:last')
Example #10
0
    def __init__(self):
        # Create client with FCM server login info
        super(Client, self).__init__(FCM_JID,
                                     FCM_SERVER_KEY,
                                     sasl_mech='PLAIN')

        # Create pending command queue
        self.cmd_q = []

        # Create handler for received messages
        self.registerHandler(
            Callback(
                'FCM Message Receive',
                MatchXPath('{%s}message/{%s}gcm' %
                           (self.default_ns, 'google:mobile:data')),
                self.recv_message))

        # Connect to server and begin processing XML stream
        self.auto_reconnect = False
        self.connect((_get_fcm_server_ip(), FCM_SERVER_PORT),
                     use_tls=True,
                     use_ssl=True,
                     reattempt=False)
        self.process(threaded=True)