nsarchive 2.0.0b1__tar.gz → 3.0.0a1__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.0a1/PKG-INFO +20 -0
- nsarchive-3.0.0a1/README.md +3 -0
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/cls/archives.py +24 -7
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/cls/base.py +8 -0
- nsarchive-3.0.0a1/nsarchive/cls/economy.py +100 -0
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/cls/entities.py +130 -11
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/cls/republic.py +40 -2
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/instances/_economy.py +34 -16
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/instances/_entities.py +32 -25
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/instances/_republic.py +31 -13
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/pyproject.toml +1 -1
- nsarchive-2.0.0b1/PKG-INFO +0 -177
- nsarchive-2.0.0b1/README.md +0 -160
- nsarchive-2.0.0b1/nsarchive/cls/economy.py +0 -44
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/LICENSE +0 -0
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/__init__.py +0 -0
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/assets/default_avatar.png +0 -0
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/cls/exceptions.py +0 -0
- {nsarchive-2.0.0b1 → nsarchive-3.0.0a1}/nsarchive/utils.py +0 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: nsarchive
|
3
|
+
Version: 3.0.0a1
|
4
|
+
Summary: API-wrapper pour récupérer des données liées à Nation
|
5
|
+
License: GPL-3.0
|
6
|
+
Author: happex
|
7
|
+
Author-email: 110610727+okayhappex@users.noreply.github.com
|
8
|
+
Requires-Python: >=3.10,<4.0
|
9
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
14
|
+
Requires-Dist: pillow (>=10.4,<11.0)
|
15
|
+
Requires-Dist: supabase (>=2.9.1,<3.0.0)
|
16
|
+
Description-Content-Type: text/markdown
|
17
|
+
|
18
|
+
# NSArchive
|
19
|
+
|
20
|
+
Documentation pas disponible pour l'instant
|
@@ -3,7 +3,24 @@ import time
|
|
3
3
|
from .base import *
|
4
4
|
|
5
5
|
class Archive:
|
6
|
-
def __init__(self, author:
|
6
|
+
def __init__(self, author: NSID = '0', target: NSID = '0'):
|
7
|
+
"""
|
8
|
+
Classe de référence pour toutes les archives.
|
9
|
+
|
10
|
+
## Attributs de base
|
11
|
+
- date: `int`\n
|
12
|
+
Date (timestamp) de l'exécution de l'archive
|
13
|
+
- id: `NSID`\n
|
14
|
+
Clé d'identification des archives (basée sur la date)
|
15
|
+
- author: `NSID`\n
|
16
|
+
ID de l'auteur de l'action
|
17
|
+
- target: `NSID`:
|
18
|
+
ID de la cible de l'action
|
19
|
+
- action: `str`:\n
|
20
|
+
Action effectuée
|
21
|
+
- details: `dict`\n
|
22
|
+
Ensemble de détails que les différents bots peuvent utiliser
|
23
|
+
"""
|
7
24
|
self.date: int = round(time.time())
|
8
25
|
|
9
26
|
self.id: NSID = NSID(self.date)
|
@@ -19,7 +36,7 @@ class Archive:
|
|
19
36
|
# Entities
|
20
37
|
|
21
38
|
class Sanction(Archive):
|
22
|
-
def __init__(self, author:
|
39
|
+
def __init__(self, author: NSID, target: NSID) -> None:
|
23
40
|
super().__init__(author, target)
|
24
41
|
|
25
42
|
self.details: dict = {
|
@@ -29,7 +46,7 @@ class Sanction(Archive):
|
|
29
46
|
}
|
30
47
|
|
31
48
|
class Report(Archive):
|
32
|
-
def __init__(self, author:
|
49
|
+
def __init__(self, author: NSID, target: NSID) -> None:
|
33
50
|
super().__init__(author, target)
|
34
51
|
|
35
52
|
self.details: dict = {
|
@@ -41,7 +58,7 @@ class Report(Archive):
|
|
41
58
|
# Community
|
42
59
|
|
43
60
|
class Election(Archive):
|
44
|
-
def __init__(self, author:
|
61
|
+
def __init__(self, author: NSID, target: NSID, position: str) -> None:
|
45
62
|
super().__init__(author, target)
|
46
63
|
|
47
64
|
self.details = {
|
@@ -51,7 +68,7 @@ class Election(Archive):
|
|
51
68
|
}
|
52
69
|
|
53
70
|
class Promotion(Archive):
|
54
|
-
def __init__(self, author:
|
71
|
+
def __init__(self, author: NSID, target: NSID, position: str) -> None:
|
55
72
|
super().__init__(author, target)
|
56
73
|
|
57
74
|
self.details = {
|
@@ -59,14 +76,14 @@ class Promotion(Archive):
|
|
59
76
|
}
|
60
77
|
|
61
78
|
class Demotion(Archive):
|
62
|
-
def __init__(self, author:
|
79
|
+
def __init__(self, author: NSID, target: NSID) -> None:
|
63
80
|
super().__init__(author, target)
|
64
81
|
|
65
82
|
|
66
83
|
# Bank
|
67
84
|
|
68
85
|
class Transaction(Archive):
|
69
|
-
def __init__(self, author:
|
86
|
+
def __init__(self, author: NSID, target: NSID) -> None:
|
70
87
|
super().__init__(author, target)
|
71
88
|
|
72
89
|
self.details = {
|
@@ -4,6 +4,11 @@ import typing
|
|
4
4
|
from supabase import Client
|
5
5
|
|
6
6
|
class NSID(str):
|
7
|
+
"""
|
8
|
+
Nation Server ID
|
9
|
+
|
10
|
+
ID unique et universel pour l'ensemble des entités et évènements. Il prend les `int`, les `str` et les autres instances `NSID` pour les convertir en un identifiant hexadécimal.
|
11
|
+
"""
|
7
12
|
unknown = "0"
|
8
13
|
admin = "1"
|
9
14
|
gov = "2"
|
@@ -35,6 +40,9 @@ class NSID(str):
|
|
35
40
|
return instance
|
36
41
|
|
37
42
|
class Instance:
|
43
|
+
"""
|
44
|
+
Instance qui servira de base à toutes les instances.
|
45
|
+
"""
|
38
46
|
def __init__(self, client: Client):
|
39
47
|
self.db = client
|
40
48
|
|
@@ -0,0 +1,100 @@
|
|
1
|
+
from .base import NSID
|
2
|
+
|
3
|
+
class BankAccount:
|
4
|
+
"""
|
5
|
+
Compte en banque d'une entité, individuelle ou collective.
|
6
|
+
|
7
|
+
## Attributs
|
8
|
+
- id: `NSID`\n
|
9
|
+
Identifiant du compte
|
10
|
+
- owner: `NSID`\n
|
11
|
+
Identifiant du titulaire du compte
|
12
|
+
- amount: `int`\n
|
13
|
+
Somme d'argent totale sur le compte
|
14
|
+
- frozen: `bool`\n
|
15
|
+
État gelé ou non du compte
|
16
|
+
- bank: `NSID`\n
|
17
|
+
Identifiant de la banque qui détient le compte
|
18
|
+
- income: `int`\n
|
19
|
+
Somme entrante sur le compte depuis la dernière réinitialisation (tous les ~ 28 jours)
|
20
|
+
"""
|
21
|
+
|
22
|
+
def __init__(self, id: NSID) -> None:
|
23
|
+
self.id: NSID = NSID(id)
|
24
|
+
self.owner: NSID = NSID(0)
|
25
|
+
self.amount: int = 0
|
26
|
+
self.frozen: bool = False
|
27
|
+
self.bank: NSID = NSID("6")
|
28
|
+
|
29
|
+
self.income: int = 0
|
30
|
+
|
31
|
+
class Item:
|
32
|
+
"""
|
33
|
+
Article d'inventaire qui peut circuler sur le serveur
|
34
|
+
|
35
|
+
## Attributs
|
36
|
+
- id: `NSID`\n
|
37
|
+
Identifiant de l'objet
|
38
|
+
- title: `str`\n
|
39
|
+
Nom de l'objet
|
40
|
+
- emoji: `str`\n
|
41
|
+
Emoji lié à l'objet
|
42
|
+
"""
|
43
|
+
|
44
|
+
def __init__(self, id: NSID) -> None:
|
45
|
+
self.id: NSID = NSID(id)
|
46
|
+
self.title: str = "Unknown Object"
|
47
|
+
self.emoji: str = ":light_bulb:"
|
48
|
+
|
49
|
+
class Inventory:
|
50
|
+
"""
|
51
|
+
Inventaire d'un membre
|
52
|
+
|
53
|
+
## Attributs
|
54
|
+
- owner_id: `NSID`\n
|
55
|
+
ID du propriétaire de l'inventaire
|
56
|
+
- objects: `dict[str, NSID]`\n
|
57
|
+
Collection d'objets et leur quantité
|
58
|
+
"""
|
59
|
+
|
60
|
+
def __init__(self, owner_id: NSID) -> None:
|
61
|
+
self.owner_id: NSID = NSID(owner_id)
|
62
|
+
self.objects: dict[str, NSID] = {}
|
63
|
+
|
64
|
+
def append(self, item: Item, quantity: int = 1):
|
65
|
+
if item.id in self.objects.keys():
|
66
|
+
self.objects[item.id] += quantity
|
67
|
+
else:
|
68
|
+
self.objects[item.id] = quantity
|
69
|
+
|
70
|
+
def throw(self, item: Item, quantity: int = 1):
|
71
|
+
if item.id in self.objects.keys():
|
72
|
+
if self.objects[item.id] > quantity:
|
73
|
+
self.objects[item.id] -= quantity
|
74
|
+
else:
|
75
|
+
self.objects[item.id] = 0
|
76
|
+
|
77
|
+
class Sale:
|
78
|
+
"""
|
79
|
+
Vente mettant en jeu un objet
|
80
|
+
|
81
|
+
## Attributs
|
82
|
+
- id: `NSID`\n
|
83
|
+
Identifiant de la vente
|
84
|
+
- item: `NSID`\n
|
85
|
+
Identifiant de l'objet mis en vente
|
86
|
+
- quantity: `int`\n
|
87
|
+
Quantité d'objets mis en vente
|
88
|
+
- price: `int`\n
|
89
|
+
Prix total du lot
|
90
|
+
- seller_id: `NSID`\n
|
91
|
+
Identifiant du vendeur
|
92
|
+
"""
|
93
|
+
|
94
|
+
def __init__(self, id: NSID, item: Item) -> None:
|
95
|
+
self.id: NSID = NSID(id)
|
96
|
+
self.item: NSID = NSID(item.id)
|
97
|
+
self.quantity: int = 1
|
98
|
+
|
99
|
+
self.price: int = 0
|
100
|
+
self.seller_id: NSID = NSID('0')
|
@@ -33,6 +33,18 @@ class PositionPermissions:
|
|
33
33
|
self.__setattr__(*perm)
|
34
34
|
|
35
35
|
class Position:
|
36
|
+
"""
|
37
|
+
Position légale d'une entité
|
38
|
+
|
39
|
+
## Attributs
|
40
|
+
- name: `str`\n
|
41
|
+
Titre de la position
|
42
|
+
- id: `str`\n
|
43
|
+
Identifiant de la position
|
44
|
+
- permissions: `.PositionPermissions`\n
|
45
|
+
Permissions accordées à l'utilisateur
|
46
|
+
"""
|
47
|
+
|
36
48
|
def __init__(self, id: str = 'inconnu') -> None:
|
37
49
|
self.name: str = "Inconnue"
|
38
50
|
self.id = id
|
@@ -42,7 +54,23 @@ class Position:
|
|
42
54
|
return self.id
|
43
55
|
|
44
56
|
class Entity:
|
45
|
-
|
57
|
+
"""
|
58
|
+
Classe de référence pour les entités
|
59
|
+
|
60
|
+
## Attributs
|
61
|
+
- id: `NSID`\n
|
62
|
+
Identifiant de l'entité
|
63
|
+
- name: `str`\n
|
64
|
+
Nom d'usage de l'entité
|
65
|
+
- registerDate: `int`\n
|
66
|
+
Date d'enregistrement de l'entité
|
67
|
+
- position: `.Position`\n
|
68
|
+
Position légale de l'entité
|
69
|
+
- additional: `dict`\n
|
70
|
+
Infos supplémentaires exploitables par les bots
|
71
|
+
"""
|
72
|
+
|
73
|
+
def __init__(self, id: NSID) -> None:
|
46
74
|
self.id: NSID = NSID(id) # ID hexadécimal de l'entité (ou nom dans le cas de l'entreprise)
|
47
75
|
self.name: str = "Entité Inconnue"
|
48
76
|
self.registerDate: int = 0
|
@@ -66,7 +94,22 @@ class Entity:
|
|
66
94
|
del self.additional[key]
|
67
95
|
|
68
96
|
class User(Entity):
|
69
|
-
|
97
|
+
"""
|
98
|
+
Entité individuelle
|
99
|
+
|
100
|
+
## Attributs
|
101
|
+
- Tous les attributs de la classe `.Entity`
|
102
|
+
- xp: `int`\n
|
103
|
+
Points d'expérience de l'entité
|
104
|
+
- boosts: `dict[str, int]`\n
|
105
|
+
Ensemble des boosts dont bénéficie l'entité
|
106
|
+
- permissions: `.PositionPermissions`\n
|
107
|
+
Fusion des permissions offertes par la position et les groupes
|
108
|
+
- votes: `list[NSID]`\n
|
109
|
+
Liste des votes auxquels a participé l'entité
|
110
|
+
"""
|
111
|
+
|
112
|
+
def __init__(self, id: NSID) -> None:
|
70
113
|
super().__init__(NSID(id))
|
71
114
|
|
72
115
|
self.xp: int = 0
|
@@ -74,7 +117,7 @@ class User(Entity):
|
|
74
117
|
self.permissions: PositionPermissions = PositionPermissions() # Elles seront définies en récupérant les permissions de sa position
|
75
118
|
self.votes: list[str] = []
|
76
119
|
|
77
|
-
def add_vote(self, id:
|
120
|
+
def add_vote(self, id: NSID):
|
78
121
|
self.votes.append(NSID(id))
|
79
122
|
|
80
123
|
def get_level(self) -> None:
|
@@ -111,7 +154,16 @@ class MemberPermissions:
|
|
111
154
|
self.__setattr__(*perm)
|
112
155
|
|
113
156
|
class GroupMember(User):
|
114
|
-
|
157
|
+
"""
|
158
|
+
Membre au sein d'une entité collective
|
159
|
+
|
160
|
+
## Attributs
|
161
|
+
- Tous les attributs de la classe `.User`
|
162
|
+
- permission_level: `int`\n
|
163
|
+
Niveau d'accréditation du membre (0 = salarié, 4 = administrateur)
|
164
|
+
"""
|
165
|
+
|
166
|
+
def __init__(self, id: NSID) -> None:
|
115
167
|
super().__init__(id)
|
116
168
|
|
117
169
|
self.permission_level: int = 0
|
@@ -133,19 +185,65 @@ class GroupMember(User):
|
|
133
185
|
|
134
186
|
return p
|
135
187
|
|
188
|
+
class Share:
|
189
|
+
"""
|
190
|
+
Action d'une entreprise
|
191
|
+
|
192
|
+
## Attributs
|
193
|
+
- owner: `NSID`\n
|
194
|
+
Identifiant du titulaire de l'action
|
195
|
+
- price: `int`\n
|
196
|
+
Prix de l'action
|
197
|
+
"""
|
198
|
+
|
199
|
+
def __getstate__(self) -> dict:
|
200
|
+
return {
|
201
|
+
"owner": self.owner,
|
202
|
+
"price": self.price
|
203
|
+
}
|
204
|
+
|
205
|
+
def __setstate__(self, state: dict):
|
206
|
+
self.owner: NSID = state['owner']
|
207
|
+
self.price: int = state['price']
|
208
|
+
|
209
|
+
def __init__(self, owner: NSID = NSID(0x0), price: int = 10):
|
210
|
+
self.owner: NSID = owner
|
211
|
+
self.price: int = price
|
212
|
+
|
213
|
+
def assign_owner(self, owner: NSID):
|
214
|
+
self.owner = owner
|
215
|
+
|
216
|
+
def set_price(self, price: int):
|
217
|
+
self.price = price
|
218
|
+
|
136
219
|
class Organization(Entity):
|
137
|
-
|
220
|
+
"""
|
221
|
+
Entité collective
|
222
|
+
|
223
|
+
## Attributs
|
224
|
+
- Tous les attributs de la classe `.Entity`
|
225
|
+
- owner: `.Entity`\n
|
226
|
+
Utilisateur ou entreprise propriétaire de l'entité collective
|
227
|
+
- avatar: `bytes`\n
|
228
|
+
Avatar/logo de l'entité collective
|
229
|
+
- certifications: `dict[str, int]`\n
|
230
|
+
Liste des certifications et de leur date d'ajout
|
231
|
+
- members: `list[.GroupMember]`\n
|
232
|
+
Liste des membres de l'entreprise
|
233
|
+
- parts: `list[.Share]`\n
|
234
|
+
Liste des actions émises par l'entreprise
|
235
|
+
"""
|
236
|
+
|
237
|
+
def __init__(self, id: NSID) -> None:
|
138
238
|
super().__init__(NSID(id))
|
139
239
|
|
140
|
-
self.owner: Entity
|
240
|
+
self.owner: Entity = User(NSID(0x0))
|
141
241
|
self.avatar: bytes = utils.open_asset('default_avatar.png')
|
142
242
|
|
143
243
|
self.certifications: dict = {}
|
144
244
|
self.members: list[GroupMember] = []
|
145
245
|
|
146
|
-
self.parts:
|
147
|
-
self.id: 1
|
148
|
-
}
|
246
|
+
self.parts: list[Share] = 50 * [ Share(self.owner.id, 0) ]
|
149
247
|
|
150
248
|
def add_certification(self, certification: str) -> None:
|
151
249
|
self.certifications[certification] = round(time.time())
|
@@ -176,5 +274,26 @@ class Organization(Entity):
|
|
176
274
|
def set_owner(self, member: User) -> None:
|
177
275
|
self.owner = member
|
178
276
|
|
179
|
-
def
|
180
|
-
return [ member.
|
277
|
+
def get_members_by_attr(self, attribute: str = "id") -> list[str]:
|
278
|
+
return [ member.__getattribute__(attribute) for member in self.members ]
|
279
|
+
|
280
|
+
def get_shares(self, include_worth: bool = False) -> dict[str, int] | dict[str, dict[str, int]]:
|
281
|
+
shares = {}
|
282
|
+
|
283
|
+
for share in self.parts:
|
284
|
+
if include_worth:
|
285
|
+
if share.owner in shares.keys():
|
286
|
+
shares[share.owner]['count'] += 1
|
287
|
+
shares[share.owner]['worth'] += share.price
|
288
|
+
else:
|
289
|
+
shares[share.owner] = {
|
290
|
+
'count': 1,
|
291
|
+
'worth': share.price
|
292
|
+
}
|
293
|
+
else:
|
294
|
+
if share.owner in shares.keys():
|
295
|
+
shares[share.owner] += 1
|
296
|
+
else:
|
297
|
+
shares[share.owner] = 1
|
298
|
+
|
299
|
+
return shares
|
@@ -3,13 +3,43 @@ from nsarchive.cls.base import NSID
|
|
3
3
|
# Votes
|
4
4
|
|
5
5
|
class VoteOption:
|
6
|
+
"""
|
7
|
+
Option disponible lors d'un vote
|
8
|
+
|
9
|
+
## Attributs
|
10
|
+
- id: `str`\n
|
11
|
+
Identifiant de l'option
|
12
|
+
- title: `str`\n
|
13
|
+
Label de l'option
|
14
|
+
- count: `int`\n
|
15
|
+
Nombre de sympathisants pour cette option
|
16
|
+
"""
|
17
|
+
|
6
18
|
def __init__(self, id: str, title: str = None, count: int = 0):
|
7
19
|
self.id = id
|
8
20
|
self.title = title if title else id
|
9
21
|
self.count = count
|
10
22
|
|
11
23
|
class Vote:
|
12
|
-
|
24
|
+
"""
|
25
|
+
Classe de référence pour les différents votes du serveur
|
26
|
+
|
27
|
+
## Attributs
|
28
|
+
- id: `NSID`\n
|
29
|
+
Identifiant du vote
|
30
|
+
- title: `str`\n
|
31
|
+
Titre du vote
|
32
|
+
- choices: list[.VoteOption]\n
|
33
|
+
Liste des choix disponibles
|
34
|
+
- author: `NSID`\n
|
35
|
+
Identifiant de l'auteur du vote
|
36
|
+
- startDate: `int`\n
|
37
|
+
Date de début du vote
|
38
|
+
- endDate: `int`\n
|
39
|
+
Date limite pour voter
|
40
|
+
"""
|
41
|
+
|
42
|
+
def __init__(self, id: NSID, title: str) -> None:
|
13
43
|
self.id: NSID = NSID(id)
|
14
44
|
self.title: str = title
|
15
45
|
self.choices: list[VoteOption] = []
|
@@ -31,6 +61,10 @@ class Vote:
|
|
31
61
|
return sorted_list
|
32
62
|
|
33
63
|
class Referendum(Vote):
|
64
|
+
"""
|
65
|
+
Vote à trois positions
|
66
|
+
"""
|
67
|
+
|
34
68
|
def __init__(self, id: NSID, title: str) -> None:
|
35
69
|
super().__init__(id, title)
|
36
70
|
|
@@ -41,6 +75,10 @@ class Referendum(Vote):
|
|
41
75
|
]
|
42
76
|
|
43
77
|
class Lawsuit(Vote):
|
78
|
+
"""
|
79
|
+
Vote à trois positions pour un procès
|
80
|
+
"""
|
81
|
+
|
44
82
|
def __init__(self, id: NSID, title: str) -> None:
|
45
83
|
super().__init__(id, title)
|
46
84
|
|
@@ -54,7 +92,7 @@ class Lawsuit(Vote):
|
|
54
92
|
# Institutions (defs)
|
55
93
|
|
56
94
|
class Official:
|
57
|
-
def __init__(self, id:
|
95
|
+
def __init__(self, id: NSID) -> None:
|
58
96
|
self.id: NSID = NSID(id)
|
59
97
|
|
60
98
|
self.mandates: int = {
|
@@ -18,12 +18,12 @@ class EconomyInstance(Instance):
|
|
18
18
|
---- COMPTES EN BANQUE ----
|
19
19
|
"""
|
20
20
|
|
21
|
-
def get_account(self, id:
|
21
|
+
def get_account(self, id: NSID) -> BankAccount:
|
22
22
|
"""
|
23
23
|
Récupère les informations d'un compte bancaire.
|
24
24
|
|
25
25
|
## Paramètres
|
26
|
-
id: `
|
26
|
+
id: `NSID`\n
|
27
27
|
ID du compte.
|
28
28
|
|
29
29
|
## Renvoie
|
@@ -46,7 +46,13 @@ class EconomyInstance(Instance):
|
|
46
46
|
return account
|
47
47
|
|
48
48
|
def save_account(self, account: BankAccount):
|
49
|
-
"""
|
49
|
+
"""
|
50
|
+
Sauvegarde un compte bancaire dans la base de données.
|
51
|
+
|
52
|
+
## Paramètres
|
53
|
+
- account: `.BankAccount`\n
|
54
|
+
Compte à sauvegarder
|
55
|
+
"""
|
50
56
|
|
51
57
|
_data = {
|
52
58
|
'id': NSID(account.id),
|
@@ -60,7 +66,13 @@ class EconomyInstance(Instance):
|
|
60
66
|
self._put_in_db('accounts', _data)
|
61
67
|
|
62
68
|
def freeze_account(self, account: BankAccount):
|
63
|
-
"""
|
69
|
+
"""
|
70
|
+
Gèle un compte bancaire pour empêcher toute transaction.
|
71
|
+
|
72
|
+
## Paramètres
|
73
|
+
- account: `.BankAccount`\n
|
74
|
+
Compte à geler
|
75
|
+
"""
|
64
76
|
|
65
77
|
account.id = NSID(account.id)
|
66
78
|
account.frozen = True
|
@@ -71,7 +83,7 @@ class EconomyInstance(Instance):
|
|
71
83
|
---- OBJETS & VENTES ----
|
72
84
|
"""
|
73
85
|
|
74
|
-
def save_item(self, item: Item)
|
86
|
+
def save_item(self, item: Item):
|
75
87
|
"""
|
76
88
|
Sauvegarde des infos à propos d'un item.
|
77
89
|
|
@@ -107,13 +119,13 @@ class EconomyInstance(Instance):
|
|
107
119
|
|
108
120
|
return item
|
109
121
|
|
110
|
-
def delete_item(self, item: Item)
|
122
|
+
def delete_item(self, item: Item):
|
111
123
|
"""
|
112
124
|
Annule le référencement d'un item.
|
113
125
|
|
114
126
|
## Paramètres
|
115
127
|
item: `.Item`\n
|
116
|
-
Item à
|
128
|
+
Item à supprimer
|
117
129
|
"""
|
118
130
|
|
119
131
|
self._delete_by_ID('items', item.id)
|
@@ -127,7 +139,7 @@ class EconomyInstance(Instance):
|
|
127
139
|
ID de la vente.
|
128
140
|
|
129
141
|
## Renvoie
|
130
|
-
- `.Sale | None
|
142
|
+
- `.Sale | None`: Le résultat de la vente
|
131
143
|
"""
|
132
144
|
|
133
145
|
id = NSID(id)
|
@@ -136,7 +148,7 @@ class EconomyInstance(Instance):
|
|
136
148
|
|
137
149
|
if _data is None:
|
138
150
|
return None
|
139
|
-
|
151
|
+
|
140
152
|
item = self.get_item(_data['id'])
|
141
153
|
|
142
154
|
sale = Sale(NSID(id), Item(_data['id']) if item is None else item)
|
@@ -144,7 +156,7 @@ class EconomyInstance(Instance):
|
|
144
156
|
|
145
157
|
return sale
|
146
158
|
|
147
|
-
def sell_item(self, item: Item, quantity: int, price: int, seller: NSID)
|
159
|
+
def sell_item(self, item: Item, quantity: int, price: int, seller: NSID):
|
148
160
|
"""
|
149
161
|
Vend un item sur le marché.
|
150
162
|
|
@@ -187,7 +199,7 @@ class EconomyInstance(Instance):
|
|
187
199
|
ID du propriétaire de l'inventaire
|
188
200
|
|
189
201
|
## Retourne
|
190
|
-
- `.Inventory | None
|
202
|
+
- `.Inventory | None`: L'inventaire s'il a été trouvé
|
191
203
|
"""
|
192
204
|
|
193
205
|
_data = self._get_by_ID('inventories', id)
|
@@ -204,7 +216,7 @@ class EconomyInstance(Instance):
|
|
204
216
|
|
205
217
|
return inventory
|
206
218
|
|
207
|
-
def save_inventory(self, inventory: Inventory)
|
219
|
+
def save_inventory(self, inventory: Inventory):
|
208
220
|
"""
|
209
221
|
Sauvegarder un inventaire
|
210
222
|
|
@@ -217,7 +229,7 @@ class EconomyInstance(Instance):
|
|
217
229
|
|
218
230
|
self._put_in_db('inventories', _data)
|
219
231
|
|
220
|
-
def delete_inventory(self, inventory: Inventory)
|
232
|
+
def delete_inventory(self, inventory: Inventory):
|
221
233
|
"""
|
222
234
|
Supprime un inventaire
|
223
235
|
|
@@ -233,7 +245,13 @@ class EconomyInstance(Instance):
|
|
233
245
|
"""
|
234
246
|
|
235
247
|
def _add_archive(self, archive: Archive):
|
236
|
-
"""
|
248
|
+
"""
|
249
|
+
Ajoute une archive d'une transaction ou d'une vente dans la base de données.
|
250
|
+
|
251
|
+
## Paramètres
|
252
|
+
- archive: `.Archive`\n
|
253
|
+
Archive à ajouter
|
254
|
+
"""
|
237
255
|
|
238
256
|
archive.id = NSID(archive.id)
|
239
257
|
archive.author = NSID(archive.author)
|
@@ -248,12 +266,12 @@ class EconomyInstance(Instance):
|
|
248
266
|
|
249
267
|
self._put_in_db('archives', _data)
|
250
268
|
|
251
|
-
def _get_archive(self, id:
|
269
|
+
def _get_archive(self, id: NSID) -> Archive | Transaction:
|
252
270
|
"""
|
253
271
|
Récupère une archive spécifique.
|
254
272
|
|
255
273
|
## Paramètres
|
256
|
-
id: `
|
274
|
+
id: `NSID`\n
|
257
275
|
ID de l'archive.
|
258
276
|
|
259
277
|
## Renvoie
|
@@ -25,7 +25,7 @@ class EntityInstance(Instance):
|
|
25
25
|
---- ENTITÉS ----
|
26
26
|
"""
|
27
27
|
|
28
|
-
def get_entity(self, id:
|
28
|
+
def get_entity(self, id: NSID) -> User | Organization | Entity:
|
29
29
|
"""
|
30
30
|
Fonction permettant de récupérer le profil public d'une entité.\n
|
31
31
|
|
@@ -83,8 +83,12 @@ class EntityInstance(Instance):
|
|
83
83
|
|
84
84
|
entity.append(member)
|
85
85
|
|
86
|
+
entity.parts = []
|
87
|
+
|
88
|
+
for owner, attrs in _data['parts'].items():
|
89
|
+
entity.parts.extend(attrs['count'] * [ Share(NSID(owner), attrs['worth'] // attrs['count']) ])
|
90
|
+
|
86
91
|
entity.certifications = _data['certifications']
|
87
|
-
entity.parts = _data['parts']
|
88
92
|
entity.avatar = self._download_from_storage('organizations', f"avatars/{entity.id}")
|
89
93
|
else:
|
90
94
|
entity = Entity(id)
|
@@ -101,12 +105,12 @@ class EntityInstance(Instance):
|
|
101
105
|
|
102
106
|
return entity
|
103
107
|
|
104
|
-
def save_entity(self, entity: Entity)
|
108
|
+
def save_entity(self, entity: Entity):
|
105
109
|
"""
|
106
110
|
Fonction permettant de créer ou modifier une entité.
|
107
111
|
|
108
112
|
## Paramètres
|
109
|
-
entity: `.Entity
|
113
|
+
entity: `.Entity`\n
|
110
114
|
L'entité à sauvegarder
|
111
115
|
"""
|
112
116
|
|
@@ -130,6 +134,7 @@ class EntityInstance(Instance):
|
|
130
134
|
_data['owner_id'] = NSID(entity.owner.id) if entity.owner else NSID("0")
|
131
135
|
_data['members'] = []
|
132
136
|
_data['certifications'] = entity.certifications
|
137
|
+
_data['parts'] = entity.get_shares(True)
|
133
138
|
|
134
139
|
for member in entity.members:
|
135
140
|
_member = {
|
@@ -139,7 +144,7 @@ class EntityInstance(Instance):
|
|
139
144
|
|
140
145
|
_data['members'] += [_member]
|
141
146
|
|
142
|
-
self._upload_to_storage('organizations', entity.avatar, f'/avatars/{entity.id}')
|
147
|
+
self._upload_to_storage('organizations', entity.avatar, f'/avatars/{entity.id}', overwrite = True)
|
143
148
|
elif type(entity) == User:
|
144
149
|
_data['xp'] = entity.xp
|
145
150
|
_data['boosts'] = entity.boosts
|
@@ -147,12 +152,12 @@ class EntityInstance(Instance):
|
|
147
152
|
|
148
153
|
self._put_in_db('individuals' if isinstance(entity, User) else 'organizations', _data)
|
149
154
|
|
150
|
-
def delete_entity(self, entity: Entity)
|
155
|
+
def delete_entity(self, entity: Entity):
|
151
156
|
"""
|
152
157
|
Fonction permettant de supprimer le profil d'une entité
|
153
158
|
|
154
159
|
## Paramètres
|
155
|
-
entity: `.Entity
|
160
|
+
entity: `.Entity`\n
|
156
161
|
L'entité à supprimer
|
157
162
|
"""
|
158
163
|
|
@@ -163,11 +168,11 @@ class EntityInstance(Instance):
|
|
163
168
|
Récupère une liste d'entités en fonction d'une requête.
|
164
169
|
|
165
170
|
## Paramètres
|
166
|
-
query: `dict
|
171
|
+
query: `dict`\n
|
167
172
|
La requête pour filtrer les entités.
|
168
173
|
|
169
174
|
## Renvoie
|
170
|
-
- `list[Entity | User | Organization]`
|
175
|
+
- `list[.Entity | .User | .Organization]`
|
171
176
|
"""
|
172
177
|
|
173
178
|
if "_type" in query.keys():
|
@@ -187,43 +192,41 @@ class EntityInstance(Instance):
|
|
187
192
|
|
188
193
|
return [ self.get_entity(NSID(entity['id'])) for entity in _res if entity is not None ]
|
189
194
|
|
190
|
-
def get_entity_groups(self, id:
|
195
|
+
def get_entity_groups(self, id: NSID) -> list[Organization]:
|
191
196
|
"""
|
192
197
|
Récupère les groupes auxquels appartient une entité.
|
193
198
|
|
194
199
|
## Paramètres
|
195
|
-
id: `
|
200
|
+
id: `NSID`\n
|
196
201
|
ID de l'entité.
|
197
202
|
|
198
203
|
## Renvoie
|
199
|
-
- `list[Organization]`
|
204
|
+
- `list[.Organization]`
|
200
205
|
"""
|
201
206
|
|
202
207
|
id = NSID(id)
|
203
|
-
|
208
|
+
_groups = self.fetch_entities(_type = 'organization')
|
209
|
+
groups = []
|
204
210
|
|
205
|
-
for group in
|
211
|
+
for group in _groups:
|
206
212
|
if group is None:
|
207
|
-
groups.remove(group)
|
208
213
|
continue
|
209
214
|
|
210
215
|
if group.owner.id == id:
|
211
|
-
|
216
|
+
groups.append(group)
|
212
217
|
|
213
218
|
for member in group.members:
|
214
219
|
if member.id == id:
|
215
|
-
|
216
|
-
else:
|
217
|
-
groups.remove(group)
|
220
|
+
groups.append(group)
|
218
221
|
|
219
|
-
return [ group for group in groups
|
222
|
+
return [ group for group in groups ]
|
220
223
|
|
221
224
|
def get_position(self, id: str) -> Position:
|
222
225
|
"""
|
223
226
|
Récupère une position légale (métier, domaine professionnel).
|
224
227
|
|
225
228
|
## Paramètres
|
226
|
-
id: `str
|
229
|
+
id: `str`\n
|
227
230
|
ID de la position (SENSIBLE À LA CASSE !)
|
228
231
|
|
229
232
|
## Renvoie
|
@@ -245,9 +248,13 @@ class EntityInstance(Instance):
|
|
245
248
|
---- ARCHIVES --
|
246
249
|
"""
|
247
250
|
|
248
|
-
def _add_archive(self, archive: Archive)
|
251
|
+
def _add_archive(self, archive: Archive):
|
249
252
|
"""
|
250
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
|
251
258
|
"""
|
252
259
|
|
253
260
|
archive.id = NSID(archive.id)
|
@@ -265,12 +272,12 @@ class EntityInstance(Instance):
|
|
265
272
|
|
266
273
|
self._put_in_db('archives', _data)
|
267
274
|
|
268
|
-
def _get_archive(self, id:
|
275
|
+
def _get_archive(self, id: NSID) -> Archive | Sanction:
|
269
276
|
"""
|
270
277
|
Récupère une archive spécifique.
|
271
278
|
|
272
279
|
## Paramètres
|
273
|
-
id: `
|
280
|
+
id: `NSID`\n
|
274
281
|
ID de l'archive.
|
275
282
|
|
276
283
|
## Renvoie
|
@@ -302,7 +309,7 @@ class EntityInstance(Instance):
|
|
302
309
|
Récupère une liste d'archives correspondant à la requête.
|
303
310
|
|
304
311
|
## Paramètres
|
305
|
-
query: `dict
|
312
|
+
query: `dict`\n
|
306
313
|
Requête pour filtrer les archives.
|
307
314
|
|
308
315
|
## Renvoie
|
@@ -26,12 +26,12 @@ class RepublicInstance(Instance):
|
|
26
26
|
---- VOTES & REFERENDUMS ----
|
27
27
|
"""
|
28
28
|
|
29
|
-
def get_vote(self, id:
|
29
|
+
def get_vote(self, id: NSID) -> Vote | Referendum | Lawsuit:
|
30
30
|
"""
|
31
31
|
Récupère un vote spécifique.
|
32
32
|
|
33
33
|
## Paramètres
|
34
|
-
id: `
|
34
|
+
id: `NSID`\n
|
35
35
|
ID du vote.
|
36
36
|
|
37
37
|
## Renvoie
|
@@ -72,8 +72,14 @@ class RepublicInstance(Instance):
|
|
72
72
|
|
73
73
|
return vote
|
74
74
|
|
75
|
-
def save_vote(self, vote: Vote | Referendum | Lawsuit)
|
76
|
-
"""
|
75
|
+
def save_vote(self, vote: Vote | Referendum | Lawsuit):
|
76
|
+
"""
|
77
|
+
Sauvegarde un vote dans la base de données.
|
78
|
+
|
79
|
+
## Paramètres
|
80
|
+
- vote: `.Vote`\n
|
81
|
+
Vote à sauvegarder
|
82
|
+
"""
|
77
83
|
|
78
84
|
vote.id = NSID(vote.id)
|
79
85
|
|
@@ -102,12 +108,12 @@ class RepublicInstance(Instance):
|
|
102
108
|
---- INSTITUTION & MANDAT ----
|
103
109
|
"""
|
104
110
|
|
105
|
-
def get_official(self, id:
|
111
|
+
def get_official(self, id: NSID, current_mandate: bool = True) -> Official:
|
106
112
|
"""
|
107
113
|
Récupère les informations d'un fonctionnaire (mandats, contributions).
|
108
114
|
|
109
115
|
## Paramètres
|
110
|
-
id: `
|
116
|
+
id: `NSID`\n
|
111
117
|
ID du fonctionnaire.
|
112
118
|
current_mandate: `bool`\n
|
113
119
|
Indique si l'on doit récupérer le mandat actuel ou les anciens mandats.
|
@@ -190,7 +196,7 @@ class RepublicInstance(Instance):
|
|
190
196
|
Celle-ci met à jour: Le gouvernement (président, ministres), les différents députés et leur président, les différents juges, les différents policiers.\n
|
191
197
|
|
192
198
|
## Paramètres
|
193
|
-
institutions: `.
|
199
|
+
institutions: `.State`\n
|
194
200
|
Le nouvel état des institutions, à sauvegarder.
|
195
201
|
"""
|
196
202
|
|
@@ -211,9 +217,15 @@ class RepublicInstance(Instance):
|
|
211
217
|
self._put_in_db('functions', { 'id': 'MIN_AUD', 'users': [ institutions.government.press_minister.id ] })
|
212
218
|
self._put_in_db('functions', { 'id': 'MIN_OUT', 'users': [ institutions.government.outer_minister.id ] })
|
213
219
|
|
214
|
-
def new_mandate(self, institutions: State, weeks: int = 4)
|
220
|
+
def new_mandate(self, institutions: State, weeks: int = 4):
|
215
221
|
"""
|
216
222
|
Fonction qui amène à supprimer toutes les archives du mandat précédent
|
223
|
+
|
224
|
+
## Paramètres
|
225
|
+
- institutions: `.State`\n
|
226
|
+
Nouvel État à sauvegarder
|
227
|
+
- weeks: `int`\n
|
228
|
+
Nombre de semaines du mandat
|
217
229
|
"""
|
218
230
|
|
219
231
|
for item in self.fetch('mandate'):
|
@@ -226,8 +238,14 @@ class RepublicInstance(Instance):
|
|
226
238
|
---- ARCHIVES ----
|
227
239
|
"""
|
228
240
|
|
229
|
-
def _add_archive(self, archive: Archive)
|
230
|
-
"""
|
241
|
+
def _add_archive(self, archive: Archive):
|
242
|
+
"""
|
243
|
+
Ajoute une archive d'une action (élection, promotion, ou rétrogradation) dans la base de données.
|
244
|
+
|
245
|
+
## Paramètres
|
246
|
+
- archive: `.Archive`\n
|
247
|
+
Archive à ajouter
|
248
|
+
"""
|
231
249
|
|
232
250
|
archive.id = NSID(archive.id)
|
233
251
|
_data = archive.__dict__.copy()
|
@@ -244,12 +262,12 @@ class RepublicInstance(Instance):
|
|
244
262
|
self._put_in_db('archives', _data)
|
245
263
|
self._put_in_db('mandate', _data) # Ajouter les archives à celle du mandat actuel
|
246
264
|
|
247
|
-
def _get_archive(self, id:
|
265
|
+
def _get_archive(self, id: NSID) -> Archive | Election | Promotion | Demotion:
|
248
266
|
"""
|
249
267
|
Récupère une archive spécifique.
|
250
268
|
|
251
269
|
## Paramètres
|
252
|
-
id: `
|
270
|
+
id: `NSID`\n
|
253
271
|
ID de l'archive.
|
254
272
|
|
255
273
|
## Renvoie
|
@@ -283,7 +301,7 @@ class RepublicInstance(Instance):
|
|
283
301
|
Récupère une liste d'archives correspondant à la requête.
|
284
302
|
|
285
303
|
## Paramètres
|
286
|
-
query: `dict
|
304
|
+
query: `dict`\n
|
287
305
|
Requête pour filtrer les archives.
|
288
306
|
|
289
307
|
## Renvoie
|
nsarchive-2.0.0b1/PKG-INFO
DELETED
@@ -1,177 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: nsarchive
|
3
|
-
Version: 2.0.0b1
|
4
|
-
Summary: API-wrapper pour récupérer des données liées à Nation
|
5
|
-
License: GPL-3.0
|
6
|
-
Author: happex
|
7
|
-
Author-email: 110610727+okayhappex@users.noreply.github.com
|
8
|
-
Requires-Python: >=3.10,<4.0
|
9
|
-
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
14
|
-
Requires-Dist: pillow (>=10.4,<11.0)
|
15
|
-
Requires-Dist: supabase (>=2.9.1,<3.0.0)
|
16
|
-
Description-Content-Type: text/markdown
|
17
|
-
|
18
|
-
# nsarchive
|
19
|
-
|
20
|
-
`nsarchive` est un module Python pour la gestion des entités (utilisateurs et organisations) à l'aide de la base de données Deta. Ce module permet de créer, récupérer, sauvegarder et gérer des entités et leurs attributs spécifiques.
|
21
|
-
|
22
|
-
## Pré-requis
|
23
|
-
|
24
|
-
Listes des choses à avoir afin de pouvoir utiliser le module correctement:
|
25
|
-
- [Python 3.10](https://www.python.org/downloads/) ou supérieur
|
26
|
-
- Un token [Deta](https://deta.space), donné par un administrateur ou pour votre collection personnelle
|
27
|
-
- Un bon capuccino, pour commencer la programmation en bons termes
|
28
|
-
|
29
|
-
> **Note:** Il vous faudra un token différent pour accéder aux différentes parties de la base de données. Vos tokens n'expireront pas à moins que l'ordre en aura été donné
|
30
|
-
|
31
|
-
## Installation
|
32
|
-
|
33
|
-
Vous pouvez installer ce module via pip :
|
34
|
-
|
35
|
-
```sh
|
36
|
-
pip install nsarchive
|
37
|
-
```
|
38
|
-
|
39
|
-
## Utilisation
|
40
|
-
|
41
|
-
### Importation et Initialisation
|
42
|
-
|
43
|
-
Pour utiliser `nsarchive`, commencez par importer le module et initialiser une instance d'`EntityInstance` avec votre token Deta.
|
44
|
-
|
45
|
-
```python
|
46
|
-
from nsarchive import EntityInstance
|
47
|
-
|
48
|
-
# Remplacez 'your_deta_token' par votre véritable token Deta
|
49
|
-
entity_instance = EntityInstance(token = 'your_deta_token')
|
50
|
-
```
|
51
|
-
|
52
|
-
### Récupérer une Entité
|
53
|
-
|
54
|
-
Vous pouvez récupérer une entité (Utilisateur ou Organisation) à l'aide de son ID.
|
55
|
-
|
56
|
-
```python
|
57
|
-
entity = entity_instance.get_entity(id = 'entity_id')
|
58
|
-
print(entity.name)
|
59
|
-
```
|
60
|
-
|
61
|
-
**ATTENTION: Les entités sont identifiées sous une forme hexadécimale. Pour les avoir, vous devez convertir leur ID Discord en hexadécimale puis enlever le préfixe `0x`.**
|
62
|
-
|
63
|
-
Pour les organisations, l'ID Discord correspondra à la formule suivante: `ID fondateur // 100000`.
|
64
|
-
|
65
|
-
N'oubliez pas de toujours utiliser un `str` dans les ID pour interagir avec la base de données.
|
66
|
-
|
67
|
-
### Sauvegarder une Entité
|
68
|
-
|
69
|
-
Après avoir modifié une entité, vous pouvez la sauvegarder dans la base de données.
|
70
|
-
|
71
|
-
```python
|
72
|
-
entity.rename("Nouveau Nom")
|
73
|
-
entity_instance.save_entity(entity)
|
74
|
-
```
|
75
|
-
|
76
|
-
### Rechercher des Entités
|
77
|
-
|
78
|
-
Vous pouvez rechercher des entités avec des critères spécifiques.
|
79
|
-
|
80
|
-
```python
|
81
|
-
entities = entity_instance.fetch_entity(query = {'name': 'Alice'})
|
82
|
-
for entity in entities:
|
83
|
-
print(entity['name'])
|
84
|
-
```
|
85
|
-
|
86
|
-
### Gérer les Organisations
|
87
|
-
|
88
|
-
Les organisations peuvent avoir des membres et des certifications. Voici comment ajouter un membre ou une certification.
|
89
|
-
|
90
|
-
```python
|
91
|
-
organization = entity_instance.get_entity(id = 'org_id')
|
92
|
-
user = entity_instance.get_entity(id = 'user_id')
|
93
|
-
|
94
|
-
# Ajouter un membre
|
95
|
-
organization.add_member(user)
|
96
|
-
entity_instance.save_entity(organization)
|
97
|
-
|
98
|
-
# Ajouter une certification
|
99
|
-
organization.add_certification('Certification Example')
|
100
|
-
entity_instance.save_entity(organization)
|
101
|
-
```
|
102
|
-
|
103
|
-
Les certifications pourront être utilisées pour vérifier l'officialité d'une organisation, mais également pour déterminer si l'on peut accorder (ou non) des permissions à ses membres.
|
104
|
-
|
105
|
-
### Exemples de Classes
|
106
|
-
|
107
|
-
#### `Entity`
|
108
|
-
|
109
|
-
Classe parente des classes `User` et `Organization`, elle est utilisée lorsque le module ne peut pas déterminer l'appartenance d'une identité à l'une de ces deux classes ou à l'autre.
|
110
|
-
|
111
|
-
```python
|
112
|
-
from nsarchive.cls.entities import Entity
|
113
|
-
|
114
|
-
entity = Entity(id='entity_id')
|
115
|
-
entity.rename('New Name')
|
116
|
-
entity.add_xp(100)
|
117
|
-
print(entity.get_level())
|
118
|
-
```
|
119
|
-
|
120
|
-
#### `User`
|
121
|
-
|
122
|
-
```python
|
123
|
-
from nsarchive.cls.entities import User
|
124
|
-
|
125
|
-
user = User(id = 'user_id')
|
126
|
-
user.edit_boost(name = 'admin', multiplier = 5) # Négliger le paramètre <multiplier> ou le fixer à un nombre négatif reviendrait à supprimer le boost.
|
127
|
-
print(user.boosts)
|
128
|
-
```
|
129
|
-
|
130
|
-
> **Note:** Lorsqu'on ajoute de l'expérience à un utilisateur via la méthode `add_xp`, le nombre de points ajoutés est automatiquement multiplié par le bonus le plus important dont l'utilisateur bénéficie.
|
131
|
-
|
132
|
-
#### `Organization`
|
133
|
-
|
134
|
-
```python
|
135
|
-
from nsarchive.cls.entities import Organization
|
136
|
-
|
137
|
-
organization = Organization(id = 'org_id')
|
138
|
-
organization.set_owner(user)
|
139
|
-
organization.add_member(user)
|
140
|
-
print(organization.members)
|
141
|
-
```
|
142
|
-
|
143
|
-
> **Note:** Les attributs `owner` et `members` sont indépendants. L'owner peut être n'importe quelle personne faisant ou non partie des `members`.
|
144
|
-
|
145
|
-
## Gestion des Exceptions
|
146
|
-
|
147
|
-
`nsarchive` fournit des exceptions spécifiques pour gérer les erreurs courantes.
|
148
|
-
|
149
|
-
#### `NameTooLongError`
|
150
|
-
|
151
|
-
Lancé lorsque le nom d'une entité dépasse la longueur maximale autorisée (32 caractères).
|
152
|
-
|
153
|
-
```python
|
154
|
-
from nsarchive.cls.exceptions import NameTooLongError
|
155
|
-
|
156
|
-
try:
|
157
|
-
entity.rename('Ce nom est long, voire même très long, je dirais même extrêmement long')
|
158
|
-
except NameTooLongError as e:
|
159
|
-
print(e)
|
160
|
-
```
|
161
|
-
|
162
|
-
#### `EntityTypeError`
|
163
|
-
|
164
|
-
Lancé lorsque le type d'entité est incorrect. Vous ne devriez normalement pas la rencontrer en utilisant le module, mais elle pourrait vous être utile.
|
165
|
-
|
166
|
-
```python
|
167
|
-
from nsarchive.cls.exceptions import EntityTypeError
|
168
|
-
|
169
|
-
try:
|
170
|
-
# Code qui peut lancer une EntityTypeError
|
171
|
-
except EntityTypeError as e:
|
172
|
-
print(e)
|
173
|
-
```
|
174
|
-
|
175
|
-
## License
|
176
|
-
|
177
|
-
Ce projet est sous licence GNU GPL-3.0 - Voir le fichier [LICENSE](LICENSE) pour plus de détails.
|
nsarchive-2.0.0b1/README.md
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
# nsarchive
|
2
|
-
|
3
|
-
`nsarchive` est un module Python pour la gestion des entités (utilisateurs et organisations) à l'aide de la base de données Deta. Ce module permet de créer, récupérer, sauvegarder et gérer des entités et leurs attributs spécifiques.
|
4
|
-
|
5
|
-
## Pré-requis
|
6
|
-
|
7
|
-
Listes des choses à avoir afin de pouvoir utiliser le module correctement:
|
8
|
-
- [Python 3.10](https://www.python.org/downloads/) ou supérieur
|
9
|
-
- Un token [Deta](https://deta.space), donné par un administrateur ou pour votre collection personnelle
|
10
|
-
- Un bon capuccino, pour commencer la programmation en bons termes
|
11
|
-
|
12
|
-
> **Note:** Il vous faudra un token différent pour accéder aux différentes parties de la base de données. Vos tokens n'expireront pas à moins que l'ordre en aura été donné
|
13
|
-
|
14
|
-
## Installation
|
15
|
-
|
16
|
-
Vous pouvez installer ce module via pip :
|
17
|
-
|
18
|
-
```sh
|
19
|
-
pip install nsarchive
|
20
|
-
```
|
21
|
-
|
22
|
-
## Utilisation
|
23
|
-
|
24
|
-
### Importation et Initialisation
|
25
|
-
|
26
|
-
Pour utiliser `nsarchive`, commencez par importer le module et initialiser une instance d'`EntityInstance` avec votre token Deta.
|
27
|
-
|
28
|
-
```python
|
29
|
-
from nsarchive import EntityInstance
|
30
|
-
|
31
|
-
# Remplacez 'your_deta_token' par votre véritable token Deta
|
32
|
-
entity_instance = EntityInstance(token = 'your_deta_token')
|
33
|
-
```
|
34
|
-
|
35
|
-
### Récupérer une Entité
|
36
|
-
|
37
|
-
Vous pouvez récupérer une entité (Utilisateur ou Organisation) à l'aide de son ID.
|
38
|
-
|
39
|
-
```python
|
40
|
-
entity = entity_instance.get_entity(id = 'entity_id')
|
41
|
-
print(entity.name)
|
42
|
-
```
|
43
|
-
|
44
|
-
**ATTENTION: Les entités sont identifiées sous une forme hexadécimale. Pour les avoir, vous devez convertir leur ID Discord en hexadécimale puis enlever le préfixe `0x`.**
|
45
|
-
|
46
|
-
Pour les organisations, l'ID Discord correspondra à la formule suivante: `ID fondateur // 100000`.
|
47
|
-
|
48
|
-
N'oubliez pas de toujours utiliser un `str` dans les ID pour interagir avec la base de données.
|
49
|
-
|
50
|
-
### Sauvegarder une Entité
|
51
|
-
|
52
|
-
Après avoir modifié une entité, vous pouvez la sauvegarder dans la base de données.
|
53
|
-
|
54
|
-
```python
|
55
|
-
entity.rename("Nouveau Nom")
|
56
|
-
entity_instance.save_entity(entity)
|
57
|
-
```
|
58
|
-
|
59
|
-
### Rechercher des Entités
|
60
|
-
|
61
|
-
Vous pouvez rechercher des entités avec des critères spécifiques.
|
62
|
-
|
63
|
-
```python
|
64
|
-
entities = entity_instance.fetch_entity(query = {'name': 'Alice'})
|
65
|
-
for entity in entities:
|
66
|
-
print(entity['name'])
|
67
|
-
```
|
68
|
-
|
69
|
-
### Gérer les Organisations
|
70
|
-
|
71
|
-
Les organisations peuvent avoir des membres et des certifications. Voici comment ajouter un membre ou une certification.
|
72
|
-
|
73
|
-
```python
|
74
|
-
organization = entity_instance.get_entity(id = 'org_id')
|
75
|
-
user = entity_instance.get_entity(id = 'user_id')
|
76
|
-
|
77
|
-
# Ajouter un membre
|
78
|
-
organization.add_member(user)
|
79
|
-
entity_instance.save_entity(organization)
|
80
|
-
|
81
|
-
# Ajouter une certification
|
82
|
-
organization.add_certification('Certification Example')
|
83
|
-
entity_instance.save_entity(organization)
|
84
|
-
```
|
85
|
-
|
86
|
-
Les certifications pourront être utilisées pour vérifier l'officialité d'une organisation, mais également pour déterminer si l'on peut accorder (ou non) des permissions à ses membres.
|
87
|
-
|
88
|
-
### Exemples de Classes
|
89
|
-
|
90
|
-
#### `Entity`
|
91
|
-
|
92
|
-
Classe parente des classes `User` et `Organization`, elle est utilisée lorsque le module ne peut pas déterminer l'appartenance d'une identité à l'une de ces deux classes ou à l'autre.
|
93
|
-
|
94
|
-
```python
|
95
|
-
from nsarchive.cls.entities import Entity
|
96
|
-
|
97
|
-
entity = Entity(id='entity_id')
|
98
|
-
entity.rename('New Name')
|
99
|
-
entity.add_xp(100)
|
100
|
-
print(entity.get_level())
|
101
|
-
```
|
102
|
-
|
103
|
-
#### `User`
|
104
|
-
|
105
|
-
```python
|
106
|
-
from nsarchive.cls.entities import User
|
107
|
-
|
108
|
-
user = User(id = 'user_id')
|
109
|
-
user.edit_boost(name = 'admin', multiplier = 5) # Négliger le paramètre <multiplier> ou le fixer à un nombre négatif reviendrait à supprimer le boost.
|
110
|
-
print(user.boosts)
|
111
|
-
```
|
112
|
-
|
113
|
-
> **Note:** Lorsqu'on ajoute de l'expérience à un utilisateur via la méthode `add_xp`, le nombre de points ajoutés est automatiquement multiplié par le bonus le plus important dont l'utilisateur bénéficie.
|
114
|
-
|
115
|
-
#### `Organization`
|
116
|
-
|
117
|
-
```python
|
118
|
-
from nsarchive.cls.entities import Organization
|
119
|
-
|
120
|
-
organization = Organization(id = 'org_id')
|
121
|
-
organization.set_owner(user)
|
122
|
-
organization.add_member(user)
|
123
|
-
print(organization.members)
|
124
|
-
```
|
125
|
-
|
126
|
-
> **Note:** Les attributs `owner` et `members` sont indépendants. L'owner peut être n'importe quelle personne faisant ou non partie des `members`.
|
127
|
-
|
128
|
-
## Gestion des Exceptions
|
129
|
-
|
130
|
-
`nsarchive` fournit des exceptions spécifiques pour gérer les erreurs courantes.
|
131
|
-
|
132
|
-
#### `NameTooLongError`
|
133
|
-
|
134
|
-
Lancé lorsque le nom d'une entité dépasse la longueur maximale autorisée (32 caractères).
|
135
|
-
|
136
|
-
```python
|
137
|
-
from nsarchive.cls.exceptions import NameTooLongError
|
138
|
-
|
139
|
-
try:
|
140
|
-
entity.rename('Ce nom est long, voire même très long, je dirais même extrêmement long')
|
141
|
-
except NameTooLongError as e:
|
142
|
-
print(e)
|
143
|
-
```
|
144
|
-
|
145
|
-
#### `EntityTypeError`
|
146
|
-
|
147
|
-
Lancé lorsque le type d'entité est incorrect. Vous ne devriez normalement pas la rencontrer en utilisant le module, mais elle pourrait vous être utile.
|
148
|
-
|
149
|
-
```python
|
150
|
-
from nsarchive.cls.exceptions import EntityTypeError
|
151
|
-
|
152
|
-
try:
|
153
|
-
# Code qui peut lancer une EntityTypeError
|
154
|
-
except EntityTypeError as e:
|
155
|
-
print(e)
|
156
|
-
```
|
157
|
-
|
158
|
-
## License
|
159
|
-
|
160
|
-
Ce projet est sous licence GNU GPL-3.0 - Voir le fichier [LICENSE](LICENSE) pour plus de détails.
|
@@ -1,44 +0,0 @@
|
|
1
|
-
from .base import NSID
|
2
|
-
|
3
|
-
class BankAccount:
|
4
|
-
def __init__(self, id: str | NSID) -> None:
|
5
|
-
self.id: NSID = NSID(id)
|
6
|
-
self.owner: NSID = NSID(0)
|
7
|
-
self.amount: int = 0
|
8
|
-
self.frozen: bool = False
|
9
|
-
self.bank: str = "HexaBank"
|
10
|
-
|
11
|
-
self.income: int = 0
|
12
|
-
|
13
|
-
class Item:
|
14
|
-
def __init__(self, id: str | NSID) -> None:
|
15
|
-
self.id: NSID = NSID(id)
|
16
|
-
self.title: str = "Unknown Object"
|
17
|
-
self.emoji: str = ":light_bulb:"
|
18
|
-
|
19
|
-
class Inventory:
|
20
|
-
def __init__(self, owner_id: NSID) -> None:
|
21
|
-
self.owner_id: NSID = NSID(owner_id)
|
22
|
-
self.objects: dict[str, NSID] = {}
|
23
|
-
|
24
|
-
def append(self, item: Item, quantity: int = 1):
|
25
|
-
if item.id in self.objects.keys():
|
26
|
-
self.objects[item.id] += quantity
|
27
|
-
else:
|
28
|
-
self.objects[item.id] = quantity
|
29
|
-
|
30
|
-
def throw(self, item: Item, quantity: int = 1):
|
31
|
-
if item.id in self.objects.keys():
|
32
|
-
if self.objects[item.id] > quantity:
|
33
|
-
self.objects[item.id] -= quantity
|
34
|
-
else:
|
35
|
-
self.objects[item.id] = 0
|
36
|
-
|
37
|
-
class Sale:
|
38
|
-
def __init__(self, id: NSID, item: Item) -> None:
|
39
|
-
self.id: NSID = NSID(id)
|
40
|
-
self.item: NSID = NSID(item.id)
|
41
|
-
self.quantity: int = 1
|
42
|
-
|
43
|
-
self.price: int = 0
|
44
|
-
self.seller_id: NSID = NSID('0')
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|