summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slixmpp/plugins/__init__.py1
-rw-r--r--slixmpp/plugins/xep_0425/__init__.py13
-rw-r--r--slixmpp/plugins/xep_0425/moderation.py39
-rw-r--r--slixmpp/plugins/xep_0425/stanza.py46
4 files changed, 99 insertions, 0 deletions
diff --git a/slixmpp/plugins/__init__.py b/slixmpp/plugins/__init__.py
index 61e7a995..2b02c9e3 100644
--- a/slixmpp/plugins/__init__.py
+++ b/slixmpp/plugins/__init__.py
@@ -96,6 +96,7 @@ __all__ = [
'xep_0421', # Anonymous unique occupant identifiers for MUCs
'xep_0422', # Message Fastening
'xep_0424', # Message Retraction
+ 'xep_0425', # Message Moderation
'xep_0428', # Message Fallback
'xep_0444', # Message Reactions
]
diff --git a/slixmpp/plugins/xep_0425/__init__.py b/slixmpp/plugins/xep_0425/__init__.py
new file mode 100644
index 00000000..2effe361
--- /dev/null
+++ b/slixmpp/plugins/xep_0425/__init__.py
@@ -0,0 +1,13 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+from slixmpp.plugins.xep_0425.stanza import *
+from slixmpp.plugins.xep_0425.moderation import XEP_0425
+
+register_plugin(XEP_0425)
diff --git a/slixmpp/plugins/xep_0425/moderation.py b/slixmpp/plugins/xep_0425/moderation.py
new file mode 100644
index 00000000..e840d80d
--- /dev/null
+++ b/slixmpp/plugins/xep_0425/moderation.py
@@ -0,0 +1,39 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+from typing import Optional
+
+from slixmpp import JID, Message
+from slixmpp.exceptions import IqError, IqTimeout
+from slixmpp.plugins import BasePlugin
+from slixmpp.plugins.xep_0425 import stanza
+
+
+class XEP_0425(BasePlugin):
+ '''XEP-0425: Message Moderation'''
+
+ name = 'xep_0425'
+ description = 'Message Moderation'
+ dependencies = {'xep_0424', 'xep_0421'}
+ stanza = stanza
+ namespace = stanza.NS
+
+ def plugin_init(self) -> None:
+ stanza.register_plugins()
+
+ def session_bind(self, jid):
+ self.xmpp.plugin['xep_0030'].add_feature(feature=stanza.NS)
+
+ def plugin_end(self):
+ self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS)
+
+ async def moderate(self, room: JID, id: str, reason: str = '', *,
+ ifrom: Optional[JID] = None, **iqkwargs):
+ iq = self.xmpp.make_iq_set(ito=room.bare, ifrom=ifrom)
+ iq['apply_to']['id'] = id
+ iq['apply_to']['moderate']['reason'] = reason
+ await iq.send(**iqkwargs)
diff --git a/slixmpp/plugins/xep_0425/stanza.py b/slixmpp/plugins/xep_0425/stanza.py
new file mode 100644
index 00000000..9b756953
--- /dev/null
+++ b/slixmpp/plugins/xep_0425/stanza.py
@@ -0,0 +1,46 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permissio
+"""
+
+from slixmpp.stanza import Message, Iq
+from slixmpp.xmlstream import (
+ ElementBase,
+ register_stanza_plugin,
+)
+from slixmpp.plugins.xep_0422.stanza import ApplyTo
+from slixmpp.plugins.xep_0421.stanza import OccupantId
+from slixmpp.plugins.xep_0424.stanza import Retract, Retracted
+
+
+NS = 'urn:xmpp:message-moderate:0'
+
+
+class Moderate(ElementBase):
+ namespace = NS
+ name = 'moderate'
+ plugin_attrib = 'moderate'
+ interfaces = {'reason'}
+ sub_interfaces = {'reason'}
+
+
+class Moderated(ElementBase):
+ namespace = NS
+ name = 'moderated'
+ plugin_attrib = 'moderated'
+ interfaces = {'reason', 'by'}
+ sub_interfaces = {'reason'}
+
+
+def register_plugins():
+ register_stanza_plugin(Iq, ApplyTo)
+ register_stanza_plugin(ApplyTo, Moderate)
+ register_stanza_plugin(Moderate, Retract)
+
+ register_stanza_plugin(Message, Moderated)
+ register_stanza_plugin(ApplyTo, Moderated)
+ register_stanza_plugin(Moderated, Retracted)
+ register_stanza_plugin(Moderated, OccupantId)