From 81ebf4e8ba7d273cfd51df9c64fc5153cc687989 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 22 Jan 2021 18:40:37 +0100 Subject: [PATCH] XEP-0382: Spoiler Messages --- slixmpp/plugins/__init__.py | 1 + slixmpp/plugins/xep_0382/__init__.py | 13 +++++++++++ slixmpp/plugins/xep_0382/spoiler.py | 32 ++++++++++++++++++++++++++++ slixmpp/plugins/xep_0382/stanza.py | 26 ++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 slixmpp/plugins/xep_0382/__init__.py create mode 100644 slixmpp/plugins/xep_0382/spoiler.py create mode 100644 slixmpp/plugins/xep_0382/stanza.py diff --git a/slixmpp/plugins/__init__.py b/slixmpp/plugins/__init__.py index a0159ad1..e833d808 100644 --- a/slixmpp/plugins/__init__.py +++ b/slixmpp/plugins/__init__.py @@ -100,6 +100,7 @@ __all__ = [ 'xep_0369', # MIX-CORE 'xep_0377', # Spam reporting 'xep_0380', # Explicit Message Encryption + 'xep_0382', # Spoiler Messages 'xep_0394', # Message Markup 'xep_0403', # MIX-Presence 'xep_0404', # MIX-Anon diff --git a/slixmpp/plugins/xep_0382/__init__.py b/slixmpp/plugins/xep_0382/__init__.py new file mode 100644 index 00000000..4a6b83fc --- /dev/null +++ b/slixmpp/plugins/xep_0382/__init__.py @@ -0,0 +1,13 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2021 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_0382.stanza import * +from slixmpp.plugins.xep_0382.spoiler import XEP_0382 + +register_plugin(XEP_0382) diff --git a/slixmpp/plugins/xep_0382/spoiler.py b/slixmpp/plugins/xep_0382/spoiler.py new file mode 100644 index 00000000..2f556f77 --- /dev/null +++ b/slixmpp/plugins/xep_0382/spoiler.py @@ -0,0 +1,32 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2021 Mathieu Pasquet + This file is part of Slixmpp. + + See the file LICENSE for copying permission. +""" +from slixmpp import JID +from slixmpp.plugins import BasePlugin +from slixmpp.plugins.xep_0382 import stanza +from slixmpp.stanza import Message + + +class XEP_0382(BasePlugin): + '''XEP-0382: Spoiler Messages''' + + name = 'xep_0382' + description = 'Spoiler Messages' + dependencies = {'xep_0030'} + stanza = stanza + namespace = stanza.NS + + def plugin_init(self) -> None: + stanza.register_plugins() + Message.sub_interfaces.add('spoiler') + + def session_bind(self, jid: JID): + self.xmpp['xep_0030'].add_feature(stanza.NS) + + def plugin_end(self): + self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS) + Message.sub_interfaces.remove('spoiler') diff --git a/slixmpp/plugins/xep_0382/stanza.py b/slixmpp/plugins/xep_0382/stanza.py new file mode 100644 index 00000000..0ce2b5f4 --- /dev/null +++ b/slixmpp/plugins/xep_0382/stanza.py @@ -0,0 +1,26 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2021 Mathieu Pasquet + This file is part of Slixmpp. + + See the file LICENSE for copying permissio +""" + +from slixmpp.stanza import Message +from slixmpp.xmlstream import ( + register_stanza_plugin, + ElementBase, +) + + +NS = 'urn:xmpp:spoiler:0' + + +class Spoiler(ElementBase): + namespace = NS + name = 'spoiler' + plugin_attrib = 'spoiler' + + +def register_plugins(): + register_stanza_plugin(Message, Spoiler)