wnox 0.7.0__py3-none-any.whl → 0.9.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
wnox/__init__.py CHANGED
@@ -10,6 +10,10 @@ import requests as r
10
10
 
11
11
  import random
12
12
  import string
13
+ from dotenv import load_dotenv
14
+ import os
15
+ from pymongo import MongoClient
16
+
13
17
 
14
18
  nest_asyncio.apply()
15
19
  eventdatax = {}
@@ -46,6 +50,11 @@ class WSX(ClientXMPP, EventEmitter):
46
50
  connected = False
47
51
  def __init__(self, jid, password, app:str, uid:str, resource:str):
48
52
 
53
+ if "-" in app:
54
+ raise "app should not contain dash '-'"
55
+ if "-" in resource:
56
+ raise "resource should not contain dash '-'"
57
+
49
58
  ClientXMPP.__init__(self, jid, password)
50
59
  EventEmitter.__init__(self)
51
60
  self.app = app
@@ -59,10 +68,10 @@ class WSX(ClientXMPP, EventEmitter):
59
68
 
60
69
  async def start(self, event):
61
70
  """Handle session start."""
62
- print("[bridge] connected.")
71
+
63
72
  self.send_presence(ptype="presence")
64
73
  await self.get_roster()
65
- await self.emit("connect",{})
74
+ await self.emit("__connect",{})
66
75
  self.connected = True
67
76
 
68
77
 
@@ -71,7 +80,7 @@ class WSX(ClientXMPP, EventEmitter):
71
80
 
72
81
  async def on_disconnect(self, event):
73
82
  """Handle disconnection and attempt reconnection."""
74
- await self.emit("disconnect",{})
83
+ await self.emit("__disconnect",{})
75
84
  self.connected = False
76
85
  asyncio.create_task(self.reconnect())
77
86
 
@@ -95,24 +104,49 @@ class WSX(ClientXMPP, EventEmitter):
95
104
  delayed = "urn:xmpp:delay" in str(stanza)
96
105
 
97
106
  if body and not delayed:
98
- user_uid = from_jid.split('@')[0]
107
+
99
108
 
100
109
  if body.startswith("{"):
101
110
  try:
102
111
  json_data = json.loads(body)
112
+ if "__connect" in json_data:
113
+ return
114
+ if "__disconnect" in json_data:
115
+ return
116
+ if "__message" in json_data:
117
+ return
118
+
103
119
  if "api" in json_data:
120
+ user_uid = from_jid.split('@')[0]
104
121
  data = {key: val for key, val in json_data.items() if key != "api"}
105
122
  data = {key: val for key, val in data.items() if key != "mid"}
106
123
  data["from"] = from_jid
