wnox 1.0.0__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wnox/__init__.py +52 -3
- {wnox-1.0.0.dist-info → wnox-1.1.0.dist-info}/METADATA +1 -1
- wnox-1.1.0.dist-info/RECORD +6 -0
- wnox-1.0.0.dist-info/RECORD +0 -6
- {wnox-1.0.0.dist-info → wnox-1.1.0.dist-info}/LICENSE.txt +0 -0
- {wnox-1.0.0.dist-info → wnox-1.1.0.dist-info}/WHEEL +0 -0
- {wnox-1.0.0.dist-info → wnox-1.1.0.dist-info}/top_level.txt +0 -0
wnox/__init__.py
CHANGED
@@ -14,6 +14,51 @@ from dotenv import load_dotenv
|
|
14
14
|
import os
|
15
15
|
from pymongo import MongoClient
|
16
16
|
|
17
|
+
import zlib
|
18
|
+
import base64
|
19
|
+
|
20
|
+
def deflate_to_base64(input_string):
|
21
|
+
"""
|
22
|
+
Compress (deflate) a string and return it as a Base64-encoded string.
|
23
|
+
|
24
|
+
:param input_string: The string to compress.
|
25
|
+
:return: The Base64-encoded compressed string.
|
26
|
+
"""
|
27
|
+
try:
|
28
|
+
# Step 1: Convert the input string to bytes
|
29
|
+
input_data = input_string.encode('utf-8')
|
30
|
+
|
31
|
+
# Step 2: Compress the data using zlib
|
32
|
+
compressed_data = zlib.compress(input_data)
|
33
|
+
|
34
|
+
# Step 3: Encode the compressed data as a Base64 string
|
35
|
+
base64_string = base64.b64encode(compressed_data).decode('utf-8')
|
36
|
+
|
37
|
+
return base64_string
|
38
|
+
except Exception as e:
|
39
|
+
print(f'Failed to deflate data: {e}')
|
40
|
+
raise
|
41
|
+
|
42
|
+
def inflate_from_base64(base64_string):
|
43
|
+
"""
|
44
|
+
Inflate (decompress) a Base64-encoded string using zlib.
|
45
|
+
|
46
|
+
:param base64_string: The Base64-encoded compressed string.
|
47
|
+
:return: The decompressed string.
|
48
|
+
"""
|
49
|
+
try:
|
50
|
+
# Step 1: Decode the Base64 string into bytes
|
51
|
+
compressed_data = base64.b64decode(base64_string)
|
52
|
+
|
53
|
+
# Step 2: Decompress the data using zlib
|
54
|
+
decompressed_data = zlib.decompress(compressed_data)
|
55
|
+
|
56
|
+
# Step 3: Convert the decompressed bytes to a string
|
57
|
+
return decompressed_data.decode('utf-8')
|
58
|
+
except Exception as e:
|
59
|
+
print(f'Failed to inflate data: {e}')
|
60
|
+
raise
|
61
|
+
|
17
62
|
|
18
63
|
nest_asyncio.apply()
|
19
64
|
eventdatax = {}
|
@@ -93,6 +138,10 @@ class WSX(ClientXMPP, EventEmitter):
|
|
93
138
|
"""Handle incoming messages."""
|
94
139
|
if stanza.tag == "{jabber:client}message":
|
95
140
|
body = str(stanza['body'])
|
141
|
+
try:
|
142
|
+
body = inflate_from_base64(body)
|
143
|
+
except:
|
144
|
+
pass
|
96
145
|
from_jid = str(stanza['from'])
|
97
146
|
itsme = from_jid and f"{self.boundjid.bare.split('@')[0]}-{self.boundjid.bare.split('@')[1]}" in from_jid
|
98
147
|
itsbro = not itsme and f"{self.boundjid.bare.split('@')[0]}-" in from_jid
|
@@ -144,7 +193,7 @@ class WSX(ClientXMPP, EventEmitter):
|
|
144
193
|
result = {}
|
145
194
|
self.send_message(
|
146
195
|
mto=from_jid,
|
147
|
-
mbody=json.dumps({**result, "mid": json_data.get("mid")})
|
196
|
+
mbody= deflate_to_base64(json.dumps({**result, "mid": json_data.get("mid")}))
|
148
197
|
)
|
149
198
|
|
150
199
|
else:
|
@@ -247,7 +296,7 @@ class App:
|
|
247
296
|
self.xmpp.on(api, cb)
|
248
297
|
|
249
298
|
def sendtojid(self, jid:str, body:str):
|
250
|
-
self.xmpp.send_message(mto=jid, mbody=body)
|
299
|
+
self.xmpp.send_message(mto=jid, mbody=deflate_to_base64(body))
|
251
300
|
|
252
301
|
def connected(self):
|
253
302
|
return self.xmpp.connected
|
@@ -287,7 +336,7 @@ class App:
|
|
287
336
|
def sendtochannel(self, channelname:str, body:str):
|
288
337
|
if channelname not in self.channels:
|
289
338
|
self.subscribe(channelname)
|
290
|
-
self.xmpp.send_message(mto=f"{channelname}@conference.qepal.com", mbody=body, mtype='groupchat')
|
339
|
+
self.xmpp.send_message(mto=f"{channelname}@conference.qepal.com", mbody=deflate_to_base64(body), mtype='groupchat')
|
291
340
|
|
292
341
|
async def loop(self):
|
293
342
|
|
@@ -0,0 +1,6 @@
|
|
1
|
+
wnox/__init__.py,sha256=CmdPo15z7gZxiG9PvTVfn9gYNxBhE5UNaUZVBBTM3TY,14536
|
2
|
+
wnox-1.1.0.dist-info/LICENSE.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
wnox-1.1.0.dist-info/METADATA,sha256=u-98O9kqrH1TT3W-RLwe6vskCP4qD91kFMenUaSPSYA,838
|
4
|
+
wnox-1.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
5
|
+
wnox-1.1.0.dist-info/top_level.txt,sha256=Xm9SC1bx_o6zjvo2FI-3QiZX2PZ_0UBQkGlvfYsnkwc,5
|
6
|
+
wnox-1.1.0.dist-info/RECORD,,
|
wnox-1.0.0.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
wnox/__init__.py,sha256=V6y8LqJa16zkRKkfxzCeYHX6hqO2oJB4oUbcU8IP69o,12940
|
2
|
-
wnox-1.0.0.dist-info/LICENSE.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
wnox-1.0.0.dist-info/METADATA,sha256=k4Hh2_CeuNy2rKCWQAtIowLPSggMo3hzqQyXJKULRKs,838
|
4
|
-
wnox-1.0.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
5
|
-
wnox-1.0.0.dist-info/top_level.txt,sha256=Xm9SC1bx_o6zjvo2FI-3QiZX2PZ_0UBQkGlvfYsnkwc,5
|
6
|
-
wnox-1.0.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|