nsarchive 3.0.0a1__py3-none-any.whl → 3.0.0a2__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.
@@ -1,18 +1,14 @@
1
1
  import time
2
2
 
3
- from supabase import create_client
4
-
5
3
  from ..cls.base import *
6
4
  from ..cls.archives import *
7
5
  from ..cls.economy import *
8
6
 
9
- from ..cls.exceptions import *
10
-
11
7
  class EconomyInstance(Instance):
12
- """Gère les interactions avec les comptes bancaires, les transactions, et le marché."""
8
+ """Indisponible dans cette version."""
13
9
 
14
- def __init__(self, id: str, token: str) -> None:
15
- super().__init__(create_client(f"https://{id}.supabase.co", token))
10
+ def __init__(self, url: str, token: str) -> None:
11
+ super().__init__(url, token)
16
12
 
17
13
  """
18
14
  ---- COMPTES EN BANQUE ----
@@ -20,6 +16,7 @@ class EconomyInstance(Instance):
20
16
 
21
17
  def get_account(self, id: NSID) -> BankAccount:
22
18
  """
19
+ *INDISPONIBLE DANS CETTE VERSION.*\n
23
20
  Récupère les informations d'un compte bancaire.
24
21
 
25
22
  ## Paramètres
@@ -30,6 +27,8 @@ class EconomyInstance(Instance):
30
27
  - `.BankAccount`
31
28
  """
32
29
 
30
+ return BankAccount(NSID(id)) # Provisoire
31
+
33
32
  id = NSID(id)
34
33
  _data = self._get_by_ID('accounts', id)
35
34
 
@@ -47,6 +46,7 @@ class EconomyInstance(Instance):
47
46
 
48
47
  def save_account(self, account: BankAccount):
49
48
  """
49
+ *INDISPONIBLE DANS CETTE VERSION.*\n
50
50
  Sauvegarde un compte bancaire dans la base de données.
51
51
 
52
52
  ## Paramètres
@@ -54,6 +54,8 @@ class EconomyInstance(Instance):
54
54
  Compte à sauvegarder
55
55
  """
56
56
 
57
+ return # Provisoire
58
+
57
59
  _data = {
58
60
  'id': NSID(account.id),
59
61
  'amount': account.amount,
@@ -67,6 +69,7 @@ class EconomyInstance(Instance):
67
69
 
68
70
  def freeze_account(self, account: BankAccount):
69
71
  """
72
+ *INDISPONIBLE DANS CETTE VERSION.*\n
70
73
  Gèle un compte bancaire pour empêcher toute transaction.
71
74
 
72
75
  ## Paramètres
@@ -74,6 +77,8 @@ class EconomyInstance(Instance):
74
77
  Compte à geler
75
78
  """
76
79
 
80
+ return # Provisoire
81
+
77
82
  account.id = NSID(account.id)
78
83
  account.frozen = True
79
84
 
@@ -85,6 +90,7 @@ class EconomyInstance(Instance):
85
90
 
86
91
  def save_item(self, item: Item):
87
92
  """
93
+ *INDISPONIBLE DANS CETTE VERSION.*\n
88
94
  Sauvegarde des infos à propos d'un item.
89
95
 
90
96
  ## Paramètres
@@ -92,11 +98,14 @@ class EconomyInstance(Instance):
92
98
  Article à sauvegarder
93
99
  """
94
100
 
101
+ return # Provisoire
102
+
95
103
  _item = item.__dict__
96
104
  self._put_in_db('items', _item)
97
105
 
98
106
  def get_item(self, id: NSID) -> Item | None:
99
107
  """
108
+ *INDISPONIBLE DANS CETTE VERSION.*\n
100
109
  Récupère des informations à propos d'un item.
101
110
 
102
111
  ## Paramètres
@@ -108,6 +117,8 @@ class EconomyInstance(Instance):
108
117
  - `None`
109
118
  """
110
119
 
120
+ return Item(NSID(id)) # Provisoire
121
+
111
122
  _item = self._get_by_ID('items', id)
112
123
 
113
124
  if _item is None:
@@ -121,6 +132,7 @@ class EconomyInstance(Instance):
121
132
 
122
133
  def delete_item(self, item: Item):
123
134
  """
135
+ *INDISPONIBLE DANS CETTE VERSION.*\n
124
136
  Annule le référencement d'un item.
125
137
 
126
138
  ## Paramètres
@@ -128,10 +140,13 @@ class EconomyInstance(Instance):
128
140
  Item à supprimer
