nsarchive 3.0.0a3__tar.gz → 3.0.0a5__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.0a3 → nsarchive-3.0.0a5}/PKG-INFO +1 -1
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/nsarchive/__init__.py +1 -1
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/nsarchive/cls/base.py +19 -2
- nsarchive-3.0.0a5/nsarchive/cls/economy.py +230 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/nsarchive/cls/entities.py +30 -18
- nsarchive-3.0.0a5/nsarchive/instances/_economy.py +378 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/nsarchive/instances/_entities.py +71 -17
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/nsarchive/utils.py +4 -1
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/pyproject.toml +1 -1
- nsarchive-3.0.0a3/nsarchive/cls/economy.py +0 -100
- nsarchive-3.0.0a3/nsarchive/instances/_economy.py +0 -356
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/LICENSE +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/README.md +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/nsarchive/assets/default_avatar.png +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/nsarchive/cls/archives.py +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/nsarchive/cls/republic.py +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a5}/nsarchive/instances/_republic.py +0 -0
@@ -2,7 +2,10 @@ import io
|
|
2
2
|
import json
|
3
3
|
import requests
|
4
4
|
import typing
|
5
|
-
|
5
|
+
|
6
|
+
from .. import utils
|
7
|
+
|
8
|
+
VERSION = 300
|
6
9
|
|
7
10
|
class NSID(str):
|
8
11
|
"""
|
@@ -54,6 +57,20 @@ class Instance:
|
|
54
57
|
"Content-Type": "application/json",
|
55
58
|
}
|
56
59
|
|
60
|
+
try:
|
61
|
+
test_res = requests.get(f'{self.url}/ping')
|
62
|
+
|
63
|
+
if test_res.status_code == 200:
|
64
|
+
ndb_ver = test_res.json()['_version']
|
65
|
+
_litt = lambda x: '.'.join((str(x // 100), str(x % 100)))
|
66
|
+
|
67
|
+
if ndb_ver != VERSION:
|
68
|
+
utils.warn(f"NationDB (v{_litt(ndb_ver)}) and NSArchive (v{_litt(VERSION)}) versions do not match. Some bugs may appear.")
|
69
|
+
else:
|
70
|
+
utils.warn("Something went wrong with the server.")
|
71
|
+
except:
|
72
|
+
utils.warn("NationDB is not responding.")
|
73
|
+
|
57
74
|
def request_token(self, username: str, password: str) -> str | None:
|
58
75
|
res = requests.post(f"{self.url}/auth/login", json = {
|
59
76
|
"username": username,
|
@@ -151,7 +168,7 @@ class Instance:
|
|
151
168
|
raise Exception(f"Error {res.status_code}: {res.json()['message']}")
|
152
169
|
|
153
170
|
def _delete_by_ID(self, _class: str, id: NSID):
|
154
|
-
|
171
|
+
utils.warn("Method '_delete_by_id' is deprecated. Use '_delete' instead.")
|
155
172
|
self._delete(_class, id)
|
156
173
|
|
157
174
|
def fetch(self, _class: str, **query: typing.Any) -> list:
|
@@ -0,0 +1,230 @@
|
|
1
|
+
import requests
|
2
|
+
import time
|
3
|
+
import urllib
|
4
|
+
|
5
|
+
from .base import NSID
|
6
|
+
|
7
|
+
default_headers = {}
|
8
|
+
|
9
|
+
class BankAccount:
|
10
|
+
"""
|
11
|
+
Compte en banque d'une entité, individuelle ou collective.
|
12
|
+
|
13
|
+
## Attributs
|
14
|
+
- id: `NSID`\n
|
15
|
+
Identifiant du compte
|
16
|
+
- owner: `NSID`\n
|
17
|
+
Identifiant du titulaire du compte
|
18
|
+
- amount: `int`\n
|
19
|
+
Somme d'argent totale sur le compte
|
20
|
+
- frozen: `bool`\n
|
21
|
+
État gelé ou non du compte
|
22
|
+
- bank: `NSID`\n
|
23
|
+
Identifiant de la banque qui détient le compte
|
24
|
+
- income: `int`\n
|
25
|
+
Somme entrante sur le compte depuis la dernière réinitialisation (tous les ~ 28 jours)
|
26
|
+
"""
|
27
|
+
|
28
|
+
def __init__(self, owner_id: NSID) -> None:
|
29
|
+
self._url: str = ""
|
30
|
+
|
31
|
+
self.id: NSID = NSID(owner_id)
|
32
|
+
self.owner_id: NSID = NSID(owner_id)
|
33
|
+
self.register_date: int = round(time.time())
|
34
|
+
self.tag: str = "inconnu"
|
35
|
+
self.bank: str = "HexaBank"
|
36
|
+
|
37
|
+
self.amount: int = 0
|
38
|
+
self.income: int = 0
|
39
|
+
|
40
|
+
self.frozen: bool = False
|
41
|
+
self.flagged: bool = False
|
42
|
+
|
43
|
+
def _load(self, _data: dict):
|
44
|
+
self.owner_id = NSID(_data['owner_id'])
|
45
|
+
self.register_date = _data['register_date']
|
46
|
+
self.tag = _data['tag']
|
47
|
+
self.bank = _data['bank']
|
48
|
+
|
49
|
+
self.amount = _data['amount']
|
50
|
+
self.income = _data['income']
|
51
|
+
|
52
|
+
self.frozen = _data['frozen']
|
53
|
+
self.flagged = _data['flagged']
|
54
|
+
|
55
|
+
def freeze(self, frozen: bool = True, reason: str = None) -> None:
|
56
|
+
res = requests.post(f"{self._url}/freeze?frozen={str(frozen).lower()}", headers = default_headers, json = {
|
57
|
+
"reason": reason
|
58
|
+
})
|
59
|
+
|
60
|
+
if res.status_code == 200:
|
61
|
+
self.frozen = frozen
|
62
|
+
else:
|
63
|
+
print(res.text)
|
64
|
+
res.raise_for_status()
|
65
|
+
|
66
|
+
def flag(self, flagged: bool = True, reason: str = None) -> None:
|
67
|
+
res = requests.post(f"{self._url}/flag?flagged={str(flagged).lower()}", headers = default_headers, json = {
|
68
|
+
"reason": reason
|
69
|
+
})
|
70
|
+
|
71
|
+
if res.status_code == 200:
|
72
|
+
self.flagged = flagged
|
73
|
+
else:
|
74
|
+
res.raise_for_status()
|
75
|
+
|
76
|
+
def debit(self, amount: int, reason: str = None, target: NSID = None, loan: NSID = None, digicode: str = None) -> None:
|
77
|
+
_target_query = f"&target={target}"
|
78
|
+
_loan_query = f"&loan_id={loan}"
|
79
|
+
|
80
|
+
res = requests.post(f"{self._url}/debit?amount={amount}{_target_query if target else ''}{_loan_query if loan else ''}", headers = default_headers, json = {
|
81
|
+
"reason": reason,
|
82
|
+
"digicode": digicode
|
83
|
+
})
|
84
|
+
|
85
|
+
if res.status_code == 200:
|
86
|
+
self.amount -= amount
|
87
|
+
else:
|
88
|
+
res.raise_for_status()
|
89
|
+
|
90
|
+
def deposit(self, amount: int, reason: str = None) -> None:
|
91
|
+
res = requests.post(f"{self._url}/deposit?amount={amount}", headers = default_headers, json = {
|
92
|
+
"reason": reason,
|
93
|
+
})
|
94
|
+
|
95
|
+
if res.status_code == 200:
|
96
|
+
self.amount -= amount
|
97
|
+
else:
|
98
|
+
res.raise_for_status()
|
99
|
+
|
100
|
+
class Item:
|
101
|
+
"""
|
102
|
+
Article d'inventaire qui peut circuler sur le serveur
|
103
|
+
|
104
|
+
## Attributs
|
105
|
+
- id: `NSID`\n
|
106
|
+
Identifiant de l'objet
|
107
|
+
- name: `str`\n
|
108
|
+
Nom de l'objet
|
109
|
+
- emoji: `str`\n
|
110
|
+
Emoji lié à l'objet
|
111
|
+
"""
|
112
|
+
|
113
|
+
def __init__(self) -> None:
|
114
|
+
self.id: NSID = NSID(round(time.time()))
|
115
|
+
self.name: str = "Unknown Object"
|
116
|
+
self.emoji: str = ":light_bulb:"
|
117
|
+
self.category: str = "common"
|
118
|
+
self.craft: dict = {}
|
119
|
+
|
120
|
+
def _load(self, _data: dict):
|
121
|
+
self.name = _data['name']
|
122
|
+
self.emoji = _data['emoji']
|
123
|
+
self.category = _data['category']
|
124
|
+
self.craft = _data['craft']
|
125
|
+
|
126
|
+
def rename(self, new_name: str):
|
127
|
+
res = requests.post(f"{self._url}/rename?name={new_name}", headers = default_headers)
|
128
|
+
|
129
|
+
if res.status_code == 200:
|
130
|
+
self.name = new_name
|
131
|
+
else:
|
132
|
+
res.raise_for_status()
|
133
|
+
|
134
|
+
class Sale:
|
135
|
+
"""
|
136
|
+
Vente mettant en jeu un objet
|
137
|
+
|
138
|
+
## Attributs
|
139
|
+
- id: `NSID`\n
|
140
|
+
Identifiant de la vente
|
141
|
+
- item: `NSID`\n
|
142
|
+
Identifiant de l'objet mis en vente
|
143
|
+
- quantity: `int`\n
|
144
|
+
Quantité d'objets mis en vente
|
145
|
+
- price: `int`\n
|
146
|
+
Prix total du lot
|
147
|
+
- seller_id: `NSID`\n
|
148
|
+
Identifiant du vendeur
|
149
|
+
"""
|
150
|
+
|
151
|
+
def __init__(self, item: Item) -> None:
|
152
|
+
self._url: str = ""
|
153
|
+
|
154
|
+
self.id: NSID = NSID(round(time.time()))
|
155
|
+
self.open: bool = True
|
156
|
+
self.seller_id: NSID = NSID('0')
|
157
|
+
|
158
|
+
self.item_id: NSID = NSID(item.id)
|
159
|
+
self.quantity: int = 1
|
160
|
+
self.price: int = 0
|
161
|
+
|
162
|
+
def _load(self, _data: dict):
|
163
|
+
self.id = _data['json']
|
164
|
+
self.open = _data['open']
|
165
|
+
self.seller_id = NSID(_data['seller_id'])
|
166
|
+
|
167
|
+
self.item_id = NSID(_data['item_id'])
|
168
|
+
self.quantity = _data['quantity']
|
169
|
+
self.price = _data['price']
|
170
|
+
|
171
|
+
class Inventory:
|
172
|
+
"""
|
173
|
+
Inventaire d'un membre
|
174
|
+
|
175
|
+
## Attributs
|
176
|
+
- id: `NSID`\n
|
177
|
+
ID de l'inventaire
|
178
|
+
- owner_id: `NSID`\n
|
179
|
+
ID du propriétaire de l'inventaire
|
180
|
+
- tag: `str`\n
|
181
|
+
Étiquette de l'inventaire
|
182
|
+
- register_date: `int`\n
|
183
|
+
Date (timestamp) de création de l'inventaire
|
184
|
+
- items: `dict[NSID, int]`\n
|
185
|
+
Collection d'objets et leur quantité
|
186
|
+
"""
|
187
|
+
|
188
|
+
def __init__(self, owner_id: NSID) -> None:
|
189
|
+
self._url: str = ""
|
190
|
+
|
191
|
+
self.id: NSID = NSID(owner_id)
|
192
|
+
self.owner_id: NSID = NSID(owner_id)
|
193
|
+
|
194
|
+
self.tag: str = "inconnu"
|
195
|
+
self.register_date: int = 0
|
196
|
+
|
197
|
+
self.items: dict[NSID, int] = {}
|
198
|
+
|
199
|
+
def _load(self, _data: dict):
|
200
|
+
self.id = NSID(_data['id'])
|
201
|
+
self.owner_id = NSID(_data['owner_id'])
|
202
|
+
|
203
|
+
self.tag = _data['tag']
|
204
|
+
self.register_date = _data['register_date']
|
205
|
+
|
206
|
+
self.items = _data['items']
|
207
|
+
|
208
|
+
def deposit_item(self, item: Item, giver: NSID = None, quantity: int = 1, digicode: str = None):
|
209
|
+
res = requests.post(f"{self._url}/deposit?item={item.id}&amount={quantity}", headers = default_headers, json = {
|
210
|
+
"giver": giver,
|
211
|
+
"digicode": digicode
|
212
|
+
})
|
213
|
+
|
214
|
+
if res.status_code == 200:
|
215
|
+
if self.objects[item.id] > quantity:
|
216
|
+
self.objects[item.id] -= quantity
|
217
|
+
else:
|
218
|
+
self.objects[item.id] = 0
|
219
|
+
else:
|
220
|
+
res.raise_for_status()
|
221
|
+
|
222
|
+
def sell_item(self, item: Item, price: int, quantity: int = 1, digicode: str = None) -> NSID:
|
223
|
+
res = requests.post(f"{self._url}/sell_item?item={item.id}&quantity={quantity}&price={price}", headers = default_headers, json = {
|
224
|
+
"digicode": digicode
|
225
|
+
})
|
226
|
+
|
227
|
+
if res.status_code == 200:
|
228
|
+
return NSID(res.json()['sale_id'])
|
229
|
+
else:
|
230
|
+
res.raise_for_status()
|
@@ -31,17 +31,20 @@ class PositionPermissions:
|
|
31
31
|
"""
|
32
32
|
|
33
33
|
def __init__(self) -> None:
|
34
|
-
self.
|
35
|
-
self.
|
36
|
-
self.
|
37
|
-
self.
|
38
|
-
self.items = Permission("---r") # APPEND =
|
34
|
+
self.bots = Permission() # APPEND = /, MANAGE = proposer d'héberger un bot, EDIT = changer les paramètres d'un bot, READ = /
|
35
|
+
self.constitution = Permission() # APPEND = /, MANAGE = /, EDIT = modifier la constitution, READ = /
|
36
|
+
self.database = Permission() # APPEND = créer des sous-bases de données, MANAGE = gérer la base de données, EDIT = modifier les éléments, READ = avoir accès à toutes les données sans exception
|
37
|
+
self.inventories = Permission("a---") # APPEND = ouvrir un ou plusieurs comptes/inventaires, MANAGE = voir les infos globales concernant les comptes en banque ou inventaires, EDIT = gérer des comptes en banque (ou inventaires), READ = voir les infos d'un compte en banque ou inventaire
|
38
|
+
self.items = Permission("---r") # APPEND = créer un item, MANAGE = gérer les items, EDIT = modifier des items, READ = voir tous les items
|
39
39
|
self.laws = Permission() # APPEND = proposer un texte de loi, MANAGE = accepter ou refuser une proposition, EDIT = modifier un texte, READ = /
|
40
|
+
self.loans = Permission() # APPEND = prélever de l'argent sur un compte, MANAGE = gérer les prêts/prélèvements, EDIT = modifier les prêts, READ = voir tous les prêts
|
40
41
|
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.
|
42
|
+
self.mines = Permission("----") # APPEND = générer des matières premières, MANAGE = gérer les accès aux réservoirs, EDIT = créer un nouveau réservoir, READ = récupérer des matières premières
|
43
|
+
self.money = Permission("----") # APPEND = générer ou supprimer de la monnaie, MANAGE = /, EDIT = /, READ = /
|
42
44
|
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 = /
|
43
45
|
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
|
44
46
|
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
|
47
|
+
self.sales = Permission("---r") # APPEND = vendre, MANAGE = gérer les ventes, EDIT = modifier des ventes, READ = accéder au marketplace
|
45
48
|
self.state_budgets = Permission() # APPEND = débloquer un nouveau budget, MANAGE = gérer les budjets, EDIT = gérer les sommes pour chaque budjet, READ = accéder aux infos concernant les budgets
|
46
49
|
self.votes = Permission() # APPEND = déclencher un vote, MANAGE = fermer un vote, EDIT = /, READ = lire les propriétés d'un vote avant sa fermeture
|
47
50
|
|
@@ -71,10 +74,28 @@ class Position:
|
|
71
74
|
self.name: str = "Inconnue"
|
72
75
|
self.id = id
|
73
76
|
self.permissions: PositionPermissions = PositionPermissions()
|
77
|
+
self.manager_permissions: PositionPermissions = PositionPermissions()
|
78
|
+
|
79
|
+
self._url: str = ""
|
74
80
|
|
75
81
|
def __repr__(self):
|
76
82
|
return self.id
|
77
83
|
|
84
|
+
def update_permisions(self, **permissions: str):
|
85
|
+
query = "&".join(f"{k}={ urllib.parse.quote(v) }" for k, v in permissions.items())
|
86
|
+
|
87
|
+
res = requests.post(f"{self._url}/update_permissions?{query}", headers = default_headers)
|
88
|
+
|
89
|
+
if res.status_code == 200:
|
90
|
+
self.permissions.merge(permissions)
|
91
|
+
else:
|
92
|
+
res.raise_for_status()
|
93
|
+
|
94
|
+
def _load(self, _data: dict):
|
95
|
+
self.name = _data['name']
|
96
|
+
self.permissions.merge(_data['permissions'])
|
97
|
+
self.manager_permissions.merge(_data['manager_permissions'])
|
98
|
+
|
78
99
|
class Entity:
|
79
100
|
"""
|
80
101
|
Classe de référence pour les entités
|
@@ -110,7 +131,6 @@ class Entity:
|
|
110
131
|
if res.status_code == 200:
|
111
132
|
self.name = new_name
|
112
133
|
else:
|
113
|
-
print(res.status_code)
|
114
134
|
res.raise_for_status()
|
115
135
|
|
116
136
|
def set_position(self, position: Position) -> None:
|
@@ -285,19 +305,14 @@ class Organization(Entity):
|
|
285
305
|
super().__init__(NSID(id))
|
286
306
|
|
287
307
|
self.owner: Entity = User(NSID(0x0))
|
288
|
-
self.
|
308
|
+
self.avatar_url: str = self._url + '/avatar'
|
289
309
|
|
290
310
|
self.certifications: dict = {}
|
291
311
|
self.members: list[GroupMember] = []
|
292
312
|
self.invites: dict[GroupInvite] = []
|
293
313
|
|
294
314
|
def _load(self, _data: dict):
|
295
|
-
|
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}")
|
315
|
+
self.avatar_url = self._url + '/avatar'
|
301
316
|
|
302
317
|
for _member in _data['members']:
|
303
318
|
member = GroupMember(_member['id'])
|
@@ -356,7 +371,4 @@ class Organization(Entity):
|
|
356
371
|
return [ member.__getattribute__(attribute) for member in self.members ]
|
357
372
|
|
358
373
|
def save_avatar(self, data: bytes = None):
|
359
|
-
|
360
|
-
return
|
361
|
-
|
362
|
-
self.avatar = data
|
374
|
+
pass
|