nsarchive 3.0.0a2__tar.gz → 3.0.0a3__tar.gz
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-3.0.0a2 → nsarchive-3.0.0a3}/PKG-INFO +1 -1
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/__init__.py +1 -1
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/cls/entities.py +25 -55
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/instances/_entities.py +15 -30
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/pyproject.toml +1 -1
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/LICENSE +0 -0
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/README.md +0 -0
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/assets/default_avatar.png +0 -0
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/cls/archives.py +0 -0
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/cls/base.py +0 -0
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/cls/economy.py +0 -0
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/cls/republic.py +0 -0
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/instances/_economy.py +0 -0
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/instances/_republic.py +0 -0
- {nsarchive-3.0.0a2 → nsarchive-3.0.0a3}/nsarchive/utils.py +0 -0
@@ -1,7 +1,8 @@
|
|
1
1
|
import requests
|
2
2
|
import time
|
3
3
|
import typing
|
4
|
-
import urllib
|
4
|
+
import urllib
|
5
|
+
import warnings
|
5
6
|
|
6
7
|
from .base import NSID
|
7
8
|
|
@@ -37,6 +38,7 @@ class PositionPermissions:
|
|
37
38
|
self.items = Permission("---r") # APPEND = vendre, MANAGE = gérer des items dont on n'est pas propriétaire (hors marketplace), EDIT = gérer des items dont on n'est pas propriétaire (dans le marketplace), READ = accéder au marketplace
|
38
39
|
self.laws = Permission() # APPEND = proposer un texte de loi, MANAGE = accepter ou refuser une proposition, EDIT = modifier un texte, READ = /
|
39
40
|
self.members = Permission("---r") # APPEND = créer des entités, MANAGE = modérer des entités (hors Discord), EDIT = modifier des entités, READ = voir le profil des entités
|
41
|
+
self.money = Permission("---r") # APPEND = créer des entités, MANAGE = modérer des entités (hors Discord), EDIT = modifier des entités, READ = voir le profil des entités
|
40
42
|
self.national_channel = Permission() # APPEND = prendre la parole sur la chaîne nationale, MANAGE = voir qui peut prendre la parole, EDIT = modifier le planning de la chaîne nationale, READ = /
|
41
43
|
self.organizations = Permission("---r") # APPEND = créer une nouvelle organisation, MANAGE = exécuter des actions administratives sur les organisations, EDIT = modifier des organisations, READ = voir le profil de n'importe quelle organisation
|
42
44
|
self.reports = Permission() # APPEND = déposer plainte, MANAGE = accépter ou refuser une plainte, EDIT = /, READ = accéder à des infos supplémentaires pour une plainte
|
@@ -170,7 +172,13 @@ class User(Entity):
|
|
170
172
|
|
171
173
|
self.xp: int = 0
|
172
174
|
self.boosts: dict[str, int] = {}
|
173
|
-
self.
|
175
|
+
self.votes: list[NSID] = []
|
176
|
+
|
177
|
+
def _load(self, _data: dict):
|
178
|
+
self.xp = _data['xp']
|
179
|
+
self.boosts = _data['boosts']
|
180
|
+
|
181
|
+
self.votes = [ NSID(vote) for vote in _data['votes'] ]
|
174
182
|
|
175
183
|
def get_level(self) -> None:
|
176
184
|
i = 0
|
@@ -255,37 +263,6 @@ class GroupInvite:
|
|
255
263
|
self.level: str = 0
|
256
264
|
self._expires: int = round(time.time()) + 604800
|
257
265
|
|
258
|
-
class Share:
|
259
|
-
"""
|
260
|
-
Action d'une entreprise
|
261
|
-
|
262
|
-
## Attributs
|
263
|
-
- owner: `NSID`\n
|
264
|
-
Identifiant du titulaire de l'action
|
265
|
-
- price: `int`\n
|
266
|
-
Prix de l'action
|
267
|
-
"""
|
268
|
-
|
269
|
-
def __getstate__(self) -> dict:
|
270
|
-
return {
|
271
|
-
"owner": self.owner,
|
272
|
-
"price": self.price
|
273
|
-
}
|
274
|
-
|
275
|
-
def __setstate__(self, state: dict):
|
276
|
-
self.owner: NSID = state['owner']
|
277
|
-
self.price: int = state['price']
|
278
|
-
|
279
|
-
def __init__(self, owner: NSID = NSID(0x0), price: int = 10):
|
280
|
-
self.owner: NSID = owner
|
281
|
-
self.price: int = price
|
282
|
-
|
283
|
-
def assign_owner(self, owner: NSID):
|
284
|
-
self.owner = owner
|
285
|
-
|
286
|
-
def set_price(self, price: int):
|
287
|
-
self.price = price
|
288
|
-
|
289
266
|
class Organization(Entity):
|
290
267
|
"""
|
291
268
|
Entité collective
|
@@ -314,7 +291,21 @@ class Organization(Entity):
|
|
314
291
|
self.members: list[GroupMember] = []
|
315
292
|
self.invites: dict[GroupInvite] = []
|
316
293
|
|
317
|
-
|
294
|
+
def _load(self, _data: dict):
|
295
|
+
res = requests.get(f"{self._url}/avatar")
|
296
|
+
|
297
|
+
if res.status_code == 200:
|
298
|
+
self.avatar = res.content
|
299
|
+
else:
|
300
|
+
warnings.warn(f"Failed to get avatar for {self.id}")
|
301
|
+
|
302
|
+
for _member in _data['members']:
|
303
|
+
member = GroupMember(_member['id'])
|
304
|
+
member.permission_level = _member['level']
|
305
|
+
|
306
|
+
self.members.append(member)
|
307
|
+
|
308
|
+
self.certifications = _data['certifications']
|
318
309
|
|
319
310
|
def add_certification(self, certification: str, __expires: int = 2419200) -> None:
|
320
311
|
res = requests.post(f"{self._url}/add_certification?name={certification}&duration={__expires}", headers = default_headers)
|
@@ -364,27 +355,6 @@ class Organization(Entity):
|
|
364
355
|
def get_members_by_attr(self, attribute: str = "id") -> list[str]:
|
365
356
|
return [ member.__getattribute__(attribute) for member in self.members ]
|
366
357
|
|
367
|
-
def get_shares(self, include_worth: bool = False) -> dict[str, int] | dict[str, dict[str, int]]:
|
368
|
-
shares = {}
|
369
|
-
|
370
|
-
for share in self.parts:
|
371
|
-
if include_worth:
|
372
|
-
if share.owner in shares.keys():
|
373
|
-
shares[share.owner]['count'] += 1
|
374
|
-
shares[share.owner]['worth'] += share.price
|
375
|
-
else:
|
376
|
-
shares[share.owner] = {
|
377
|
-
'count': 1,
|
378
|
-
'worth': share.price
|
379
|
-
}
|
380
|
-
else:
|
381
|
-
if share.owner in shares.keys():
|
382
|
-
shares[share.owner] += 1
|
383
|
-
else:
|
384
|
-
shares[share.owner] = 1
|
385
|
-
|
386
|
-
return shares
|
387
|
-
|
388
358
|
def save_avatar(self, data: bytes = None):
|
389
359
|
if not data:
|
390
360
|
return
|
@@ -53,7 +53,7 @@ class EntityInstance(Instance):
|
|
53
53
|
return None
|
54
54
|
elif "xp" in _data.keys():
|
55
55
|
_data['_type'] = 'user'
|
56
|
-
elif "
|
56
|
+
elif "members" in _data.keys():
|
57
57
|
_data['_type'] = 'organization'
|
58
58
|
else:
|
59
59
|
_data['_type'] = 'entity'
|
@@ -62,37 +62,13 @@ class EntityInstance(Instance):
|
|
62
62
|
entity = User(id)
|
63
63
|
entity._url = f"{self.url}/model/individuals/{id}"
|
64
64
|
|
65
|
-
entity.
|
66
|
-
entity.boosts = _data['boosts']
|
67
|
-
|
68
|
-
entity.votes = [ NSID(vote) for vote in _data['votes'] ]
|
69
|
-
entity.groups = [ NSID(group) for group in _data['groups'] ]
|
65
|
+
entity._load(_data)
|
70
66
|
elif _data['_type'] == 'organization':
|
71
67
|
entity = Organization(id)
|
72
68
|
entity._url = f"{self.url}/model/organizations/{id}"
|
69
|
+
entity.owner = self.get_entity(_data["owner_id"])
|
73
70
|
|
74
|
-
|
75
|
-
|
76
|
-
if res.status_code == 200:
|
77
|
-
entity.avatar = res.content
|
78
|
-
else:
|
79
|
-
warnings.warn(f"Failed to get avatar for {id}")
|
80
|
-
|
81
|
-
entity.owner = self.get_entity(NSID(_data['owner_id']))
|
82
|
-
|
83
|
-
for _member in _data['members']:
|
84
|
-
member = GroupMember(_member['id'])
|
85
|
-
member.permission_level = _member['level']
|
86
|
-
|
87
|
-
entity.append(member)
|
88
|
-
|
89
|
-
entity.parts = []
|
90
|
-
|
91
|
-
for attrs in _data['parts']:
|
92
|
-
owner = attrs["owner"]
|
93
|
-
entity.parts.extend(attrs['count'] * [ Share(NSID(owner), attrs['worth'] // attrs['count']) ])
|
94
|
-
|
95
|
-
entity.certifications = _data['certifications']
|
71
|
+
entity._load(_data)
|
96
72
|
else:
|
97
73
|
entity = Entity(id)
|
98
74
|
|
@@ -108,6 +84,16 @@ class EntityInstance(Instance):
|
|
108
84
|
|
109
85
|
return entity
|
110
86
|
|
87
|
+
def get_entity_groups(self, entity: User) -> list[Organization]:
|
88
|
+
print(entity._url)
|
89
|
+
res = requests.get(f"{entity._url}/groups", headers = self.default_headers)
|
90
|
+
|
91
|
+
if res.status_code == 200:
|
92
|
+
return res.json()
|
93
|
+
else:
|
94
|
+
res.raise_for_status()
|
95
|
+
return []
|
96
|
+
|
111
97
|
def save_entity(self, entity: Entity):
|
112
98
|
"""
|
113
99
|
Fonction permettant de créer ou modifier une entité.
|
@@ -137,7 +123,6 @@ class EntityInstance(Instance):
|
|
137
123
|
_data['owner_id'] = NSID(entity.owner.id) if entity.owner else NSID("0")
|
138
124
|
_data['members'] = []
|
139
125
|
_data['certifications'] = entity.certifications
|
140
|
-
_data['parts'] = entity.get_shares(True)
|
141
126
|
|
142
127
|
for member in entity.members:
|
143
128
|
_member = {
|
@@ -151,7 +136,7 @@ class EntityInstance(Instance):
|
|
151
136
|
elif type(entity) == User:
|
152
137
|
_data['xp'] = entity.xp
|
153
138
|
_data['boosts'] = entity.boosts
|
154
|
-
|
139
|
+
_data['votes'] = [ NSID(vote) for vote in entity.votes]
|
155
140
|
else:
|
156
141
|
return
|
157
142
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|