slidge 0.1.0rc1__py3-none-any.whl → 0.1.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- slidge/__init__.py +54 -31
- slidge/__main__.py +51 -5
- slidge/command/__init__.py +28 -0
- slidge/command/adhoc.py +258 -0
- slidge/command/admin.py +193 -0
- slidge/command/base.py +441 -0
- slidge/command/categories.py +3 -0
- slidge/command/chat_command.py +288 -0
- slidge/command/register.py +179 -0
- slidge/command/user.py +250 -0
- slidge/contact/__init__.py +8 -0
- slidge/contact/contact.py +452 -0
- slidge/contact/roster.py +192 -0
- slidge/core/__init__.py +2 -0
- slidge/core/cache.py +121 -39
- slidge/core/config.py +116 -11
- slidge/core/gateway/__init__.py +3 -0
- slidge/core/gateway/base.py +895 -0
- slidge/core/gateway/caps.py +63 -0
- slidge/core/gateway/delivery_receipt.py +52 -0
- slidge/core/gateway/disco.py +80 -0
- slidge/core/gateway/mam.py +75 -0
- slidge/core/gateway/muc_admin.py +35 -0
- slidge/core/gateway/ping.py +66 -0
- slidge/core/gateway/presence.py +95 -0
- slidge/core/gateway/registration.py +53 -0
- slidge/core/gateway/search.py +102 -0
- slidge/core/gateway/session_dispatcher.py +795 -0
- slidge/core/gateway/vcard_temp.py +130 -0
- slidge/core/mixins/__init__.py +9 -1
- slidge/core/mixins/attachment.py +506 -0
- slidge/core/mixins/avatar.py +167 -0
- slidge/core/mixins/base.py +6 -19
- slidge/core/mixins/disco.py +66 -15
- slidge/core/mixins/lock.py +31 -0
- slidge/core/mixins/message.py +254 -252
- slidge/core/mixins/message_maker.py +154 -0
- slidge/core/mixins/presence.py +128 -31
- slidge/core/mixins/recipient.py +43 -0
- slidge/core/pubsub.py +275 -116
- slidge/core/session.py +586 -518
- slidge/group/__init__.py +10 -0
- slidge/group/archive.py +125 -0
- slidge/group/bookmarks.py +163 -0
- slidge/group/participant.py +458 -0
- slidge/group/room.py +1103 -0
- slidge/migration.py +18 -0
- slidge/slixfix/__init__.py +68 -0
- slidge/{util/xep_0050 → slixfix/link_preview}/__init__.py +4 -5
- slidge/slixfix/link_preview/link_preview.py +17 -0
- slidge/slixfix/link_preview/stanza.py +99 -0
- slidge/slixfix/roster.py +60 -0
- slidge/{util → slixfix}/xep_0077/register.py +1 -2
- slidge/slixfix/xep_0077/stanza.py +104 -0
- slidge/{util → slixfix}/xep_0100/gateway.py +17 -12
- slidge/slixfix/xep_0153/__init__.py +10 -0
- slidge/slixfix/xep_0153/stanza.py +25 -0
- slidge/slixfix/xep_0153/vcard_avatar.py +23 -0
- slidge/slixfix/xep_0264/__init__.py +5 -0
- slidge/slixfix/xep_0264/stanza.py +36 -0
- slidge/slixfix/xep_0264/thumbnail.py +23 -0
- slidge/slixfix/xep_0292/__init__.py +5 -0
- slidge/slixfix/xep_0292/vcard4.py +100 -0
- slidge/slixfix/xep_0313/__init__.py +12 -0
- slidge/slixfix/xep_0313/mam.py +262 -0
- slidge/slixfix/xep_0313/stanza.py +359 -0
- slidge/slixfix/xep_0317/__init__.py +5 -0
- slidge/slixfix/xep_0317/hats.py +17 -0
- slidge/slixfix/xep_0317/stanza.py +28 -0
- slidge/{util → slixfix}/xep_0356_old/privilege.py +9 -7
- slidge/slixfix/xep_0424/__init__.py +9 -0
- slidge/slixfix/xep_0424/retraction.py +77 -0
- slidge/slixfix/xep_0424/stanza.py +28 -0
- slidge/slixfix/xep_0490/__init__.py +8 -0
- slidge/slixfix/xep_0490/mds.py +47 -0
- slidge/slixfix/xep_0490/stanza.py +17 -0
- slidge/util/__init__.py +4 -6
- slidge/util/archive_msg.py +61 -0
- slidge/util/conf.py +25 -4
- slidge/util/db.py +23 -69
- slidge/util/schema.sql +126 -0
- slidge/util/sql.py +508 -0
- slidge/util/test.py +136 -86
- slidge/util/types.py +155 -14
- slidge/util/util.py +225 -51
- slidge-0.1.2.dist-info/METADATA +111 -0
- slidge-0.1.2.dist-info/RECORD +96 -0
- {slidge-0.1.0rc1.dist-info → slidge-0.1.2.dist-info}/WHEEL +1 -1
- slidge/core/adhoc.py +0 -492
- slidge/core/chat_command.py +0 -197
- slidge/core/contact.py +0 -441
- slidge/core/disco.py +0 -59
- slidge/core/gateway.py +0 -899
- slidge/core/muc/__init__.py +0 -3
- slidge/core/muc/bookmarks.py +0 -74
- slidge/core/muc/participant.py +0 -152
- slidge/core/muc/room.py +0 -348
- slidge/plugins/discord/__init__.py +0 -121
- slidge/plugins/discord/client.py +0 -121
- slidge/plugins/discord/session.py +0 -172
- slidge/plugins/dummy.py +0 -334
- slidge/plugins/facebook.py +0 -591
- slidge/plugins/hackernews.py +0 -209
- slidge/plugins/mattermost/__init__.py +0 -1
- slidge/plugins/mattermost/api.py +0 -288
- slidge/plugins/mattermost/gateway.py +0 -417
- slidge/plugins/mattermost/websocket.py +0 -248
- slidge/plugins/signal/__init__.py +0 -4
- slidge/plugins/signal/config.py +0 -4
- slidge/plugins/signal/contact.py +0 -104
- slidge/plugins/signal/gateway.py +0 -379
- slidge/plugins/signal/group.py +0 -76
- slidge/plugins/signal/session.py +0 -515
- slidge/plugins/signal/txt.py +0 -13
- slidge/plugins/signal/util.py +0 -32
- slidge/plugins/skype.py +0 -310
- slidge/plugins/steam.py +0 -400
- slidge/plugins/telegram/__init__.py +0 -6
- slidge/plugins/telegram/client.py +0 -325
- slidge/plugins/telegram/config.py +0 -21
- slidge/plugins/telegram/contact.py +0 -154
- slidge/plugins/telegram/gateway.py +0 -182
- slidge/plugins/telegram/group.py +0 -184
- slidge/plugins/telegram/session.py +0 -275
- slidge/plugins/telegram/util.py +0 -153
- slidge/plugins/whatsapp/__init__.py +0 -6
- slidge/plugins/whatsapp/config.py +0 -17
- slidge/plugins/whatsapp/contact.py +0 -33
- slidge/plugins/whatsapp/event.go +0 -455
- slidge/plugins/whatsapp/gateway.go +0 -156
- slidge/plugins/whatsapp/gateway.py +0 -69
- slidge/plugins/whatsapp/go.mod +0 -17
- slidge/plugins/whatsapp/go.sum +0 -22
- slidge/plugins/whatsapp/session.go +0 -371
- slidge/plugins/whatsapp/session.py +0 -370
- slidge/util/xep_0030/__init__.py +0 -13
- slidge/util/xep_0030/disco.py +0 -811
- slidge/util/xep_0030/stanza/__init__.py +0 -7
- slidge/util/xep_0030/stanza/info.py +0 -270
- slidge/util/xep_0030/stanza/items.py +0 -147
- slidge/util/xep_0030/static.py +0 -467
- slidge/util/xep_0050/adhoc.py +0 -631
- slidge/util/xep_0050/stanza.py +0 -180
- slidge/util/xep_0077/stanza.py +0 -71
- slidge/util/xep_0292/__init__.py +0 -1
- slidge/util/xep_0292/stanza.py +0 -167
- slidge/util/xep_0292/vcard4.py +0 -74
- slidge/util/xep_0356/__init__.py +0 -7
- slidge/util/xep_0356/permissions.py +0 -35
- slidge/util/xep_0356/privilege.py +0 -160
- slidge/util/xep_0356/stanza.py +0 -44
- slidge/util/xep_0461/__init__.py +0 -6
- slidge/util/xep_0461/reply.py +0 -48
- slidge/util/xep_0461/stanza.py +0 -80
- slidge-0.1.0rc1.dist-info/METADATA +0 -171
- slidge-0.1.0rc1.dist-info/RECORD +0 -99
- /slidge/{plugins/__init__.py → py.typed} +0 -0
- /slidge/{util → slixfix}/xep_0077/__init__.py +0 -0
- /slidge/{util → slixfix}/xep_0100/__init__.py +0 -0
- /slidge/{util → slixfix}/xep_0100/stanza.py +0 -0
- /slidge/{util → slixfix}/xep_0356_old/__init__.py +0 -0
- /slidge/{util → slixfix}/xep_0356_old/stanza.py +0 -0
- {slidge-0.1.0rc1.dist-info → slidge-0.1.2.dist-info}/LICENSE +0 -0
- {slidge-0.1.0rc1.dist-info → slidge-0.1.2.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
# Slixmpp: The Slick XMPP Library
|
2
|
+
# Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
3
|
+
# This file is part of Slixmpp.
|
4
|
+
# See the file LICENSE for copying permission
|
5
|
+
from slixmpp.plugins.base import register_plugin
|
6
|
+
|
7
|
+
from .mam import XEP_0313
|
8
|
+
from .stanza import MAM, Metadata, Result
|
9
|
+
|
10
|
+
register_plugin(XEP_0313)
|
11
|
+
|
12
|
+
__all__ = ["XEP_0313", "Result", "MAM", "Metadata"]
|
@@ -0,0 +1,262 @@
|
|
1
|
+
# Slixmpp: The Slick XMPP Library
|
2
|
+
# Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
3
|
+
# This file is part of Slixmpp.
|
4
|
+
# See the file LICENSE for copying permission
|
5
|
+
import logging
|
6
|
+
from asyncio import Future
|
7
|
+
from collections.abc import AsyncGenerator
|
8
|
+
from datetime import datetime
|
9
|
+
from typing import Any, Awaitable, Callable, Dict, Optional, Tuple
|
10
|
+
|
11
|
+
from slixmpp import JID
|
12
|
+
from slixmpp.plugins import BasePlugin
|
13
|
+
from slixmpp.plugins.xep_0004.stanza import Form
|
14
|
+
from slixmpp.stanza import Iq, Message
|
15
|
+
from slixmpp.xmlstream import register_stanza_plugin
|
16
|
+
from slixmpp.xmlstream.handler import Collector
|
17
|
+
from slixmpp.xmlstream.matcher import MatchXMLMask
|
18
|
+
|
19
|
+
from . import stanza
|
20
|
+
|
21
|
+
log = logging.getLogger(__name__)
|
22
|
+
|
23
|
+
|
24
|
+
class XEP_0313(BasePlugin):
|
25
|
+
"""
|
26
|
+
XEP-0313 Message Archive Management
|
27
|
+
"""
|
28
|
+
|
29
|
+
name = "xep_0313"
|
30
|
+
description = "XEP-0313: Message Archive Management"
|
31
|
+
dependencies = {"xep_0004", "xep_0030", "xep_0050", "xep_0059", "xep_0297"}
|
32
|
+
stanza = stanza
|
33
|
+
|
34
|
+
def plugin_init(self):
|
35
|
+
register_stanza_plugin(stanza.MAM, Form)
|
36
|
+
register_stanza_plugin(Iq, stanza.MAM)
|
37
|
+
register_stanza_plugin(Message, stanza.Result)
|
38
|
+
register_stanza_plugin(Iq, stanza.Fin)
|
39
|
+
register_stanza_plugin(stanza.Result, self.xmpp["xep_0297"].stanza.Forwarded)
|
40
|
+
register_stanza_plugin(stanza.MAM, self.xmpp["xep_0059"].stanza.Set)
|
41
|
+
register_stanza_plugin(stanza.Fin, self.xmpp["xep_0059"].stanza.Set)
|
42
|
+
register_stanza_plugin(Iq, stanza.Metadata)
|
43
|
+
register_stanza_plugin(stanza.Metadata, stanza.Start)
|
44
|
+
register_stanza_plugin(stanza.Metadata, stanza.End)
|
45
|
+
|
46
|
+
def retrieve(
|
47
|
+
self,
|
48
|
+
jid: Optional[JID] = None,
|
49
|
+
start: Optional[datetime] = None,
|
50
|
+
end: Optional[datetime] = None,
|
51
|
+
with_jid: Optional[JID] = None,
|
52
|
+
ifrom: Optional[JID] = None,
|
53
|
+
reverse: bool = False,
|
54
|
+
timeout: int = None,
|
55
|
+
callback: Callable[[Iq], None] = None,
|
56
|
+
iterator: bool = False,
|
57
|
+
rsm: Optional[Dict[str, Any]] = None,
|
58
|
+
) -> Awaitable:
|
59
|
+
"""
|
60
|
+
Send a MAM query and retrieve the results.
|
61
|
+
|
62
|
+
:param JID jid: Entity holding the MAM records
|
63
|
+
:param datetime start,end: MAM query temporal boundaries
|
64
|
+
:param JID with_jid: Filter results on this JID
|
65
|
+
:param JID ifrom: To change the from address of the query
|
66
|
+
:param bool reverse: Get the results in reverse order
|
67
|
+
:param int timeout: IQ timeout
|
68
|
+
:param func callback: Custom callback for handling results
|
69
|
+
:param bool iterator: Use RSM and iterate over a paginated query
|
70
|
+
:param dict rsm: RSM custom options
|
71
|
+
"""
|
72
|
+
iq, stanza_mask = self._pre_mam_retrieve(jid, start, end, with_jid, ifrom)
|
73
|
+
query_id = iq["id"]
|
74
|
+
amount = 10
|
75
|
+
if rsm:
|
76
|
+
for key, value in rsm.items():
|
77
|
+
iq["mam"]["rsm"][key] = str(value)
|
78
|
+
if key == "max":
|
79
|
+
amount = value
|
80
|
+
cb_data = {}
|
81
|
+
|
82
|
+
xml_mask = str(stanza_mask)
|
83
|
+
|
84
|
+
def pre_cb(query: Iq) -> None:
|
85
|
+
stanza_mask["mam_result"]["queryid"] = query["id"]
|
86
|
+
xml_mask = str(stanza_mask)
|
87
|
+
query["mam"]["queryid"] = query["id"]
|
88
|
+
collector = Collector("MAM_Results_%s" % query_id, MatchXMLMask(xml_mask))
|
89
|
+
self.xmpp.register_handler(collector)
|
90
|
+
cb_data["collector"] = collector
|
91
|
+
|
92
|
+
def post_cb(result: Iq) -> None:
|
93
|
+
results = cb_data["collector"].stop()
|
94
|
+
if result["type"] == "result":
|
95
|
+
result["mam"]["results"] = results
|
96
|
+
result["mam_fin"]["results"] = results
|
97
|
+
|
98
|
+
if iterator:
|
99
|
+
return self.xmpp["xep_0059"].iterate(
|
100
|
+
iq,
|
101
|
+
"mam",
|
102
|
+
"results",
|
103
|
+
amount=amount,
|
104
|
+
reverse=reverse,
|
105
|
+
recv_interface="mam_fin",
|
106
|
+
pre_cb=pre_cb,
|
107
|
+
post_cb=post_cb,
|
108
|
+
)
|
109
|
+
|
110
|
+
collector = Collector("MAM_Results_%s" % query_id, MatchXMLMask(xml_mask))
|
111
|
+
self.xmpp.register_handler(collector)
|
112
|
+
|
113
|
+
def wrapped_cb(iq: Iq) -> None:
|
114
|
+
results = collector.stop()
|
115
|
+
if iq["type"] == "result":
|
116
|
+
iq["mam"]["results"] = results
|
117
|
+
if callback:
|
118
|
+
callback(iq)
|
119
|
+
|
120
|
+
return iq.send(timeout=timeout, callback=wrapped_cb)
|
121
|
+
|
122
|
+
async def iterate(
|
123
|
+
self,
|
124
|
+
jid: Optional[JID] = None,
|
125
|
+
start: Optional[datetime] = None,
|
126
|
+
end: Optional[datetime] = None,
|
127
|
+
with_jid: Optional[JID] = None,
|
128
|
+
ifrom: Optional[JID] = None,
|
129
|
+
reverse: bool = False,
|
130
|
+
rsm: Optional[Dict[str, Any]] = None,
|
131
|
+
total: Optional[int] = None,
|
132
|
+
) -> AsyncGenerator:
|
133
|
+
"""
|
134
|
+
Iterate over each message of MAM query.
|
135
|
+
|
136
|
+
.. versionadded:: 1.8.0
|
137
|
+
|
138
|
+
:param jid: Entity holding the MAM records
|
139
|
+
:param start: MAM query start time
|
140
|
+
:param end: MAM query end time
|
141
|
+
:param with_jid: Filter results on this JID
|
142
|
+
:param ifrom: To change the from address of the query
|
143
|
+
:param reverse: Get the results in reverse order
|
144
|
+
:param rsm: RSM custom options
|
145
|
+
:param total: A number of messages received after which the query
|
146
|
+
should stop.
|
147
|
+
"""
|
148
|
+
iq, stanza_mask = self._pre_mam_retrieve(jid, start, end, with_jid, ifrom)
|
149
|
+
query_id = iq["id"]
|
150
|
+
amount = 10
|
151
|
+
|
152
|
+
if rsm:
|
153
|
+
for key, value in rsm.items():
|
154
|
+
iq["mam"]["rsm"][key] = str(value)
|
155
|
+
if key == "max":
|
156
|
+
amount = value
|
157
|
+
cb_data = {}
|
158
|
+
|
159
|
+
def pre_cb(query: Iq) -> None:
|
160
|
+
stanza_mask["mam_result"]["queryid"] = query["id"]
|
161
|
+
xml_mask = str(stanza_mask)
|
162
|
+
query["mam"]["queryid"] = query["id"]
|
163
|
+
collector = Collector("MAM_Results_%s" % query_id, MatchXMLMask(xml_mask))
|
164
|
+
self.xmpp.register_handler(collector)
|
165
|
+
cb_data["collector"] = collector
|
166
|
+
|
167
|
+
def post_cb(result: Iq) -> None:
|
168
|
+
results = cb_data["collector"].stop()
|
169
|
+
if result["type"] == "result":
|
170
|
+
result["mam"]["results"] = results
|
171
|
+
result["mam_fin"]["results"] = results
|
172
|
+
|
173
|
+
iterator = self.xmpp["xep_0059"].iterate(
|
174
|
+
iq,
|
175
|
+
"mam",
|
176
|
+
"results",
|
177
|
+
amount=amount,
|
178
|
+
reverse=reverse,
|
179
|
+
recv_interface="mam_fin",
|
180
|
+
pre_cb=pre_cb,
|
181
|
+
post_cb=post_cb,
|
182
|
+
)
|
183
|
+
recv_count = 0
|
184
|
+
|
185
|
+
async for page in iterator:
|
186
|
+
messages = [message for message in page["mam"]["results"]]
|
187
|
+
if reverse:
|
188
|
+
messages.reverse()
|
189
|
+
for message in messages:
|
190
|
+
yield message
|
191
|
+
recv_count += 1
|
192
|
+
if total is not None and recv_count >= total:
|
193
|
+
break
|
194
|
+
if total is not None and recv_count >= total:
|
195
|
+
break
|
196
|
+
|
197
|
+
def _pre_mam_retrieve(
|
198
|
+
self,
|
199
|
+
jid: Optional[JID] = None,
|
200
|
+
start: Optional[datetime] = None,
|
201
|
+
end: Optional[datetime] = None,
|
202
|
+
with_jid: Optional[JID] = None,
|
203
|
+
ifrom: Optional[JID] = None,
|
204
|
+
) -> Tuple[Iq, Message]:
|
205
|
+
"""Build the IQ and stanza mask for MAM results"""
|
206
|
+
iq = self.xmpp.make_iq_set(ito=jid, ifrom=ifrom)
|
207
|
+
query_id = iq["id"]
|
208
|
+
iq["mam"]["queryid"] = query_id
|
209
|
+
iq["mam"]["start"] = start
|
210
|
+
iq["mam"]["end"] = end
|
211
|
+
iq["mam"]["with"] = with_jid
|
212
|
+
|
213
|
+
stanza_mask = self.xmpp.Message()
|
214
|
+
|
215
|
+
auto_origin = stanza_mask.xml.find("{urn:xmpp:sid:0}origin-id")
|
216
|
+
if auto_origin is not None:
|
217
|
+
stanza_mask.xml.remove(auto_origin)
|
218
|
+
del stanza_mask["id"]
|
219
|
+
del stanza_mask["lang"]
|
220
|
+
stanza_mask["from"] = jid
|
221
|
+
stanza_mask["mam_result"]["queryid"] = query_id
|
222
|
+
|
223
|
+
return (iq, stanza_mask)
|
224
|
+
|
225
|
+
async def get_fields(self, jid: Optional[JID] = None, **iqkwargs) -> Form:
|
226
|
+
"""Get MAM query fields.
|
227
|
+
|
228
|
+
.. versionadded:: 1.8.0
|
229
|
+
|
230
|
+
:param jid: JID to retrieve the policy from.
|
231
|
+
:return: The Form of allowed options
|
232
|
+
"""
|
233
|
+
ifrom = iqkwargs.pop("ifrom", None)
|
234
|
+
iq = self.xmpp.make_iq_get(ito=jid, ifrom=ifrom)
|
235
|
+
iq.enable("mam")
|
236
|
+
result = await iq.send(**iqkwargs)
|
237
|
+
return result["mam"]["form"]
|
238
|
+
|
239
|
+
async def get_configuration_commands(
|
240
|
+
self, jid: Optional[JID], **discokwargs
|
241
|
+
) -> Future:
|
242
|
+
"""Get the list of MAM advanced configuration commands.
|
243
|
+
|
244
|
+
.. versionchanged:: 1.8.0
|
245
|
+
|
246
|
+
:param jid: JID to get the commands from.
|
247
|
+
"""
|
248
|
+
if jid is None:
|
249
|
+
jid = self.xmpp.boundjid.bare
|
250
|
+
return await self.xmpp["xep_0030"].get_items(
|
251
|
+
jid=jid, node="urn:xmpp:mam#configure", **discokwargs
|
252
|
+
)
|
253
|
+
|
254
|
+
def get_archive_metadata(self, jid: Optional[JID] = None, **iqkwargs) -> Future:
|
255
|
+
"""Get the archive metadata from a JID.
|
256
|
+
|
257
|
+
:param jid: JID to get the metadata from.
|
258
|
+
"""
|
259
|
+
ifrom = iqkwargs.pop("ifrom", None)
|
260
|
+
iq = self.xmpp.make_iq_get(ito=jid, ifrom=ifrom)
|
261
|
+
iq.enable("mam_metadata")
|
262
|
+
return iq.send(**iqkwargs)
|
@@ -0,0 +1,359 @@
|
|
1
|
+
# Slixmpp: The Slick XMPP Library
|
2
|
+
# Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
3
|
+
# This file is part of Slixmpp.
|
4
|
+
# See the file LICENSE for copying permissio
|
5
|
+
from datetime import datetime
|
6
|
+
from typing import Any, Iterable, List, Optional, Set, Union
|
7
|
+
|
8
|
+
from slixmpp.jid import JID
|
9
|
+
from slixmpp.plugins import xep_0082
|
10
|
+
from slixmpp.stanza import Message
|
11
|
+
from slixmpp.xmlstream import ET, ElementBase
|
12
|
+
|
13
|
+
|
14
|
+
class MAM(ElementBase):
|
15
|
+
"""A MAM Query element.
|
16
|
+
|
17
|
+
.. code-block:: xml
|
18
|
+
|
19
|
+
<iq type='set' id='juliet1'>
|
20
|
+
<query xmlns='urn:xmpp:mam:2'>
|
21
|
+
<x xmlns='jabber:x:data' type='submit'>
|
22
|
+
<field var='FORM_TYPE' type='hidden'>
|
23
|
+
<value>urn:xmpp:mam:2</value>
|
24
|
+
</field>
|
25
|
+
<field var='with'>
|
26
|
+
<value>juliet@capulet.lit</value>
|
27
|
+
</field>
|
28
|
+
</x>
|
29
|
+
</query>
|
30
|
+
</iq>
|
31
|
+
|
32
|
+
"""
|
33
|
+
|
34
|
+
name = "query"
|
35
|
+
namespace = "urn:xmpp:mam:2"
|
36
|
+
plugin_attrib = "mam"
|
37
|
+
#: Available interfaces:
|
38
|
+
#:
|
39
|
+
#: - ``queryid``: The MAM query id
|
40
|
+
#: - ``start`` and ``end``: Temporal boundaries of the query
|
41
|
+
#: - ``with``: JID of the other entity the conversation is with
|
42
|
+
#: - ``after_id``: Fetch stanzas after this specific ID
|
43
|
+
#: - ``before_id``: Fetch stanzas before this specific ID
|
44
|
+
#: - ``ids``: Fetch the stanzas matching those IDs
|
45
|
+
#: - ``results``: pseudo-interface used to accumulate MAM results during
|
46
|
+
#: fetch, not relevant for the stanza itself.
|
47
|
+
interfaces = {
|
48
|
+
"queryid",
|
49
|
+
"start",
|
50
|
+
"end",
|
51
|
+
"with",
|
52
|
+
"results",
|
53
|
+
"before_id",
|
54
|
+
"after_id",
|
55
|
+
"ids",
|
56
|
+
"flip_page",
|
57
|
+
}
|
58
|
+
sub_interfaces = {
|
59
|
+
"start",
|
60
|
+
"end",
|
61
|
+
"with",
|
62
|
+
"before_id",
|
63
|
+
"after_id",
|
64
|
+
"ids",
|
65
|
+
"flip_page",
|
66
|
+
}
|
67
|
+
|
68
|
+
def setup(self, xml=None):
|
69
|
+
ElementBase.setup(self, xml)
|
70
|
+
self._results: List[Message] = []
|
71
|
+
|
72
|
+
def _setup_form(self):
|
73
|
+
found = self.xml.find(
|
74
|
+
"{jabber:x:data}x/"
|
75
|
+
'{jabber:x:data}field[@var="FORM_TYPE"]/'
|
76
|
+
"{jabber:x:data}value[.='urn:xmpp:mam:2']"
|
77
|
+
)
|
78
|
+
if found is None:
|
79
|
+
self["form"]["type"] = "submit"
|
80
|
+
self["form"].add_field(
|
81
|
+
var="FORM_TYPE", ftype="hidden", value="urn:xmpp:mam:2"
|
82
|
+
)
|
83
|
+
|
84
|
+
def get_fields(self):
|
85
|
+
form = self.get_plugin("form", check=True)
|
86
|
+
if not form:
|
87
|
+
return {}
|
88
|
+
return form.get_fields()
|
89
|
+
|
90
|
+
def get_start(self) -> Optional[datetime]:
|
91
|
+
fields = self.get_fields()
|
92
|
+
field = fields.get("start")
|
93
|
+
if field and field["value"]:
|
94
|
+
return xep_0082.parse(field["value"])
|
95
|
+
return None
|
96
|
+
|
97
|
+
def set_start(self, value: Union[str, datetime]):
|
98
|
+
self._setup_form()
|
99
|
+
if isinstance(value, datetime):
|
100
|
+
value = xep_0082.format_datetime(value)
|
101
|
+
self.set_custom_field("start", value)
|
102
|
+
|
103
|
+
def get_end(self) -> Optional[datetime]:
|
104
|
+
fields = self.get_fields()
|
105
|
+
field = fields.get("end")
|
106
|
+
if field and field["value"]:
|
107
|
+
return xep_0082.parse(field["value"])
|
108
|
+
return None
|
109
|
+
|
110
|
+
def set_end(self, value: Union[str, datetime]):
|
111
|
+
if isinstance(value, datetime):
|
112
|
+
value = xep_0082.format_datetime(value)
|
113
|
+
self.set_custom_field("end", value)
|
114
|
+
|
115
|
+
def get_with(self) -> Optional[JID]:
|
116
|
+
fields = self.get_fields()
|
117
|
+
field = fields.get("with")
|
118
|
+
if field:
|
119
|
+
return JID(field["value"])
|
120
|
+
return None
|
121
|
+
|
122
|
+
def set_with(self, value: JID):
|
123
|
+
self.set_custom_field("with", value)
|
124
|
+
|
125
|
+
def set_custom_field(self, fieldname: str, value: Any):
|
126
|
+
self._setup_form()
|
127
|
+
fields = self.get_fields()
|
128
|
+
field = fields.get(fieldname)
|
129
|
+
if field:
|
130
|
+
field["value"] = str(value)
|
131
|
+
else:
|
132
|
+
field = self["form"].add_field(var=fieldname)
|
133
|
+
field["value"] = str(value)
|
134
|
+
|
135
|
+
def get_custom_field(self, fieldname: str) -> Optional[str]:
|
136
|
+
fields = self.get_fields()
|
137
|
+
field = fields.get(fieldname)
|
138
|
+
if field:
|
139
|
+
return field["value"]
|
140
|
+
return None
|
141
|
+
|
142
|
+
def set_before_id(self, value: str):
|
143
|
+
self.set_custom_field("before-id", value)
|
144
|
+
|
145
|
+
def get_before_id(self):
|
146
|
+
self.get_custom_field("before-id")
|
147
|
+
|
148
|
+
def set_after_id(self, value: str):
|
149
|
+
self.set_custom_field("after-id", value)
|
150
|
+
|
151
|
+
def get_after_id(self):
|
152
|
+
self.get_custom_field("after-id")
|
153
|
+
|
154
|
+
def set_ids(self, value: List[str]):
|
155
|
+
self._setup_form()
|
156
|
+
fields = self.get_fields()
|
157
|
+
field = fields.get("ids")
|
158
|
+
if field:
|
159
|
+
field["ids"] = value
|
160
|
+
else:
|
161
|
+
field = self["form"].add_field(var="ids")
|
162
|
+
field["value"] = value
|
163
|
+
|
164
|
+
def get_ids(self):
|
165
|
+
self.get_custom_field("id")
|
166
|
+
|
167
|
+
# The results interface is meant only as an easy
|
168
|
+
# way to access the set of collected message responses
|
169
|
+
# from the query.
|
170
|
+
|
171
|
+
def get_results(self) -> List[Message]:
|
172
|
+
return self._results
|
173
|
+
|
174
|
+
def set_results(self, values: List[Message]):
|
175
|
+
self._results = values
|
176
|
+
|
177
|
+
def del_results(self):
|
178
|
+
self._results = []
|
179
|
+
|
180
|
+
def get_flip_page(self):
|
181
|
+
return self.xml.find(f"{{{self.namespace}}}flip-page") is not None
|
182
|
+
|
183
|
+
|
184
|
+
class Fin(ElementBase):
|
185
|
+
"""A MAM fin element (end of query).
|
186
|
+
|
187
|
+
.. code-block:: xml
|
188
|
+
|
189
|
+
<iq type='result' id='juliet1'>
|
190
|
+
<fin xmlns='urn:xmpp:mam:2'>
|
191
|
+
<set xmlns='http://jabber.org/protocol/rsm'>
|
192
|
+
<first index='0'>28482-98726-73623</first>
|
193
|
+
<last>09af3-cc343-b409f</last>
|
194
|
+
</set>
|
195
|
+
</fin>
|
196
|
+
</iq>
|
197
|
+
|
198
|
+
"""
|
199
|
+
|
200
|
+
name = "fin"
|
201
|
+
namespace = "urn:xmpp:mam:2"
|
202
|
+
plugin_attrib = "mam_fin"
|
203
|
+
interfaces = {"results", "stable", "complete"}
|
204
|
+
|
205
|
+
def setup(self, xml=None):
|
206
|
+
ElementBase.setup(self, xml)
|
207
|
+
self._results: List[Message] = []
|
208
|
+
|
209
|
+
# The results interface is meant only as an easy
|
210
|
+
# way to access the set of collected message responses
|
211
|
+
# from the query.
|
212
|
+
|
213
|
+
def get_results(self) -> List[Message]:
|
214
|
+
return self._results
|
215
|
+
|
216
|
+
def set_results(self, values: List[Message]):
|
217
|
+
self._results = values
|
218
|
+
|
219
|
+
def del_results(self):
|
220
|
+
self._results = []
|
221
|
+
|
222
|
+
|
223
|
+
class Result(ElementBase):
|
224
|
+
"""A MAM result payload.
|
225
|
+
|
226
|
+
.. code-block:: xml
|
227
|
+
|
228
|
+
<message id='aeb213' to='juliet@capulet.lit/chamber'>
|
229
|
+
<result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
|
230
|
+
<forwarded xmlns='urn:xmpp:forward:0'>
|
231
|
+
<delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
|
232
|
+
<message xmlns='jabber:client' from="witch@shakespeare.lit"
|
233
|
+
to="macbeth@shakespeare.lit">
|
234
|
+
<body>Hail to thee</body>
|
235
|
+
</message>
|
236
|
+
</forwarded>
|
237
|
+
</result>
|
238
|
+
</message>
|
239
|
+
"""
|
240
|
+
|
241
|
+
name = "result"
|
242
|
+
namespace = "urn:xmpp:mam:2"
|
243
|
+
plugin_attrib = "mam_result"
|
244
|
+
#: Available interfaces:
|
245
|
+
#:
|
246
|
+
#: - ``queryid``: MAM queryid
|
247
|
+
#: - ``id``: ID of the result
|
248
|
+
interfaces = {"queryid", "id"}
|
249
|
+
|
250
|
+
|
251
|
+
class Metadata(ElementBase):
|
252
|
+
"""Element containing archive metadata
|
253
|
+
|
254
|
+
.. code-block:: xml
|
255
|
+
|
256
|
+
<iq type='result' id='jui8921rr9'>
|
257
|
+
<metadata xmlns='urn:xmpp:mam:2'>
|
258
|
+
<start id='YWxwaGEg' timestamp='2008-08-22T21:09:04Z' />
|
259
|
+
<end id='b21lZ2Eg' timestamp='2020-04-20T14:34:21Z' />
|
260
|
+
</metadata>
|
261
|
+
</iq>
|
262
|
+
|
263
|
+
"""
|
264
|
+
|
265
|
+
name = "metadata"
|
266
|
+
namespace = "urn:xmpp:mam:2"
|
267
|
+
plugin_attrib = "mam_metadata"
|
268
|
+
|
269
|
+
|
270
|
+
class Start(ElementBase):
|
271
|
+
"""Metadata about the start of an archive.
|
272
|
+
|
273
|
+
.. code-block:: xml
|
274
|
+
|
275
|
+
<iq type='result' id='jui8921rr9'>
|
276
|
+
<metadata xmlns='urn:xmpp:mam:2'>
|
277
|
+
<start id='YWxwaGEg' timestamp='2008-08-22T21:09:04Z' />
|
278
|
+
<end id='b21lZ2Eg' timestamp='2020-04-20T14:34:21Z' />
|
279
|
+
</metadata>
|
280
|
+
</iq>
|
281
|
+
|
282
|
+
"""
|
283
|
+
|
284
|
+
name = "start"
|
285
|
+
namespace = "urn:xmpp:mam:2"
|
286
|
+
plugin_attrib = name
|
287
|
+
#: Available interfaces:
|
288
|
+
#:
|
289
|
+
#: - ``id``: ID of the first message of the archive
|
290
|
+
#: - ``timestamp`` (``datetime``): timestamp of the first message of the
|
291
|
+
#: archive
|
292
|
+
interfaces = {"id", "timestamp"}
|
293
|
+
|
294
|
+
def get_timestamp(self) -> Optional[datetime]:
|
295
|
+
"""Get the timestamp.
|
296
|
+
|
297
|
+
:returns: The timestamp.
|
298
|
+
"""
|
299
|
+
stamp = self.xml.attrib.get("timestamp", None)
|
300
|
+
if stamp is not None:
|
301
|
+
return xep_0082.parse(stamp)
|
302
|
+
return stamp
|
303
|
+
|
304
|
+
def set_timestamp(self, value: Union[datetime, str]):
|
305
|
+
"""Set the timestamp.
|
306
|
+
|
307
|
+
:param value: Value of the timestamp (either a datetime or a
|
308
|
+
XEP-0082 timestamp string.
|
309
|
+
"""
|
310
|
+
if isinstance(value, str):
|
311
|
+
value = xep_0082.parse(value)
|
312
|
+
value = xep_0082.format_datetime(value)
|
313
|
+
self.xml.attrib["timestamp"] = value
|
314
|
+
|
315
|
+
|
316
|
+
class End(ElementBase):
|
317
|
+
"""Metadata about the end of an archive.
|
318
|
+
|
319
|
+
.. code-block:: xml
|
320
|
+
|
321
|
+
<iq type='result' id='jui8921rr9'>
|
322
|
+
<metadata xmlns='urn:xmpp:mam:2'>
|
323
|
+
<start id='YWxwaGEg' timestamp='2008-08-22T21:09:04Z' />
|
324
|
+
<end id='b21lZ2Eg' timestamp='2020-04-20T14:34:21Z' />
|
325
|
+
</metadata>
|
326
|
+
</iq>
|
327
|
+
|
328
|
+
"""
|
329
|
+
|
330
|
+
name = "end"
|
331
|
+
namespace = "urn:xmpp:mam:2"
|
332
|
+
plugin_attrib = name
|
333
|
+
#: Available interfaces:
|
334
|
+
#:
|
335
|
+
#: - ``id``: ID of the first message of the archive
|
336
|
+
#: - ``timestamp`` (``datetime``): timestamp of the first message of the
|
337
|
+
#: archive
|
338
|
+
interfaces = {"id", "timestamp"}
|
339
|
+
|
340
|
+
def get_timestamp(self) -> Optional[datetime]:
|
341
|
+
"""Get the timestamp.
|
342
|
+
|
343
|
+
:returns: The timestamp.
|
344
|
+
"""
|
345
|
+
stamp = self.xml.attrib.get("timestamp", None)
|
346
|
+
if stamp is not None:
|
347
|
+
return xep_0082.parse(stamp)
|
348
|
+
return stamp
|
349
|
+
|
350
|
+
def set_timestamp(self, value: Union[datetime, str]):
|
351
|
+
"""Set the timestamp.
|
352
|
+
|
353
|
+
:param value: Value of the timestamp (either a datetime or a
|
354
|
+
XEP-0082 timestamp string.
|
355
|
+
"""
|
356
|
+
if isinstance(value, str):
|
357
|
+
value = xep_0082.parse(value)
|
358
|
+
value = xep_0082.format_datetime(value)
|
359
|
+
self.xml.attrib["timestamp"] = value
|
@@ -0,0 +1,17 @@
|
|
1
|
+
from slixmpp.plugins import BasePlugin
|
2
|
+
|
3
|
+
from . import stanza
|
4
|
+
|
5
|
+
|
6
|
+
class XEP_0317(BasePlugin):
|
7
|
+
"""
|
8
|
+
XEP-0317: Hats
|
9
|
+
"""
|
10
|
+
|
11
|
+
name = "xep_0317"
|
12
|
+
description = "XEP-0317: Hats"
|
13
|
+
dependencies = {"xep_0045"}
|
14
|
+
stanza = stanza
|
15
|
+
|
16
|
+
def plugin_init(self):
|
17
|
+
stanza.register()
|
@@ -0,0 +1,28 @@
|
|
1
|
+
from slixmpp import Presence
|
2
|
+
from slixmpp.xmlstream import ElementBase, register_stanza_plugin
|
3
|
+
|
4
|
+
NS = "urn:xmpp:hats:0"
|
5
|
+
|
6
|
+
|
7
|
+
class Hats(ElementBase):
|
8
|
+
name = plugin_attrib = "hats"
|
9
|
+
namespace = NS
|
10
|
+
|
11
|
+
def add_hats(self, data: list[tuple[str, str]]):
|
12
|
+
for uri, title in data:
|
13
|
+
hat = Hat()
|
14
|
+
hat["uri"] = uri
|
15
|
+
hat["title"] = title
|
16
|
+
self.append(hat)
|
17
|
+
|
18
|
+
|
19
|
+
class Hat(ElementBase):
|
20
|
+
name = plugin_attrib = "hat"
|
21
|
+
namespace = NS
|
22
|
+
interfaces = {"uri", "title"}
|
23
|
+
plugin_multi_attrib = "hats"
|
24
|
+
|
25
|
+
|
26
|
+
def register():
|
27
|
+
register_stanza_plugin(Hats, Hat, iterable=True)
|
28
|
+
register_stanza_plugin(Presence, Hats)
|