From 350f85a8d193698dc8b9795fec1af4862f6d85be Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 30 Nov 2020 21:24:20 +0100 Subject: XEP-0403: MIX-Presence --- slixmpp/plugins/__init__.py | 1 + slixmpp/plugins/xep_0403/__init__.py | 13 +++++++++ slixmpp/plugins/xep_0403/mix_presence.py | 47 ++++++++++++++++++++++++++++++++ slixmpp/plugins/xep_0403/stanza.py | 37 +++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 slixmpp/plugins/xep_0403/__init__.py create mode 100644 slixmpp/plugins/xep_0403/mix_presence.py create mode 100644 slixmpp/plugins/xep_0403/stanza.py (limited to 'slixmpp/plugins') diff --git a/slixmpp/plugins/__init__.py b/slixmpp/plugins/__init__.py index df1e3150..91f062a3 100644 --- a/slixmpp/plugins/__init__.py +++ b/slixmpp/plugins/__init__.py @@ -87,6 +87,7 @@ __all__ = [ 'xep_0332', # HTTP Over XMPP Transport 'xep_0369', # MIX-CORE 'xep_0377', # Spam reporting + 'xep_0403', # MIX-Presence 'xep_0404', # MIX-Anon 'xep_0405', # MIX-PAM 'xep_0421', # Anonymous unique occupant identifiers for MUCs diff --git a/slixmpp/plugins/xep_0403/__init__.py b/slixmpp/plugins/xep_0403/__init__.py new file mode 100644 index 00000000..0526276e --- /dev/null +++ b/slixmpp/plugins/xep_0403/__init__.py @@ -0,0 +1,13 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2020 Mathieu Pasquet + This file is part of Slixmpp. + + See the file LICENSE for copying permission. +""" + +from slixmpp.plugins.base import register_plugin +from slixmpp.plugins.xep_0403.stanza import * +from slixmpp.plugins.xep_0403.mix_presence import XEP_0403 + +register_plugin(XEP_0403) diff --git a/slixmpp/plugins/xep_0403/mix_presence.py b/slixmpp/plugins/xep_0403/mix_presence.py new file mode 100644 index 00000000..995439b9 --- /dev/null +++ b/slixmpp/plugins/xep_0403/mix_presence.py @@ -0,0 +1,47 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2020 Mathieu Pasquet + This file is part of Slixmpp. + + See the file LICENSE for copying permission. +""" +from typing import ( + Optional, + Set, +) + +from slixmpp import JID, Iq +from slixmpp.exceptions import IqError, IqTimeout +from slixmpp.plugins import BasePlugin +from slixmpp.plugins.xep_0403 import stanza +from slixmpp.xmlstream.matcher import MatchXPath +from slixmpp.xmlstream.handler import Callback + + +NODES = [ + 'urn:xmpp:mix:nodes:presence' +] + + +class XEP_0403(BasePlugin): + '''XEP-0403: MIX-Presence''' + + name = 'xep_0403' + description = 'MIX-Presence' + dependencies = {'xep_0369'} + stanza = stanza + namespace = stanza.NS + + def plugin_init(self) -> None: + stanza.register_plugins() + + self.xmpp.register_handler( + Callback( + 'MIX Presence received', + MatchXPath('{%s}presence/{%s}mix' % (self.xmpp.default_ns, stanza.NS)), + self._handle_mix_presence, + ) + ) + + def _handle_mix_presence(self, presence): + self.xmpp.event('mix_presence', presence) diff --git a/slixmpp/plugins/xep_0403/stanza.py b/slixmpp/plugins/xep_0403/stanza.py new file mode 100644 index 00000000..3e5b9cde --- /dev/null +++ b/slixmpp/plugins/xep_0403/stanza.py @@ -0,0 +1,37 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2020 Mathieu Pasquet + This file is part of Slixmpp. + + See the file LICENSE for copying permissio +""" + +from xml.etree import ElementTree as ET +from slixmpp import JID +from slixmpp.stanza import Presence +from slixmpp.xmlstream import ( + register_stanza_plugin, + ElementBase, +) + +from slixmpp.plugins.xep_0060.stanza import ( + Item, + EventItem, +) + + +NS = 'urn:xmpp:mix:presence:0' + + +class MIXPresence(ElementBase): + namespace = NS + name = 'mix' + plugin_attrib = 'mix' + interfaces = {'jid', 'nick'} + sub_interfaces = {'jid', 'nick'} + + +def register_plugins(): + register_stanza_plugin(Presence, MIXPresence) + register_stanza_plugin(Item, Presence) + register_stanza_plugin(EventItem, Presence) -- cgit v1.2.3