129
141
  """
130
142
 
143
+ return # Provisoire
144
+
131
145
  self._delete_by_ID('items', item.id)
132
146
 
133
147
  def get_sale(self, id: NSID) -> Sale | None:
134
148
  """
149
+ *INDISPONIBLE DANS CETTE VERSION.*\n
135
150
  Récupère une vente disponible sur le marketplace.
136
151
 
137
152
  ## Paramètres
@@ -142,6 +157,8 @@ class EconomyInstance(Instance):
142
157
  - `.Sale | None`: Le résultat de la vente
143
158
  """
144
159
 
160
+ return Sale(NSID(id), Item(NSID(id))) # Provisoire
161
+
145
162
  id = NSID(id)
146
163
 
147
164
  _data = self._get_by_ID('market', id)
@@ -158,6 +175,7 @@ class EconomyInstance(Instance):
158
175
 
159
176
  def sell_item(self, item: Item, quantity: int, price: int, seller: NSID):
160
177
  """
178
+ *INDISPONIBLE DANS CETTE VERSION.*\n
161
179
  Vend un item sur le marché.
162
180
 
163
181
  ## Paramètres
@@ -171,6 +189,8 @@ class EconomyInstance(Instance):
171
189
  ID de l'auteur de la vente
172
190
  """
173
191
 
192
+ return # Provisoire
193
+
174
194
  sale = Sale(NSID(round(time.time()) * 16 ** 3), item)
175
195
  sale.quantity = quantity
176
196
  sale.price = price
@@ -181,7 +201,12 @@ class EconomyInstance(Instance):
181
201
  self._put_in_db('market', _data)
182
202
 
183
203
  def delete_sale(self, sale: Sale) -> None:
184
- """Annule une vente sur le marketplace."""
204
+ """
205
+ *INDISPONIBLE DANS CETTE VERSION.*\n
206
+ Annule une vente sur le marketplace.
207
+ """
208
+
209
+ return # Provisoire
185
210
 
186
211
  sale.id = NSID(sale.id)
187
212
  self._delete_by_ID('market', NSID(sale.id))
@@ -192,6 +217,7 @@ class EconomyInstance(Instance):
192
217
 
193
218
  def get_inventory(self, id: NSID) -> Inventory | None:
194
219
  """
220
+ *INDISPONIBLE DANS CETTE VERSION.*\n
195
221
  Récupérer un inventaire dans la base des inventaires.
196
222
 
197
223
  ## Paramètres
@@ -202,6 +228,8 @@ class EconomyInstance(Instance):
202
228
  - `.Inventory | None`: L'inventaire s'il a été trouvé
203
229
  """
204
230
 
231
+ return Inventory(NSID(id)) # Provisoire
232
+
205
233
  _data = self._get_by_ID('inventories', id)
206
234
 
207
235
  if _data is None:
@@ -218,6 +246,7 @@ class EconomyInstance(Instance):
218
246
 
219
247
  def save_inventory(self, inventory: Inventory):
220
248
  """
249
+ *INDISPONIBLE DANS CETTE VERSION.*\n
221
250
  Sauvegarder un inventaire
222
251
 
223
252
  ## Paramètres
@@ -225,12 +254,15 @@ class EconomyInstance(Instance):
225
254
  Inventaire à sauvegarder
226
255
  """
227
256
 
257
+ return # Provisoire
258
+
228
259
  _data = inventory.__dict__
229
260
 
230
261
  self._put_in_db('inventories', _data)
231
262
 
232
263
  def delete_inventory(self, inventory: Inventory):
233
264
  """
265
+ *INDISPONIBLE DANS CETTE VERSION.*\n
234
266
  Supprime un inventaire
235
267
 
236
268
  ## Paramètres
@@ -238,6 +270,8 @@ class EconomyInstance(Instance):
238
270
  Inventaire à supprimer
239
271
  """
240
272
 
273
+ return # Provisoire
274
+
241
275
  self._delete_by_ID('inventories', inventory.owner_id)
242
276
 
243
277
  """
@@ -246,6 +280,7 @@ class EconomyInstance(Instance):
246
280
 
247
281
  def _add_archive(self, archive: Archive):
248
282
  """
283
+ *INDISPONIBLE DANS CETTE VERSION.*\n
249
284
  Ajoute une archive d'une transaction ou d'une vente dans la base de données.
250
285
 
251
286
  ## Paramètres
@@ -253,6 +288,8 @@ class EconomyInstance(Instance):
253
288
  Archive à ajouter
254
289
  """
255
290
 
291
+ return # Provisoire
292
+
256
293
  archive.id = NSID(archive.id)
