XEP-0421: add has_feature helper

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2020-05-27 22:36:28 +02:00
parent cec34686fc
commit 07b1a4c1cd
2 changed files with 10 additions and 3 deletions

View File

@ -6,7 +6,7 @@
See the file LICENSE for copying permission. See the file LICENSE for copying permission.
""" """
from slixmpp import Message from slixmpp import JID, Message
from slixmpp.plugins import BasePlugin from slixmpp.plugins import BasePlugin
from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.plugins.xep_0421 import stanza from slixmpp.plugins.xep_0421 import stanza
@ -18,9 +18,13 @@ class XEP_0421(BasePlugin):
name = 'xep_0421' name = 'xep_0421'
description = 'Anonymous unique occupant identifiers for MUCs' description = 'Anonymous unique occupant identifiers for MUCs'
dependencies = {'xep_0045'} dependencies = {'xep_0030', 'xep_0045'}
stanza = stanza stanza = stanza
def plugin_init(self) -> None: def plugin_init(self) -> None:
# XXX: This should be MucMessage. Someday.. # XXX: This should be MucMessage. Someday..
register_stanza_plugin(Message, OccupantId) register_stanza_plugin(Message, OccupantId)
async def has_feature(self, jid: JID) -> bool:
info = await self.xmpp['xep_0030'].get_info(jid)
return self.stanza.NS in info.get_features()

View File

@ -9,6 +9,9 @@
from slixmpp.xmlstream import ElementBase from slixmpp.xmlstream import ElementBase
NS = 'urn:xmpp:occupant-id:0'
class OccupantId(ElementBase): class OccupantId(ElementBase):
''' '''
An Occupant-id tag. An Occupant-id tag.
@ -33,5 +36,5 @@ class OccupantId(ElementBase):
''' '''
name = 'occupant-id' name = 'occupant-id'
namespace = 'urn:xmpp:occupant-id:0' namespace = NS
interface = {'id'} interface = {'id'}