107
-
108
- if True or len(user_uid) == 24 and ObjectId.is_valid(user_uid):
109
- result = await self.emit(json_data["api"], data)
110
- if result == None:
111
- result = {}
112
- self.send_message(
124
+ data["app"] = None
125
+
126
+ if len(user_uid) == 24 and ObjectId.is_valid(user_uid):
127
+ data["uid"] = user_uid
128
+ data["app"] = None
129
+ data["resource"] = None
130
+ if "@qepal.com/" in from_jid:
131
+ data["resource"] = from_jid.split("@qepal.com/")[1]
132
+
133
+ elif "conference.qepal.com" in from_jid:
134
+ pass
135
+ elif "-" in user_uid:
136
+ app = user_uid.split('-')[0]
137
+ user_uid = user_uid.split('-')[1]
138
+ data["app"] = app
139
+ data["uid"] = user_uid
140
+ data["resource"] = from_jid.split('@qepal.com/')[1]
141
+
142
+ result = await self.emit(json_data["api"], data)
143
+ if result == None:
144
+ result = {}
145
+ self.send_message(
113
146
  mto=from_jid,
114
147
  mbody=json.dumps({**result, "mid": json_data.get("mid")})
115
148
  )
149
+
116
150
  else:
117
151
  if "mid" in json_data:
118
152
  data = {key: val for key, val in json_data.items() if key != "mid"}
@@ -120,18 +154,80 @@ class WSX(ClientXMPP, EventEmitter):
120
154
  if json_data.get("mid") in eventsx:
121
155
  eventsx.get(json_data.get("mid")).set()
122
156
  else:
123
- await self.emit("message", {"from": from_jid, "body": body, "itsme": itsme, "itsbro": itsbro})
157
+
158
+ data["channel"] = None
159
+ if "@conference.qepal.com" in from_jid:
160
+ s = from_jid.split("@conference.qepal.com/")
161
+ data = {"from": from_jid, "body": body, "itsme": itsme, "itsbro": itsbro}
162
+ data["channel"] = s[0]
163
+ data["uid"] = None
164
+ data["resource"] = None
165
+ data["app"] = None
166
+ ss = s[1].split("-")
167
+ if len(ss) == 2 and len(ss[0]) == 24 and ObjectId.is_valid(ss[0]):
168
+ data["uid"] = ss[0]
169
+ data["resource"] = ss[1]
170
+ elif len(ss) == 3 and len(ss[1]) == 24 and ObjectId.is_valid(ss[1]):
171
+ data["uid"] = ss[1]
172
+ data["app"] = ss[0]
173
+ data["resource"] = ss[2]
174
+ await self.emit("__message", data)
124
175
 
125
176
  except json.JSONDecodeError:
126
177
  pass
127
178
  else:
128
- await self.emit("message", {"from": from_jid, "body": body, "itsme": itsme, "itsbro": itsbro})
129
-
179
+ data = {"from": from_jid, "body": body, "itsme": itsme, "itsbro": itsbro}
180
+ data["channel"] = None
181
+ data["uid"] = None
182
+ data["resource"] = None
183
+ data["app"] = None
184
+ if "@qepal.com" in from_jid:
185
+ ss = from_jid.split("@qepal.com/")
186
+ if len(ss) == 2 and len(ss[0]) == 24 and ObjectId.is_valid(ss[0]):
187
+ data["uid"] = ss[0]
188
+ data["resource"] = ss[1]
189
+ elif "-" in ss[0]:
190
+ sss = ss[0].split("-")
191
+ data["app"] = sss[0]
192
+ data["uid"] = sss[1]
193
+ data["resource"] = ss[1]
194
+ elif "@conference.qepal.com" in from_jid:
195
+ ss = from_jid.split("@conference.qepal.com/")
196
+ data["channel"] = ss[0]
197
+ if "-" in ss[1]:
198
+ sss = ss[1].split("-")
199
+ if len(sss) == 2:
200
+ data["uid"] = sss[0]
201
+ data["resource"] = sss[1]
202
+ elif len(sss) == 3 and len(sss[1]) == 24 and ObjectId.is_valid(sss[1]):
203
+ data["app"] = sss[0]
204
+ data["uid"] = sss[1]
205
+ data["resource"] = sss[2]
206
+ await self.emit("__message",data)
207
+
130
208
 
131
209
 
132
210
  class App:
133
211
 
212
+ udb = None
134
213
  def __init__(self, *, app:str, resource:str, securekey:str, image:str, public:bool=False):
214
+
215
+ load_dotenv(".env.local")
216
+ mongourl = os.getenv("UMONGOURL")
217
+ mongo_db = os.getenv("UMONGODB_DB")
218
+
219
+ if mongourl:
220
+ try:
221
+ client = MongoClient(mongourl)
222
+ client.server_info()
223
+ self.udb = client[mongo_db]
224
+ print("✅ mongo udb connected.")
225
+ except:
226
+ print("❌ mongo udb not connected.")
227
+ else:
228
+ print("❌ no .env.local correct file")
229
+
230
+
135
231
  self.app = app
136
232
  self.channels = set()
137
233
  self.resource = resource
@@ -166,8 +262,7 @@ class App:
166
262
  else:
167
263
  jid = jids[0]
168
264
  if jid == None:
169
- print("unable to send api (-1)")
170
- return
265
+ return { "error": "no worker found" }
171
266
 
172
267
  mid = serial_generator(10)
173
268
  msg = {"mid":mid, "api":cmd, **body }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: wnox
3
- Version: 0.7.0
3
+ Version: 0.9.0
4
4
  Summary: QE nexus client.
5
5
  Home-page: https://github.com/arminkardan/pywnox
6
6
  Author: Ethan (Armin) Cardan
@@ -14,6 +14,8 @@ Description-Content-Type: text/markdown
14
14
  License-File: LICENSE.txt
15
15
  Requires-Dist: slixmpp
16
16
  Requires-Dist: bson
17
+ Requires-Dist: python-dotenv
18
+ Requires-Dist: pymongo
17
19
  Dynamic: author
18
20
  Dynamic: home-page
19
21
  Dynamic: requires-python
@@ -0,0 +1,6 @@
1
+ wnox/__init__.py,sha256=V6y8LqJa16zkRKkfxzCeYHX6hqO2oJB4oUbcU8IP69o,12940
2
+ wnox-0.9.0.dist-info/LICENSE.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ wnox-0.9.0.dist-info/METADATA,sha256=Vms5_1QfZN_Pg2HpB7RNT5g9PLgs6zFMAqN2OIDuWpE,859
4
+ wnox-0.9.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
5
+ wnox-0.9.0.dist-info/top_level.txt,sha256=Xm9SC1bx_o6zjvo2FI-3QiZX2PZ_0UBQkGlvfYsnkwc,5
6
+ wnox-0.9.0.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- wnox/__init__.py,sha256=0A8ZDb2AIEno90-9dYpcgWrbBfObb6PJ1xotKJFbs-g,8315
2
- wnox-0.7.0.dist-info/LICENSE.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- wnox-0.7.0.dist-info/METADATA,sha256=I-B2nqRwQCDlNJdPbnG4L2XXR-zZh813VyojTDGYHIM,805
4
- wnox-0.7.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
5
- wnox-0.7.0.dist-info/top_level.txt,sha256=Xm9SC1bx_o6zjvo2FI-3QiZX2PZ_0UBQkGlvfYsnkwc,5
6
- wnox-0.7.0.dist-info/RECORD,,
File without changes