257
294
  archive.author = NSID(archive.author)
258
295
  archive.target = NSID(archive.target)
@@ -268,6 +305,7 @@ class EconomyInstance(Instance):
268
305
 
269
306
  def _get_archive(self, id: NSID) -> Archive | Transaction:
270
307
  """
308
+ *INDISPONIBLE DANS CETTE VERSION.*\n
271
309
  Récupère une archive spécifique.
272
310
 
273
311
  ## Paramètres
@@ -278,6 +316,8 @@ class EconomyInstance(Instance):
278
316
  - `.Archive | .Transaction`
279
317
  """
280
318
 
319
+ return Archive() # Provisoire
320
+
281
321
  id = NSID(id)
282
322
  _data = self._get_by_ID('archives', id)
283
323
 
@@ -298,6 +338,7 @@ class EconomyInstance(Instance):
298
338
 
299
339
  def _fetch_archives(self, **query) -> list[ Archive | Transaction ]:
300
340
  """
341
+ *INDISPONIBLE DANS CETTE VERSION.*\n
301
342
  Récupère une liste d'archives correspondant à la requête.
302
343
 
303
344
  ## Paramètres
@@ -308,6 +349,8 @@ class EconomyInstance(Instance):
308
349
  - `list[.Archive | .Transaction]`
309
350
  """
310
351
 
352
+ return [] # Provisoire
353
+
311
354
  _res = self.fetch('archives', **query)
312
355
 
313
356
  return [ self._get_archive(archive['id']) for archive in _res ]
@@ -1,10 +1,7 @@
1
- from supabase import create_client
2
-
3
1
  from ..cls.base import *
4
2
  from ..cls.entities import *
5
- from ..cls.archives import *
6
3
 
7
- from ..cls.exceptions import *
4
+ from ..cls import entities # Pour les default_headers
8
5
 
9
6
  class EntityInstance(Instance):
10
7
  """
@@ -18,20 +15,24 @@ class EntityInstance(Instance):
18
15
  - Sanctions et modifications d'une entité: `.Action[ .AdminAction | .Sanction ]`
19
16
  """
20
17
 
21
- def __init__(self, id: str, token: str) -> None:
22
- super().__init__(create_client(f"https://{id}.supabase.co", token))
18
+ def __init__(self, url: str, token: str = None) -> None:
19
+ super().__init__(url, token)
20
+
21
+ entities.default_headers = self.default_headers
23
22
 
24
23
  """
25
24
  ---- ENTITÉS ----
26
25
  """
27
26
 
