sleekxmpp组件是如何工作的?

2024-06-06 04:06:41 发布

您现在位置:Python中文网/ 问答频道 /正文

这听起来可能很蠢,但我遵循了本教程:

https://github.com/fritzy/SleekXMPP/wiki/Creating-a-SleekXMPP-Plugin

下面是最后使用创建的XEP-0077插件的组件:

import sleekxmpp.componentxmpp

class Example(sleekxmpp.componentxmpp.ComponentXMPP):

    def __init__(self, jid, password):
        sleekxmpp.componentxmpp.ComponentXMPP.__init__(self, jid, password, 'localhost', 8888)

        self.registerPlugin('xep_0030')
        self.registerPlugin('xep_0077')
        self.plugin['xep_0077'].setForm('username', 'password')

        self.add_event_handler("registered_user", self.reg)
        self.add_event_handler("unregistered_user", self.unreg)

    def reg(self, iq):
        msg = "Welcome! %s" % iq['register']['username']
        self.sendMessage(iq['from'], msg, mfrom=self.fulljid)

    def unreg(self, iq):
        msg = "Bye! %s" % iq['register']['username']
        self.sendMessage(iq['from'], msg, mfrom=self.fulljid)

但我不知道如何使用它,也找不到任何sleekxmpp文档如何使用这个组件。我在这里试图实现的是能够从python在xmpp服务器上注册/注销用户。在


Tags: selfinitdefusername组件jidmsgpassword