nsarchive 3.0.0b1__py3-none-any.whl → 3.0.0b2__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.
- nsarchive/__init__.py +3 -1
- nsarchive/errors/__init__.py +1 -0
- nsarchive/errors/_globals.py +29 -0
- nsarchive/interfaces/_economy.py +0 -252
- nsarchive/interfaces/_entities.py +100 -14
- nsarchive/interfaces/_justice.py +173 -21
- nsarchive/interfaces/_state.py +177 -34
- nsarchive/mandate.py +21 -2
- nsarchive/models/base.py +108 -69
- nsarchive/models/economy.py +80 -151
- nsarchive/models/entities.py +305 -68
- nsarchive/models/justice.py +23 -2
- nsarchive/models/republic.py +44 -4
- nsarchive/models/state.py +43 -4
- nsarchive-3.0.0b2.dist-info/METADATA +90 -0
- nsarchive-3.0.0b2.dist-info/RECORD +21 -0
- nsarchive-3.0.0b1.dist-info/METADATA +0 -21
- nsarchive-3.0.0b1.dist-info/RECORD +0 -19
- {nsarchive-3.0.0b1.dist-info → nsarchive-3.0.0b2.dist-info}/LICENSE +0 -0
- {nsarchive-3.0.0b1.dist-info → nsarchive-3.0.0b2.dist-info}/WHEEL +0 -0
nsarchive/models/entities.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
import requests
|
2
2
|
import time
|
3
3
|
import typing
|
4
|
-
import urllib
|
5
|
-
import warnings
|
6
4
|
|
7
5
|
from .base import NSID
|
8
6
|
|
9
|
-
from .. import
|
7
|
+
from .. import errors
|
10
8
|
|
11
9
|
class Permission:
|
12
10
|
def __init__(self, initial: str = "----"):
|
@@ -90,14 +88,33 @@ class Position:
|
|
90
88
|
return self.id
|
91
89
|
|
92
90
|
def update_permisions(self, **permissions: str):
|
93
|
-
query = "&".join(f"{k}={
|
91
|
+
query = "&".join(f"{k}={v}" for k, v in permissions.items())
|
94
92
|
|
95
93
|
res = requests.post(f"{self._url}/update_permissions?{query}", headers = self._headers)
|
96
94
|
|
97
95
|
if res.status_code == 200:
|
98
96
|
self.permissions.merge(permissions)
|
99
|
-
|
100
|
-
|
97
|
+
elif 500 <= res.status_code < 600:
|
98
|
+
raise errors.globals.ServerDownError()
|
99
|
+
|
100
|
+
_data = res.json()
|
101
|
+
|
102
|
+
if res.status_code == 400:
|
103
|
+
if _data['message'] == "MissingParam":
|
104
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
105
|
+
elif _data['message'] == "InvalidParam":
|
106
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
107
|
+
elif _data['message'] == "InvalidToken":
|
108
|
+
raise errors.globals.AuthError("Token is not valid.")
|
109
|
+
|
110
|
+
elif res.status_code == 401:
|
111
|
+
raise errors.globals.AuthError(_data['message'])
|
112
|
+
|
113
|
+
elif res.status_code == 403:
|
114
|
+
raise errors.globals.PermissionError(_data['message'])
|
115
|
+
|
116
|
+
elif res.status_code == 404:
|
117
|
+
raise errors.globals.NotFoundError(_data['message'])
|
101
118
|
|
102
119
|
def _load(self, _data: dict, url: str, headers: dict) -> None:
|
103
120
|
self._url = url + '/model/positions/' + _data['id']
|
@@ -163,11 +180,33 @@ class Entity:
|
|
163
180
|
|
164
181
|
if res.status_code == 200:
|
165
182
|
self.name = new_name
|
166
|
-
|
167
|
-
|
183
|
+
elif 500 <= res.status_code < 600:
|
184
|
+
raise errors.globals.ServerDownError()
|
185
|
+
|
186
|
+
_data = res.json()
|
187
|
+
|
188
|
+
if res.status_code == 400:
|
189
|
+
if _data['message'] == "MissingParam":
|
190
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
191
|
+
elif _data['message'] == "InvalidParam":
|
192
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
193
|
+
elif _data['message'] == "InvalidToken":
|
194
|
+
raise errors.globals.AuthError("Token is not valid.")
|
195
|
+
|
196
|
+
elif res.status_code == 401:
|
197
|
+
raise errors.globals.AuthError(_data['message'])
|
168
198
|
|
169
|
-
|
170
|
-
|
199
|
+
elif res.status_code == 403:
|
200
|
+
raise errors.globals.PermissionError(_data['message'])
|
201
|
+
|
202
|
+
elif res.status_code == 404:
|
203
|
+
raise errors.globals.NotFoundError(_data['message'])
|
204
|
+
|
205
|
+
def set_position(self, position: str | Position) -> None:
|
206
|
+
if isinstance(position, Position):
|
207
|
+
position: str = position.id
|
208
|
+
|
209
|
+
res = requests.post(f"{self._url}/change_position?position={position}", headers = self._headers)
|
171
210
|
|
172
211
|
if res.status_code == 200:
|
173
212
|
self.position = position
|
@@ -188,22 +227,60 @@ class Entity:
|
|
188
227
|
"type": _class
|
189
228
|
}
|
190
229
|
|
191
|
-
query = "&".join(f"{k}={
|
230
|
+
query = "&".join(f"{k}={v}" for k, v in params.items())
|
192
231
|
|
193
232
|
res = requests.post(f"{self._url}/add_link?{query}", headers = self._headers)
|
194
233
|
|
195
234
|
if res.status_code == 200:
|
196
235
|
self.additional[key] = value
|
197
|
-
|
198
|
-
|
236
|
+
elif 500 <= res.status_code < 600:
|
237
|
+
raise errors.globals.ServerDownError()
|
238
|
+
|
239
|
+
_data = res.json()
|
240
|
+
|
241
|
+
if res.status_code == 400:
|
242
|
+
if _data['message'] == "MissingParam":
|
243
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
244
|
+
elif _data['message'] == "InvalidParam":
|
245
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
246
|
+
elif _data['message'] == "InvalidToken":
|
247
|
+
raise errors.globals.AuthError("Token is not valid.")
|
248
|
+
|
249
|
+
elif res.status_code == 401:
|
250
|
+
raise errors.globals.AuthError(_data['message'])
|
251
|
+
|
252
|
+
elif res.status_code == 403:
|
253
|
+
raise errors.globals.PermissionError(_data['message'])
|
254
|
+
|
255
|
+
elif res.status_code == 404:
|
256
|
+
raise errors.globals.NotFoundError(_data['message'])
|
199
257
|
|
200
258
|
def unlink(self, key: str) -> None:
|
201
|
-
res = requests.post(f"{self._url}/remove_link?link={
|
259
|
+
res = requests.post(f"{self._url}/remove_link?link={key}", headers = self._headers)
|
202
260
|
|
203
261
|
if res.status_code == 200:
|
204
262
|
del self.additional[key]
|
205
|
-
|
206
|
-
|
263
|
+
elif 500 <= res.status_code < 600:
|
264
|
+
raise errors.globals.ServerDownError()
|
265
|
+
|
266
|
+
_data = res.json()
|
267
|
+
|
268
|
+
if res.status_code == 400:
|
269
|
+
if _data['message'] == "MissingParam":
|
270
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
271
|
+
elif _data['message'] == "InvalidParam":
|
272
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
273
|
+
elif _data['message'] == "InvalidToken":
|
274
|
+
raise errors.globals.AuthError("Token is not valid.")
|
275
|
+
|
276
|
+
elif res.status_code == 401:
|
277
|
+
raise errors.globals.AuthError(_data['message'])
|
278
|
+
|
279
|
+
elif res.status_code == 403:
|
280
|
+
raise errors.globals.PermissionError(_data['message'])
|
281
|
+
|
282
|
+
elif res.status_code == 404:
|
283
|
+
raise errors.globals.NotFoundError(_data['message'])
|
207
284
|
|
208
285
|
class User(Entity):
|
209
286
|
"""
|
@@ -260,8 +337,27 @@ class User(Entity):
|
|
260
337
|
|
261
338
|
if res.status_code == 200:
|
262
339
|
self.xp += amount * boost
|
263
|
-
|
264
|
-
|
340
|
+
elif 500 <= res.status_code < 600:
|
341
|
+
raise errors.globals.ServerDownError()
|
342
|
+
|
343
|
+
_data = res.json()
|
344
|
+
|
345
|
+
if res.status_code == 400:
|
346
|
+
if _data['message'] == "MissingParam":
|
347
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
348
|
+
elif _data['message'] == "InvalidParam":
|
349
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
350
|
+
elif _data['message'] == "InvalidToken":
|
351
|
+
raise errors.globals.AuthError("Token is not valid.")
|
352
|
+
|
353
|
+
elif res.status_code == 401:
|
354
|
+
raise errors.globals.AuthError(_data['message'])
|
355
|
+
|
356
|
+
elif res.status_code == 403:
|
357
|
+
raise errors.globals.PermissionError(_data['message'])
|
358
|
+
|
359
|
+
elif res.status_code == 404:
|
360
|
+
raise errors.globals.NotFoundError(_data['message'])
|
265
361
|
|
266
362
|
def edit_boost(self, name: str, multiplier: int = -1) -> None:
|
267
363
|
res = requests.post(f"{self._url}/edit_boost?boost={name}&multiplier={multiplier}", headers = self._headers)
|
@@ -271,8 +367,27 @@ class User(Entity):
|
|
271
367
|
self.boosts[name] = multiplier
|
272
368
|
else:
|
273
369
|
del self.boosts[name]
|
274
|
-
|
275
|
-
|
370
|
+
elif 500 <= res.status_code < 600:
|
371
|
+
raise errors.globals.ServerDownError()
|
372
|
+
|
373
|
+
_data = res.json()
|
374
|
+
|
375
|
+
if res.status_code == 400:
|
376
|
+
if _data['message'] == "MissingParam":
|
377
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
378
|
+
elif _data['message'] == "InvalidParam":
|
379
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
380
|
+
elif _data['message'] == "InvalidToken":
|
381
|
+
raise errors.globals.AuthError("Token is not valid.")
|
382
|
+
|
383
|
+
elif res.status_code == 401:
|
384
|
+
raise errors.globals.AuthError(_data['message'])
|
385
|
+
|
386
|
+
elif res.status_code == 403:
|
387
|
+
raise errors.globals.PermissionError(_data['message'])
|
388
|
+
|
389
|
+
elif res.status_code == 404:
|
390
|
+
raise errors.globals.NotFoundError(_data['message'])
|
276
391
|
|
277
392
|
def get_groups(self) -> list[Entity]:
|
278
393
|
res = requests.get(f"{self._url}/groups", headers = self._headers)
|
@@ -290,35 +405,107 @@ class User(Entity):
|
|
290
405
|
groups.append(group)
|
291
406
|
|
292
407
|
return groups
|
293
|
-
|
294
|
-
|
408
|
+
elif 500 <= res.status_code < 600:
|
409
|
+
raise errors.globals.ServerDownError()
|
295
410
|
|
296
|
-
|
297
|
-
"""
|
298
|
-
Permissions d'un membre à l'échelle d'un groupe
|
299
|
-
"""
|
411
|
+
_data = res.json()
|
300
412
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
413
|
+
if res.status_code == 400:
|
414
|
+
if _data['message'] == "MissingParam":
|
415
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
416
|
+
elif _data['message'] == "InvalidParam":
|
417
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
418
|
+
elif _data['message'] == "InvalidToken":
|
419
|
+
raise errors.globals.AuthError("Token is not valid.")
|
420
|
+
|
421
|
+
elif res.status_code == 401:
|
422
|
+
raise errors.globals.AuthError(_data['message'])
|
305
423
|
|
306
|
-
|
307
|
-
|
308
|
-
|
424
|
+
elif res.status_code == 403:
|
425
|
+
raise errors.globals.PermissionError(_data['message'])
|
426
|
+
|
427
|
+
elif res.status_code == 404:
|
428
|
+
raise errors.globals.NotFoundError(_data['message'])
|
309
429
|
|
310
430
|
class GroupMember:
|
311
431
|
"""
|
312
432
|
Membre au sein d'une entité collective
|
313
433
|
|
314
434
|
## Attributs
|
315
|
-
-
|
316
|
-
|
435
|
+
- level: `int`\n
|
436
|
+
Niveau d'accréditation d'un membre au sein d'un groupe
|
437
|
+
- manager: `bool`\n
|
438
|
+
Permission ou non de modifier le groupe
|
317
439
|
"""
|
318
440
|
|
319
441
|
def __init__(self, id: NSID) -> None:
|
442
|
+
self._group_url: str
|
443
|
+
self._headers: dict
|
444
|
+
|
320
445
|
self.id = id
|
321
|
-
self.
|
446
|
+
self.level: int = 1 # Plus un level est haut, plus il a de pouvoir sur les autres membres
|
447
|
+
self.manager: bool = False
|
448
|
+
|
449
|
+
def _load(self, _data: dict, group_url: str, headers: dict):
|
450
|
+
self._group_url = group_url
|
451
|
+
self._headers = headers
|
452
|
+
|
453
|
+
self.level = _data['level']
|
454
|
+
self.manager = _data['manager']
|
455
|
+
|
456
|
+
def edit(self, level: int = None, manager: bool = None) -> None:
|
457
|
+
params = {
|
458
|
+
"member": self.id
|
459
|
+
}
|
460
|
+
|
461
|
+
if level is not None: params['level'] = level
|
462
|
+
if manager is not None: params['manager'] = str(manager).lower()
|
463
|
+
|
464
|
+
res = requests.post(f"{self._group_url}/edit_member", params = params, headers = self._headers)
|
465
|
+
|
466
|
+
if res.status_code == 200:
|
467
|
+
if level:
|
468
|
+
self.level = level
|
469
|
+
else:
|
470
|
+
return
|
471
|
+
|
472
|
+
if manager is not None:
|
473
|
+
self.manager = manager
|
474
|
+
|
475
|
+
elif 500 <= res.status_code < 600:
|
476
|
+
raise errors.globals.ServerDownError()
|
477
|
+
|
478
|
+
_data = res.json()
|
479
|
+
|
480
|
+
if res.status_code == 400:
|
481
|
+
if _data['message'] == "MissingParam":
|
482
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
483
|
+
elif _data['message'] == "InvalidParam":
|
484
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
485
|
+
elif _data['message'] == "InvalidToken":
|
486
|
+
raise errors.globals.AuthError("Token is not valid.")
|
487
|
+
|
488
|
+
elif res.status_code == 401:
|
489
|
+
raise errors.globals.AuthError(_data['message'])
|
490
|
+
|
491
|
+
elif res.status_code == 403:
|
492
|
+
raise errors.globals.PermissionError(_data['message'])
|
493
|
+
|
494
|
+
elif res.status_code == 404:
|
495
|
+
raise errors.globals.NotFoundError(_data['message'])
|
496
|
+
|
497
|
+
def promote(self, level: int = None):
|
498
|
+
if level is None:
|
499
|
+
level = self.level + 1
|
500
|
+
|
501
|
+
self.edit(level = level)
|
502
|
+
|
503
|
+
def demote(self, level: int = None):
|
504
|
+
if level is None:
|
505
|
+
level = self.level - 1
|
506
|
+
|
507
|
+
self.edit(level = level)
|
508
|
+
|
322
509
|
|
323
510
|
class Organization(Entity):
|
324
511
|
"""
|
@@ -328,14 +515,12 @@ class Organization(Entity):
|
|
328
515
|
- Tous les attributs de la classe `.Entity`
|
329
516
|
- owner: `.Entity`\n
|
330
517
|
Utilisateur ou entreprise propriétaire de l'entité collective
|
331
|
-
-
|
332
|
-
|
333
|
-
- certifications: `dict[str,
|
518
|
+
- avatar_url: `str`\n
|
519
|
+
Url du logo de l'entité collective
|
520
|
+
- certifications: `dict[str, Any]`\n
|
334
521
|
Liste des certifications et de leur date d'ajout
|
335
522
|
- members: `list[.GroupMember]`\n
|
336
523
|
Liste des membres de l'entreprise
|
337
|
-
- parts: `list[.Share]`\n
|
338
|
-
Liste des actions émises par l'entreprise
|
339
524
|
"""
|
340
525
|
|
341
526
|
def __init__(self, id: NSID) -> None:
|
@@ -345,10 +530,11 @@ class Organization(Entity):
|
|
345
530
|
self.avatar_url: str = self._url + '/avatar'
|
346
531
|
|
347
532
|
self.certifications: dict = {}
|
348
|
-
self.members:
|
533
|
+
self.members: dict[NSID, GroupMember] = {}
|
349
534
|
|
350
535
|
def _load(self, _data: dict, url: str, headers: dict):
|
351
536
|
self._url = url + '/model/organizations/' + _data['id']
|
537
|
+
self.avatar_url = url + '/avatar'
|
352
538
|
self._headers = headers
|
353
539
|
|
354
540
|
self.id = NSID(_data['id'])
|
@@ -374,11 +560,11 @@ class Organization(Entity):
|
|
374
560
|
|
375
561
|
self.owner._load(_owner, url, headers)
|
376
562
|
|
377
|
-
for _member in _data['members']:
|
378
|
-
member = GroupMember(
|
379
|
-
member.
|
563
|
+
for _id, _member in _data['members'].items():
|
564
|
+
member = GroupMember(_id)
|
565
|
+
member._load(_member, self._url, headers)
|
380
566
|
|
381
|
-
self.members.
|
567
|
+
self.members[member.id] = member
|
382
568
|
|
383
569
|
self.certifications = _data['certifications']
|
384
570
|
|
@@ -387,8 +573,27 @@ class Organization(Entity):
|
|
387
573
|
|
388
574
|
if res.status_code == 200:
|
389
575
|
self.certifications[certification] = int(round(time.time()) + __expires)
|
390
|
-
|
391
|
-
|
576
|
+
elif 500 <= res.status_code < 600:
|
577
|
+
raise errors.globals.ServerDownError()
|
578
|
+
|
579
|
+
_data = res.json()
|
580
|
+
|
581
|
+
if res.status_code == 400:
|
582
|
+
if _data['message'] == "MissingParam":
|
583
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
584
|
+
elif _data['message'] == "InvalidParam":
|
585
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
586
|
+
elif _data['message'] == "InvalidToken":
|
587
|
+
raise errors.globals.AuthError("Token is not valid.")
|
588
|
+
|
589
|
+
elif res.status_code == 401:
|
590
|
+
raise errors.globals.AuthError(_data['message'])
|
591
|
+
|
592
|
+
elif res.status_code == 403:
|
593
|
+
raise errors.globals.PermissionError(_data['message'])
|
594
|
+
|
595
|
+
elif res.status_code == 404:
|
596
|
+
raise errors.globals.NotFoundError(_data['message'])
|
392
597
|
|
393
598
|
def has_certification(self, certification: str) -> bool:
|
394
599
|
return certification in self.certifications.keys()
|
@@ -398,44 +603,76 @@ class Organization(Entity):
|
|
398
603
|
|
399
604
|
if res.status_code == 200:
|
400
605
|
del self.certifications[certification]
|
401
|
-
|
402
|
-
|
606
|
+
elif 500 <= res.status_code < 600:
|
607
|
+
raise errors.globals.ServerDownError()
|
608
|
+
|
609
|
+
_data = res.json()
|
610
|
+
|
611
|
+
if res.status_code == 400:
|
612
|
+
if _data['message'] == "MissingParam":
|
613
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
614
|
+
elif _data['message'] == "InvalidParam":
|
615
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
616
|
+
elif _data['message'] == "InvalidToken":
|
617
|
+
raise errors.globals.AuthError("Token is not valid.")
|
403
618
|
|
404
|
-
|
619
|
+
elif res.status_code == 401:
|
620
|
+
raise errors.globals.AuthError(_data['message'])
|
621
|
+
|
622
|
+
elif res.status_code == 403:
|
623
|
+
raise errors.globals.PermissionError(_data['message'])
|
624
|
+
|
625
|
+
elif res.status_code == 404:
|
626
|
+
raise errors.globals.NotFoundError(_data['message'])
|
627
|
+
|
628
|
+
def add_member(self, member: NSID) -> GroupMember:
|
405
629
|
if not isinstance(member, NSID):
|
406
630
|
raise TypeError("L'entrée membre doit être de type NSID")
|
407
631
|
|
408
|
-
res = requests.post(f"{self._url}/add_member?
|
409
|
-
"permissions": permissions.__dict__
|
410
|
-
})
|
632
|
+
res = requests.post(f"{self._url}/add_member?member={member}", headers = self._headers, json = {})
|
411
633
|
|
412
634
|
if res.status_code == 200:
|
413
635
|
member = GroupMember(member)
|
414
|
-
member.
|
636
|
+
member._group_url = self._url
|
637
|
+
member._headers = self._headers
|
415
638
|
|
416
|
-
self.members.
|
417
|
-
|
418
|
-
|
639
|
+
self.members[member.id] = member
|
640
|
+
return member
|
641
|
+
elif 500 <= res.status_code < 600:
|
642
|
+
raise errors.globals.ServerDownError()
|
643
|
+
|
644
|
+
_data = res.json()
|
645
|
+
|
646
|
+
if res.status_code == 400:
|
647
|
+
if _data['message'] == "MissingParam":
|
648
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
649
|
+
elif _data['message'] == "InvalidParam":
|
650
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
651
|
+
elif _data['message'] == "InvalidToken":
|
652
|
+
raise errors.globals.AuthError("Token is not valid.")
|
653
|
+
|
654
|
+
elif res.status_code == 401:
|
655
|
+
raise errors.globals.AuthError(_data['message'])
|
656
|
+
|
657
|
+
elif res.status_code == 403:
|
658
|
+
raise errors.globals.PermissionError(_data['message'])
|
659
|
+
|
660
|
+
elif res.status_code == 404:
|
661
|
+
raise errors.globals.NotFoundError(_data['message'])
|
419
662
|
|
420
663
|
def remove_member(self, member: GroupMember) -> None:
|
421
|
-
|
664
|
+
member.demote(level = 0)
|
422
665
|
|
423
|
-
|
424
|
-
if _member.id == member.id:
|
425
|
-
self.members.remove(_member)
|
666
|
+
del self.members[member.id]
|
426
667
|
|
427
668
|
def set_owner(self, member: User) -> None:
|
428
669
|
self.owner = member
|
429
670
|
|
430
671
|
def get_member(self, id: NSID) -> GroupMember:
|
431
|
-
|
432
|
-
if member.id == id:
|
433
|
-
return member
|
434
|
-
else:
|
435
|
-
return
|
672
|
+
return self.members.get(id)
|
436
673
|
|
437
674
|
def get_members_by_attr(self, attribute: str = "id") -> list[str]:
|
438
|
-
return [ member.__getattribute__(attribute) for member in self.members ]
|
675
|
+
return [ member.__getattribute__(attribute) for member in self.members.values() ]
|
439
676
|
|
440
677
|
def save_avatar(self, data: bytes = None):
|
441
678
|
pass
|
nsarchive/models/justice.py
CHANGED
@@ -3,6 +3,8 @@ import time
|
|
3
3
|
|
4
4
|
from .base import NSID
|
5
5
|
|
6
|
+
from .. import errors
|
7
|
+
|
6
8
|
class Report:
|
7
9
|
def __init__(self, id: NSID):
|
8
10
|
self._url: str = ""
|
@@ -46,8 +48,27 @@ class Report:
|
|
46
48
|
|
47
49
|
if res.status_code == 200:
|
48
50
|
self.status = status
|
49
|
-
|
50
|
-
|
51
|
+
elif 500 <= res.status_code < 600:
|
52
|
+
raise errors.globals.ServerDownError()
|
53
|
+
|
54
|
+
_data = res.json()
|
55
|
+
|
56
|
+
if res.status_code == 400:
|
57
|
+
if _data['message'] == "MissingParam":
|
58
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
59
|
+
elif _data['message'] == "InvalidParam":
|
60
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
61
|
+
elif _data['message'] == "InvalidToken":
|
62
|
+
raise errors.globals.AuthError("Token is not valid.")
|
63
|
+
|
64
|
+
elif res.status_code == 401:
|
65
|
+
raise errors.globals.AuthError(_data['message'])
|
66
|
+
|
67
|
+
elif res.status_code == 403:
|
68
|
+
raise errors.globals.PermissionError(_data['message'])
|
69
|
+
|
70
|
+
elif res.status_code == 404:
|
71
|
+
raise errors.globals.NotFoundError(_data['message'])
|
51
72
|
|
52
73
|
class Sanction:
|
53
74
|
def __init__(self, id: NSID):
|
nsarchive/models/republic.py
CHANGED
@@ -4,6 +4,8 @@ import time
|
|
4
4
|
|
5
5
|
from .base import NSID
|
6
6
|
|
7
|
+
from .. import errors
|
8
|
+
|
7
9
|
# Votes
|
8
10
|
|
9
11
|
class VoteOption:
|
@@ -98,8 +100,27 @@ class Vote:
|
|
98
100
|
|
99
101
|
if res.status_code == 200:
|
100
102
|
self.get(id).count += 1
|
101
|
-
|
102
|
-
|
103
|
+
elif 500 <= res.status_code < 600:
|
104
|
+
raise errors.globals.ServerDownError()
|
105
|
+
|
106
|
+
_data = res.json()
|
107
|
+
|
108
|
+
if res.status_code == 400:
|
109
|
+
if _data['message'] == "MissingParam":
|
110
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
111
|
+
elif _data['message'] == "InvalidParam":
|
112
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
113
|
+
elif _data['message'] == "InvalidToken":
|
114
|
+
raise errors.globals.AuthError("Token is not valid.")
|
115
|
+
|
116
|
+
elif res.status_code == 401:
|
117
|
+
raise errors.globals.AuthError(_data['message'])
|
118
|
+
|
119
|
+
elif res.status_code == 403:
|
120
|
+
raise errors.globals.PermissionError(_data['message'])
|
121
|
+
|
122
|
+
elif res.status_code == 404:
|
123
|
+
raise errors.globals.NotFoundError(_data['message'])
|
103
124
|
|
104
125
|
def close(self):
|
105
126
|
"""
|
@@ -110,8 +131,27 @@ class Vote:
|
|
110
131
|
|
111
132
|
if res.status_code == 200:
|
112
133
|
self.endDate = round(time.time())
|
113
|
-
|
114
|
-
|
134
|
+
elif 500 <= res.status_code < 600:
|
135
|
+
raise errors.globals.ServerDownError()
|
136
|
+
|
137
|
+
_data = res.json()
|
138
|
+
|
139
|
+
if res.status_code == 400:
|
140
|
+
if _data['message'] == "MissingParam":
|
141
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
142
|
+
elif _data['message'] == "InvalidParam":
|
143
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
144
|
+
elif _data['message'] == "InvalidToken":
|
145
|
+
raise errors.globals.AuthError("Token is not valid.")
|
146
|
+
|
147
|
+
elif res.status_code == 401:
|
148
|
+
raise errors.globals.AuthError(_data['message'])
|
149
|
+
|
150
|
+
elif res.status_code == 403:
|
151
|
+
raise errors.globals.PermissionError(_data['message'])
|
152
|
+
|
153
|
+
elif res.status_code == 404:
|
154
|
+
raise errors.globals.NotFoundError(_data['message'])
|
115
155
|
|
116
156
|
class LawsuitVote(Vote):
|
117
157
|
"""
|
nsarchive/models/state.py
CHANGED
@@ -4,6 +4,7 @@ import requests
|
|
4
4
|
|
5
5
|
from .base import NSID
|
6
6
|
from .republic import Vote
|
7
|
+
from .. import errors
|
7
8
|
|
8
9
|
class Party:
|
9
10
|
def __init__(self, org_id: NSID):
|
@@ -65,11 +66,49 @@ class Election:
|
|
65
66
|
def submit_candidacy(self):
|
66
67
|
res = requests.put(f"{self._url}/submit")
|
67
68
|
|
68
|
-
if res.status_code
|
69
|
-
|
69
|
+
if 500 <= res.status_code < 600:
|
70
|
+
raise errors.globals.ServerDownError()
|
71
|
+
|
72
|
+
_data = res.json()
|
73
|
+
|
74
|
+
if res.status_code == 400:
|
75
|
+
if _data['message'] == "MissingParam":
|
76
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
77
|
+
elif _data['message'] == "InvalidParam":
|
78
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
79
|
+
elif _data['message'] == "InvalidToken":
|
80
|
+
raise errors.globals.AuthError("Token is not valid.")
|
81
|
+
|
82
|
+
elif res.status_code == 401:
|
83
|
+
raise errors.globals.AuthError(_data['message'])
|
84
|
+
|
85
|
+
elif res.status_code == 403:
|
86
|
+
raise errors.globals.PermissionError(_data['message'])
|
87
|
+
|
88
|
+
elif res.status_code == 404:
|
89
|
+
raise errors.globals.NotFoundError(_data['message'])
|
70
90
|
|
71
91
|
def cancel_candidacy(self):
|
72
92
|
res = requests.put(f"{self._url}/cancel_candidacy")
|
73
93
|
|
74
|
-
if res.status_code
|
75
|
-
|
94
|
+
if 500 <= res.status_code < 600:
|
95
|
+
raise errors.globals.ServerDownError()
|
96
|
+
|
97
|
+
_data = res.json()
|
98
|
+
|
99
|
+
if res.status_code == 400:
|
100
|
+
if _data['message'] == "MissingParam":
|
101
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
102
|
+
elif _data['message'] == "InvalidParam":
|
103
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
104
|
+
elif _data['message'] == "InvalidToken":
|
105
|
+
raise errors.globals.AuthError("Token is not valid.")
|
106
|
+
|
107
|
+
elif res.status_code == 401:
|
108
|
+
raise errors.globals.AuthError(_data['message'])
|
109
|
+
|
110
|
+
elif res.status_code == 403:
|
111
|
+
raise errors.globals.PermissionError(_data['message'])
|
112
|
+
|
113
|
+
elif res.status_code == 404:
|
114
|
+
raise errors.globals.NotFoundError(_data['message'])
|