28
- def get_entity(self, id: NSID) -> User | Organization | Entity:
27
+ def get_entity(self, id: NSID, _class: str = None) -> User | Organization | Entity:
29
28
  """
30
29
  Fonction permettant de récupérer le profil public d'une entité.\n
31
30
 
32
31
  ## Paramètres
33
- id: `NSID`\n
32
+ id: `NSID`
34
33
  ID héxadécimal de l'entité à récupérer
34
+ _class: `str`
35
+ Classe du modèle à prendre (`.User` ou `.Organization`)
35
36
 
36
37
  ## Renvoie
37
38
  - `.User` dans le cas où l'entité choisie est un membre
@@ -41,56 +42,58 @@ class EntityInstance(Instance):
41
42
 
42
43
  id = NSID(id)
43
44
 
44
- _data = self._get_by_ID('individuals', id)
45
-
46
- if _data is None: # Aucune entité individuelle sous cet ID
47
- _data = self._get_by_ID('organizations', id) # On cherche du côté des groupes
45
+ if _class == "user":
46
+ _data = self._get_by_ID('individuals', id)
47
+ elif _class == "group":
48
+ _data = self._get_by_ID('organizations', id)
48
49
  else:
49
- _data['_type'] = 'user'
50
+ _data = self._get_by_ID('entities', id)
50
51
 
51
52
  if _data is None: # ID inexistant chez les entités
52
53
  return None
53
- elif '_type' not in _data.keys(): # S'il existe chez les organisations, clé '_type' pas encore initialisée
54
+ elif "xp" in _data.keys():
55
+ _data['_type'] = 'user'
56
+ elif "parts" in _data.keys():
54
57
  _data['_type'] = 'organization'
58
+ else:
59
+ _data['_type'] = 'entity'
55
60
 
56
61
  if _data['_type'] == 'user':
57
62
  entity = User(id)
63
+ entity._url = f"{self.url}/model/individuals/{id}"
58
64
 
59
65
  entity.xp = _data['xp']
60
66
  entity.boosts = _data['boosts']
61
67
 
62
68
  entity.votes = [ NSID(vote) for vote in _data['votes'] ]
69
+ entity.groups = [ NSID(group) for group in _data['groups'] ]
63
70
  elif _data['_type'] == 'organization':
64
71
  entity = Organization(id)
72
+ entity._url = f"{self.url}/model/organizations/{id}"
73
+
74
+ res = requests.get(f"{entity._url}/avatar")
75
+
76
+ if res.status_code == 200:
77
+ entity.avatar = res.content
78
+ else:
79
+ warnings.warn(f"Failed to get avatar for {id}")
65
80
 
66
81
  entity.owner = self.get_entity(NSID(_data['owner_id']))
67
82
 
68
83
  for _member in _data['members']:
69
84
  member = GroupMember(_member['id'])
70
- member.permission_level = _member['position']
71
-
72
- _member_profile = self.get_entity(member.id)
73
-
74
- member.set_name(_member_profile.name)
75
- member.position = _member_profile.position
76
- member.registerDate = _member_profile.registerDate
77
-
78
- member.xp = _member_profile.xp
79
- member.boosts = _member_profile.boosts
80
-
81
- member.permissions = _member_profile.permissions
82
- member.votes = _member_profile.votes
85
+ member.permission_level = _member['level']
83
86
 
84
87
  entity.append(member)
85
88
 
86
89
  entity.parts = []
87
90
 
88
- for owner, attrs in _data['parts'].items():
91
+ for attrs in _data['parts']:
92
+ owner = attrs["owner"]
89
93
  entity.parts.extend(attrs['count'] * [ Share(NSID(owner), attrs['worth'] // attrs['count']) ])
90
94
 
91
95
  entity.certifications = _data['certifications']
92
- entity.avatar = self._download_from_storage('organizations', f"avatars/{entity.id}")
93
- else:
96
+ else:
94
97
  entity = Entity(id)
95
98
 
96
99
  entity.name = _data['name']
@@ -99,9 +102,9 @@ class EntityInstance(Instance):
99
102
 
100
103
  for key, value in _data.get('additional', {}).items():
101
104
  if isinstance(value, str) and value.startswith('\n'):
102
- entity.add_link(key, int(value[1:]))
105
+ entity.additional[key] = int(value[1:])
103
106
  else:
104
- entity.add_link(key, value)
107
+ entity.additional[key] = value
105
108
 
106
109
  return entity
107
110
 
@@ -139,18 +142,28 @@ class EntityInstance(Instance):
139
142
  for member in entity.members:
140
143
  _member = {
141
144
  'id': NSID(member.id),
142
- 'position': member.permission_level
145
+ 'level': member.permission_level
143
146
  }
144
147
 
145
148
  _data['members'] += [_member]
146
149
 
147
- self._upload_to_storage('organizations', entity.avatar, f'/avatars/{entity.id}', overwrite = True)
150
+ entity.save_avatar()
148
151
  elif type(entity) == User:
149
152
  _data['xp'] = entity.xp
150
153
  _data['boosts'] = entity.boosts
151
- _data['votes'] = [ NSID(vote) for vote in entity.votes]
154
+ # _data['votes'] = [ NSID(vote) for vote in entity.votes]
155
+ else:
156
+ return
157
+
158
+ self._put_in_db(
159
+ f"/new_model/{'individuals' if isinstance(entity, User) else 'organizations'}?id={urllib.parse.quote(entity.id)}&name={urllib.parse.quote(entity.name)}",
160
+ _data,
161
+ headers = self.default_headers,
162
+ use_PUT = True
163
+ )
164
+
165
+ entity._url = f"{self.url}/model/{'individuals' if isinstance(entity, User) else 'organizations'}/{entity.id}"
152
166
 
153
- self._put_in_db('individuals' if isinstance(entity, User) else 'organizations', _data)
154
167
 
155
168
  def delete_entity(self, entity: Entity):
156
169
  """
@@ -161,14 +174,17 @@ class EntityInstance(Instance):
161
174
  L'entité à supprimer
162
175
  """
163
176
 
164
- self._delete_by_ID('individuals' if isinstance(entity, User) else 'organizations', NSID(entity.id))
177
+ res = requests.post(f"{entity._url}/delete", headers = self.default_headers,)
178
+
179
+ if res.status_code != 200:
180
+ res.raise_for_status()
165
181
 
166
182
  def fetch_entities(self, **query: typing.Any) -> list[ Entity | User | Organization ]:
167
183
  """
168
184
  Récupère une liste d'entités en fonction d'une requête.
