summaryrefslogtreecommitdiff
path: root/slixmpp/plugins/xep_0377/stanza.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2020-05-24 13:33:51 +0200
committermathieui <mathieui@mathieui.net>2020-05-24 13:33:51 +0200
commit2e31de3f456ac2e9e4d2950c04ff3594fe41db65 (patch)
tree55add6d1cd9aac7ab63e8eeb88a667336dd25824 /slixmpp/plugins/xep_0377/stanza.py
parent04df50feac4041f20a70417136adbcc3cfc71d15 (diff)
downloadslixmpp-2e31de3f456ac2e9e4d2950c04ff3594fe41db65.tar.gz
slixmpp-2e31de3f456ac2e9e4d2950c04ff3594fe41db65.tar.bz2
slixmpp-2e31de3f456ac2e9e4d2950c04ff3594fe41db65.tar.xz
slixmpp-2e31de3f456ac2e9e4d2950c04ff3594fe41db65.zip
Add a plugin for XEP-0377: spam reporting
Diffstat (limited to 'slixmpp/plugins/xep_0377/stanza.py')
-rw-r--r--slixmpp/plugins/xep_0377/stanza.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/slixmpp/plugins/xep_0377/stanza.py b/slixmpp/plugins/xep_0377/stanza.py
new file mode 100644
index 00000000..89ec66a9
--- /dev/null
+++ b/slixmpp/plugins/xep_0377/stanza.py
@@ -0,0 +1,63 @@
+"""
+ 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.xmlstream import ET, ElementBase
+
+
+class Report(ElementBase):
+ """
+ A spam/abuse report.
+
+ Example sub stanza:
+
+ <report xmlns="urn:xmpp:reporting:0">
+ <text xml:lang="en">
+ Never came trouble to my house like this.
+ </text>
+ <spam/>
+ </report>
+
+ Stanza Interface:
+ abuse -- Flag the report as abuse
+ spam -- Flag the report as spam
+ text -- Add a reason to the report
+ """
+ name = "report"
+ namespace = "urn:xmpp:reporting:0"
+ plugin_attrib = "report"
+ interfaces = ("spam", "abuse", "text")
+ sub_interfaces = {'text'}
+
+ def get_spam(self):
+ return self.xml.find('{%s}spam' % self.namespace) is not None
+
+ def set_spam(self, value):
+ if bool(value) and not self.get_spam():
+ self.xml.append(ET.Element('{%s}spam' % self.namespace))
+ elif not bool(value):
+ found = self.xml.findall('{%s}spam' % self.namespace)
+ if elm:
+ for item in found:
+ self.xml.remove(item)
+
+ def get_abuse(self):
+ return self.xml.find('{%s}abuse' % self.namespace) is not None
+
+ def set_abuse(self, value):
+ if bool(value) and not self.get_abuse():
+ self.xml.append(ET.Element('{%s}abuse' % self.namespace))
+ elif not bool(value):
+ found = self.xml.findall('{%s}abuse' % self.namespace)
+ if elm:
+ for item in found:
+ self.xml.remove(item)
+
+class Text(ElementBase):
+ name = "text"
+ plugin_attrib = "text"
+ namespace = "urn:xmpp:reporting:0"