Update plugin: XEP-0317 (hats)
Merge changes from nicoco's MR that I missed, improving tests and interface.
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
from slixmpp.plugins import BasePlugin
|
||||
from slixmpp import Presence
|
||||
from slixmpp.xmlstream import register_stanza_plugin
|
||||
from . import stanza
|
||||
|
||||
|
||||
@@ -8,13 +6,11 @@ class XEP_0317(BasePlugin):
|
||||
"""
|
||||
XEP-0317: Hats
|
||||
"""
|
||||
|
||||
name = 'xep_0317'
|
||||
description = 'XEP-0317: Hats'
|
||||
dependencies = {'xep_0030', 'xep_0050'}
|
||||
dependencies = {'xep_0030', 'xep_0045', 'xep_0050'}
|
||||
stanza = stanza
|
||||
namespace = stanza.NS
|
||||
|
||||
def plugin_init(self):
|
||||
register_stanza_plugin(stanza.Hat, stanza.Hats)
|
||||
register_stanza_plugin(stanza.Hats, Presence)
|
||||
stanza.register_plugin()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from slixmpp.xmlstream import ElementBase
|
||||
from slixmpp import Presence
|
||||
from slixmpp.xmlstream import ElementBase, register_stanza_plugin
|
||||
|
||||
NS = 'urn:xmpp:hats:0'
|
||||
|
||||
@@ -25,6 +26,13 @@ class Hats(ElementBase):
|
||||
namespace = NS
|
||||
plugin_attrib = 'hats'
|
||||
|
||||
def add_hats(self, data: list[tuple[str, str]]) -> None:
|
||||
for uri, title in data:
|
||||
hat = Hat()
|
||||
hat["uri"] = uri
|
||||
hat["title"] = title
|
||||
self.append(hat)
|
||||
|
||||
|
||||
class Hat(ElementBase):
|
||||
"""
|
||||
@@ -38,6 +46,12 @@ class Hat(ElementBase):
|
||||
|
||||
"""
|
||||
name = 'hat'
|
||||
namespace = NS
|
||||
plugin_attrib = 'hat'
|
||||
namespace = NS
|
||||
interfaces = {'title', 'uri'}
|
||||
plugin_multi_attrib = "hats"
|
||||
|
||||
|
||||
def register_plugin() -> None:
|
||||
register_stanza_plugin(Hats, Hat, iterable=True)
|
||||
register_stanza_plugin(Presence, Hats)
|
||||
|
||||
Reference in New Issue
Block a user