169
185
 
170
186
  ## Paramètres
171
- query: `dict`\n
187
+ query: `**dict`\n
172
188
  La requête pour filtrer les entités.
173
189
 
174
190
  ## Renvoie
@@ -184,43 +200,12 @@ class EntityInstance(Instance):
184
200
  _res = self.fetch('organizations', **query)
185
201
  else:
186
202
  del query["_type"]
187
- _res = self.fetch('individuals', **query)
188
- _res.extend(self.fetch('organizations', **query))
203
+ _res = self.fetch('entities', **query)
189
204
  else:
190
- _res = self.fetch('individuals', **query)
191
- _res.extend(self.fetch('organizations', **query))
205
+ _res = self.fetch('entities', **query)
192
206
 
193
207
  return [ self.get_entity(NSID(entity['id'])) for entity in _res if entity is not None ]
194
208
 
195
- def get_entity_groups(self, id: NSID) -> list[Organization]:
196
- """
197
- Récupère les groupes auxquels appartient une entité.
198
-
199
- ## Paramètres
200
- id: `NSID`\n
201
- ID de l'entité.
202
-
203
- ## Renvoie
204
- - `list[.Organization]`
205
- """
206
-
207
- id = NSID(id)
208
- _groups = self.fetch_entities(_type = 'organization')
209
- groups = []
210
-
211
- for group in _groups:
212
- if group is None:
213
- continue
214
-
215
- if group.owner.id == id:
216
- groups.append(group)
217
-
218
- for member in group.members:
219
- if member.id == id:
220
- groups.append(group)
221
-
222
- return [ group for group in groups ]
223
-
224
209
  def get_position(self, id: str) -> Position:
225
210
  """
226
211
  Récupère une position légale (métier, domaine professionnel).
@@ -239,83 +224,7 @@ class EntityInstance(Instance):
239
224
  return None
240
225
 
241
226
  position = Position(id)
242
- position.name = _data['title']
243
- position.permissions.edit(**{ p: True for p in _data['permissions'] })
244
-
245
- return position
246
-
247
- """
248
- ---- ARCHIVES --
249
- """
250
-
251
- def _add_archive(self, archive: Archive):
252
- """
253
- Ajoute une archive d'une action (modification au sein d'un groupe ou sanction) dans la base de données.
254
-
255
- ## Paramètres
256
- - archive: `.Archive`\n
257
- Archive à ajouter
258
- """
259
-
260
- archive.id = NSID(archive.id)
261
- archive.author = NSID(archive.author)
262
- archive.target = NSID(archive.target)
263
-
264
- _data = archive.__dict__.copy()
265
-
266
- if type(archive) == Sanction:
267
- _data['_type'] = "sanction"
268
- elif type(archive) == Report:
269
- _data['_type'] = "report"
270
- else:
271
- _data['_type'] = "action"
272
-
273
- self._put_in_db('archives', _data)
274
-
275
- def _get_archive(self, id: NSID) -> Archive | Sanction:
276
- """
277
- Récupère une archive spécifique.
278
-
279
- ## Paramètres
280
- id: `NSID`\n
281
- ID de l'archive.
282
-
283
- ## Renvoie
284
- - `.Archive | .Sanction `
285
- """
286
-
287
- id = NSID(id)
288
- _data = self._get_by_ID('archives', id)
289
-
290
- if _data is None:
291
- return None
292
-
293
- if _data['_type'] == "sanction": # Mute, ban, GAV, kick, détention, prune (xp seulement)
294
- archive = Sanction(_data['author'], _data['target'])
295
- elif _data['_type'] == "report": # Plainte
296
- archive = Report(_data['author'], _data['target'])
297
- else:
298
- archive = Archive(_data['author'], _data['target'])
299
-
300
- archive.id = id
301
- archive.date = _data['date']
302
- archive.action = _data['action']
303
- archive.details = _data['details']
304
-
305
- return archive
306
-
307
- def _fetch_archives(self, **query) -> list[ Archive | Sanction ]:
308
- """
309
- Récupère une liste d'archives correspondant à la requête.
310
-
311
- ## Paramètres
312
- query: `dict`\n
313
- Requête pour filtrer les archives.
314
-
315
- ## Renvoie
316
- - `list[.Archive | .Sanction]`
317
- """
318
-
319
- _res = self.fetch('archives', **query)
227
+ position.name = _data['name']
228
+ position.permissions.merge(_data['permissions'])
320
229
 
321
- return [ self._get_archive(archive['id']) for archive in _res ]
230
+ return position