nsarchive 3.0.0a4__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.0a4 → nsarchive-3.0.0a5}/PKG-INFO +1 -1
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/nsarchive/__init__.py +1 -1
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/nsarchive/cls/base.py +19 -2
- nsarchive-3.0.0a5/nsarchive/cls/economy.py +230 -0
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/nsarchive/cls/entities.py +9 -7
- nsarchive-3.0.0a5/nsarchive/instances/_economy.py +378 -0
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/nsarchive/utils.py +4 -1
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/pyproject.toml +1 -1
- nsarchive-3.0.0a4/nsarchive/cls/economy.py +0 -100
- nsarchive-3.0.0a4/nsarchive/instances/_economy.py +0 -356
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/LICENSE +0 -0
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/README.md +0 -0
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/nsarchive/assets/default_avatar.png +0 -0
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/nsarchive/cls/archives.py +0 -0
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/nsarchive/cls/republic.py +0 -0
- {nsarchive-3.0.0a4 → nsarchive-3.0.0a5}/nsarchive/instances/_entities.py +0 -0
- {nsarchive-3.0.0a4 → 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
|
|
@@ -128,7 +131,6 @@ class Entity:
|
|
128
131
|
if res.status_code == 200:
|
129
132
|
self.name = new_name
|
130
133
|
else:
|
131
|
-
print(res.status_code)
|
132
134
|
res.raise_for_status()
|
133
135
|
|
134
136
|
def set_position(self, position: Position) -> None:
|
@@ -0,0 +1,378 @@
|
|
1
|
+
import time
|
2
|
+
|
3
|
+
from ..cls.base import *
|
4
|
+
from ..cls.archives import *
|
5
|
+
from ..cls.economy import *
|
6
|
+
|
7
|
+
from ..cls import economy # Pour les default_headers
|
8
|
+
|
9
|
+
class EconomyInstance(Instance):
|
10
|
+
"""Indisponible dans cette version."""
|
11
|
+
|
12
|
+
def __init__(self, url: str, token: str) -> None:
|
13
|
+
super().__init__(url, token)
|
14
|
+
|
15
|
+
economy.default_headers = self.default_headers
|
16
|
+
|
17
|
+
"""
|
18
|
+
---- COMPTES EN BANQUE ----
|
19
|
+
"""
|
20
|
+
|
21
|
+
def get_account(self, id: NSID) -> BankAccount:
|
22
|
+
"""
|
23
|
+
Récupère les informations d'un compte bancaire.
|
24
|
+
|
25
|
+
## Paramètres
|
26
|
+
id: `NSID`\n
|
27
|
+
ID du compte.
|
28
|
+
|
29
|
+
## Renvoie
|
30
|
+
- `.BankAccount`
|
31
|
+
"""
|
32
|
+
|
33
|
+
id = NSID(id)
|
34
|
+
res = requests.get(f"{self.url}/bank/accounts/{id}", headers = self.default_headers)
|
35
|
+
|
36
|
+
if res.status_code == 200:
|
37
|
+
_data = res.json()
|
38
|
+
else:
|
39
|
+
res.raise_for_status()
|
40
|
+
return
|
41
|
+
|
42
|
+
if _data is None:
|
43
|
+
return None
|
44
|
+
|
45
|
+
account = BankAccount(id)
|
46
|
+
account._url = f"{self.url}/bank/accounts/{account.id}"
|
47
|
+
|
48
|
+
account._load(_data)
|
49
|
+
|
50
|
+
return account
|
51
|
+
|
52
|
+
def save_account(self, account: BankAccount) -> str:
|
53
|
+
"""
|
54
|
+
Sauvegarde un compte bancaire dans la base de données.
|
55
|
+
|
56
|
+
## Paramètres
|
57
|
+
- account: `.BankAccount`\n
|
58
|
+
Compte à sauvegarder
|
59
|
+
"""
|
60
|
+
|
61
|
+
_data = {
|
62
|
+
'id': NSID(account.id),
|
63
|
+
'amount': account.amount,
|
64
|
+
'frozen': account.frozen,
|
65
|
+
'owner_id': account.owner_id,
|
66
|
+
'bank': account.bank,
|
67
|
+
'income': account.income
|
68
|
+
}
|
69
|
+
|
70
|
+
res = requests.put(f"{self.url}/bank/register_account?owner={_data['owner_id']}", headers = self.default_headers, json = _data)
|
71
|
+
|
72
|
+
if res.status_code == 200:
|
73
|
+
account._url = f"{self.url}/bank/accounts/{account.id}"
|
74
|
+
account.id = res.json()['id']
|
75
|
+
|
76
|
+
return res.json()['digicode']
|
77
|
+
else:
|
78
|
+
res.raise_for_status()
|
79
|
+
|
80
|
+
def fetch_accounts(self, **query: typing.Any) -> list[BankAccount]:
|
81
|
+
"""
|
82
|
+
Récupère une liste de comptes en banque en fonction d'une requête.
|
83
|
+
|
84
|
+
## Paramètres
|
85
|
+
query: `**dict`\n
|
86
|
+
La requête pour filtrer les comptes.
|
87
|
+
|
88
|
+
## Renvoie
|
89
|
+
- `list[.BankAccount]`
|
90
|
+
"""
|
91
|
+
|
92
|
+
query = "&".join(f"{k}={ urllib.parse.quote(v) }" for k, v in query.items())
|
93
|
+
|
94
|
+
_res = requests.get(f"{self.url}/fetch/accounts?{query}", headers = self.default_headers)
|
95
|
+
|
96
|
+
if _res.status_code == 200:
|
97
|
+
_data = _res.json()
|
98
|
+
else:
|
99
|
+
_res.raise_for_status()
|
100
|
+
return []
|
101
|
+
|
102
|
+
res = []
|
103
|
+
|
104
|
+
for _acc in _data:
|
105
|
+
if not _acc: continue
|
106
|
+
|
107
|
+
account = BankAccount(_acc["owner_id"])
|
108
|
+
|
109
|
+
account.id = NSID(_acc['id'])
|
110
|
+
account._url = f"{self.url}/bank/accounts/{account.id}"
|
111
|
+
|
112
|
+
account._load(_acc)
|
113
|
+
|
114
|
+
res.append(account)
|
115
|
+
|
116
|
+
return res
|
117
|
+
|
118
|
+
"""
|
119
|
+
---- INVENTAIRES ----
|
120
|
+
"""
|
121
|
+
|
122
|
+
def get_inventory(self, id: NSID) -> Inventory:
|
123
|
+
"""
|
124
|
+
Récupère les informations d'un inventaire.
|
125
|
+
|
126
|
+
## Paramètres
|
127
|
+
id: `NSID`\n
|
128
|
+
ID de l'inventaire.
|
129
|
+
|
130
|
+
## Renvoie
|
131
|
+
- `.Inventory`
|
132
|
+
"""
|
133
|
+
|
134
|
+
id = NSID(id)
|
135
|
+
res = requests.get(f"{self.url}/bank/inventories/{id}", headers = self.default_headers)
|
136
|
+
|
137
|
+
if res.status_code == 200:
|
138
|
+
_data = res.json()
|
139
|
+
else:
|
140
|
+
res.raise_for_status()
|
141
|
+
return
|
142
|
+
|
143
|
+
if _data is None:
|
144
|
+
return None
|
145
|
+
|
146
|
+
inventory = Inventory(id)
|
147
|
+
inventory._url = f"{self.url}/bank/inventories/{inventory.id}"
|
148
|
+
|
149
|
+
inventory._load(_data)
|
150
|
+
|
151
|
+
return inventory
|
152
|
+
|
153
|
+
def save_inventory(self, inventory: Inventory) -> str:
|
154
|
+
"""
|
155
|
+
Sauvegarde un inventaire dans la base de données.
|
156
|
+
|
157
|
+
## Paramètres
|
158
|
+
- inventory: `.Inventory`\n
|
159
|
+
Inventaire à sauvegarder
|
160
|
+
"""
|
161
|
+
|
162
|
+
_data = inventory.__dict__
|
163
|
+
|
164
|
+
res = requests.put(f"{self.url}/bank/register_inventory?owner={_data['owner_id']}", headers = self.default_headers, json = _data)
|
165
|
+
|
166
|
+
if res.status_code == 200:
|
167
|
+
inventory._url = f"{self.url}/bank/inventories/{inventory.id}"
|
168
|
+
inventory.id = res.json()['id']
|
169
|
+
|
170
|
+
return res.json()['digicode']
|
171
|
+
else:
|
172
|
+
res.raise_for_status()
|
173
|
+
|
174
|
+
def fetch_inventories(self, **query: typing.Any) -> list[Inventory]:
|
175
|
+
"""
|
176
|
+
Récupère une liste d'inventaires en fonction d'une requête.
|
177
|
+
|
178
|
+
## Paramètres
|
179
|
+
query: `**dict`\n
|
180
|
+
La requête pour filtrer les inventaires.
|
181
|
+
|
182
|
+
## Renvoie
|
183
|
+
- `list[.Inventory]`
|
184
|
+
"""
|
185
|
+
|
186
|
+
query = "&".join(f"{k}={ urllib.parse.quote(v) }" for k, v in query.items())
|
187
|
+
|
188
|
+
_res = requests.get(f"{self.url}/fetch/inventories?{query}", headers = self.default_headers)
|
189
|
+
|
190
|
+
if _res.status_code == 200:
|
191
|
+
_data = _res.json()
|
192
|
+
else:
|
193
|
+
_res.raise_for_status()
|
194
|
+
return []
|
195
|
+
|
196
|
+
res = []
|
197
|
+
|
198
|
+
for _inv in _data:
|
199
|
+
if not _inv: continue
|
200
|
+
|
201
|
+
inventory = Inventory(_inv["owner_id"])
|
202
|
+
|
203
|
+
inventory.id = NSID(_inv['id'])
|
204
|
+
inventory._url = f"{self.url}/bank/inventories/{inventory.id}"
|
205
|
+
|
206
|
+
inventory._load(_inv)
|
207
|
+
|
208
|
+
res.append(inventory)
|
209
|
+
|
210
|
+
return res
|
211
|
+
|
212
|
+
"""
|
213
|
+
---- ITEMS ----
|
214
|
+
"""
|
215
|
+
|
216
|
+
def get_item(self, id: NSID) -> Item:
|
217
|
+
"""
|
218
|
+
Récupère les informations d'un item.
|
219
|
+
|
220
|
+
## Paramètres
|
221
|
+
id: `NSID`\n
|
222
|
+
ID de l'item.
|
223
|
+
|
224
|
+
## Renvoie
|
225
|
+
- `.Item`
|
226
|
+
"""
|
227
|
+
|
228
|
+
id = NSID(id)
|
229
|
+
res = requests.get(f"{self.url}/marketplace/items/{id}", headers = self.default_headers)
|
230
|
+
|
231
|
+
if res.status_code == 200:
|
232
|
+
_data = res.json()
|
233
|
+
else:
|
234
|
+
res.raise_for_status()
|
235
|
+
return
|
236
|
+
|
237
|
+
if _data is None:
|
238
|
+
return None
|
239
|
+
|
240
|
+
item = Item()
|
241
|
+
item.id = id
|
242
|
+
item._url = f"{self.url}/marketplace/items/{item.id}"
|
243
|
+
|
244
|
+
item._load(_data)
|
245
|
+
|
246
|
+
return item
|
247
|
+
|
248
|
+
def save_item(self, item: Item) -> None:
|
249
|
+
"""
|
250
|
+
Sauvegarde un item dans le marketplace.
|
251
|
+
|
252
|
+
## Paramètres
|
253
|
+
- item: `.Item`\n
|
254
|
+
Item à sauvegarder
|
255
|
+
"""
|
256
|
+
|
257
|
+
_data = item.__dict__
|
258
|
+
|
259
|
+
res = requests.put(f"{self.url}/marketplace/register_item", headers = self.default_headers, json = _data)
|
260
|
+
|
261
|
+
if res.status_code == 200:
|
262
|
+
item._url = f"{self.url}/bank/inventories/{item.id}"
|
263
|
+
item.id = res.json()['id']
|
264
|
+
else:
|
265
|
+
res.raise_for_status()
|
266
|
+
|
267
|
+
def fetch_items(self, **query: typing.Any) -> list[Item]:
|
268
|
+
"""
|
269
|
+
Récupère une liste d'items en fonction d'une requête.
|
270
|
+
|
271
|
+
## Paramètres
|
272
|
+
query: `**dict`\n
|
273
|
+
La requête pour filtrer les items.
|
274
|
+
|
275
|
+
## Renvoie
|
276
|
+
- `list[.Item]`
|
277
|
+
"""
|
278
|
+
|
279
|
+
query = "&".join(f"{k}={ urllib.parse.quote(v) }" for k, v in query.items())
|
280
|
+
|
281
|
+
_res = requests.get(f"{self.url}/fetch/items?{query}", headers = self.default_headers)
|
282
|
+
|
283
|
+
if _res.status_code == 200:
|
284
|
+
_data = _res.json()
|
285
|
+
else:
|
286
|
+
_res.raise_for_status()
|
287
|
+
return []
|
288
|
+
|
289
|
+
res = []
|
290
|
+
|
291
|
+
for _item in _data:
|
292
|
+
if not _item: continue
|
293
|
+
|
294
|
+
item = Item()
|
295
|
+
|
296
|
+
item.id = NSID(_item['id'])
|
297
|
+
item._url = f"{self.url}/marketplace/items/{item.id}"
|
298
|
+
|
299
|
+
item._load(_item)
|
300
|
+
|
301
|
+
res.append(item)
|
302
|
+
|
303
|
+
return res
|
304
|
+
|
305
|
+
|
306
|
+
"""
|
307
|
+
---- VENTES ----
|
308
|
+
"""
|
309
|
+
|
310
|
+
def get_sale(self, id: NSID) -> Sale:
|
311
|
+
"""
|
312
|
+
Récupère les informations d'une annonce.
|
313
|
+
|
314
|
+
## Paramètres
|
315
|
+
id: `NSID`\n
|
316
|
+
ID de la annonce.
|
317
|
+
|
318
|
+
## Renvoie
|
319
|
+
- `.Sale`
|
320
|
+
"""
|
321
|
+
|
322
|
+
id = NSID(id)
|
323
|
+
res = requests.get(f"{self.url}/marketplace/sales/{id}", headers = self.default_headers)
|
324
|
+
|
325
|
+
if res.status_code == 200:
|
326
|
+
_data = res.json()
|
327
|
+
else:
|
328
|
+
res.raise_for_status()
|
329
|
+
return
|
330
|
+
|
331
|
+
if _data is None:
|
332
|
+
return None
|
333
|
+
|
334
|
+
sale = Sale()
|
335
|
+
sale.id = id
|
336
|
+
sale._url = f"{self.url}/marketplace/sales/{sale.id}"
|
337
|
+
|
338
|
+
sale._load(_data)
|
339
|
+
|
340
|
+
return sale
|
341
|
+
|
342
|
+
def fetch_sales(self, **query: typing.Any) -> list[Sale]:
|
343
|
+
"""
|
344
|
+
Récupère une liste d'annonces en fonction d'une requête.
|
345
|
+
|
346
|
+
## Paramètres
|
347
|
+
query: `**dict`\n
|
348
|
+
La requête pour filtrer les annonces.
|
349
|
+
|
350
|
+
## Renvoie
|
351
|
+
- `list[.Sale]`
|
352
|
+
"""
|
353
|
+
|
354
|
+
query = "&".join(f"{k}={ urllib.parse.quote(v) }" for k, v in query.items())
|
355
|
+
|
356
|
+
_res = requests.get(f"{self.url}/fetch/sales?{query}", headers = self.default_headers)
|
357
|
+
|
358
|
+
if _res.status_code == 200:
|
359
|
+
_data = _res.json()
|
360
|
+
else:
|
361
|
+
_res.raise_for_status()
|
362
|
+
return []
|
363
|
+
|
364
|
+
res = []
|
365
|
+
|
366
|
+
for _sale in _data:
|
367
|
+
if not _sale: continue
|
368
|
+
|
369
|
+
sale = Sale()
|
370
|
+
|
371
|
+
sale.id = NSID(_sale['id'])
|
372
|
+
sale._url = f"{self.url}/marketplace/sales/{sale.id}"
|
373
|
+
|
374
|
+
sale._load(_sale)
|
375
|
+
|
376
|
+
res.append(sale)
|
377
|
+
|
378
|
+
return res
|
@@ -1,100 +0,0 @@
|
|
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')
|
@@ -1,356 +0,0 @@
|
|
1
|
-
import time
|
2
|
-
|
3
|
-
from ..cls.base import *
|
4
|
-
from ..cls.archives import *
|
5
|
-
from ..cls.economy import *
|
6
|
-
|
7
|
-
class EconomyInstance(Instance):
|
8
|
-
"""Indisponible dans cette version."""
|
9
|
-
|
10
|
-
def __init__(self, url: str, token: str) -> None:
|
11
|
-
super().__init__(url, token)
|
12
|
-
|
13
|
-
"""
|
14
|
-
---- COMPTES EN BANQUE ----
|
15
|
-
"""
|
16
|
-
|
17
|
-
def get_account(self, id: NSID) -> BankAccount:
|
18
|
-
"""
|
19
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
20
|
-
Récupère les informations d'un compte bancaire.
|
21
|
-
|
22
|
-
## Paramètres
|
23
|
-
id: `NSID`\n
|
24
|
-
ID du compte.
|
25
|
-
|
26
|
-
## Renvoie
|
27
|
-
- `.BankAccount`
|
28
|
-
"""
|
29
|
-
|
30
|
-
return BankAccount(NSID(id)) # Provisoire
|
31
|
-
|
32
|
-
id = NSID(id)
|
33
|
-
_data = self._get_by_ID('accounts', id)
|
34
|
-
|
35
|
-
if _data is None:
|
36
|
-
return None
|
37
|
-
|
38
|
-
account = BankAccount(id)
|
39
|
-
account.amount = _data['amount']
|
40
|
-
account.frozen = _data['frozen']
|
41
|
-
account.owner = NSID(_data['owner_id'])
|
42
|
-
account.bank = _data['bank']
|
43
|
-
account.income = _data['income']
|
44
|
-
|
45
|
-
return account
|
46
|
-
|
47
|
-
def save_account(self, account: BankAccount):
|
48
|
-
"""
|
49
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
50
|
-
Sauvegarde un compte bancaire dans la base de données.
|
51
|
-
|
52
|
-
## Paramètres
|
53
|
-
- account: `.BankAccount`\n
|
54
|
-
Compte à sauvegarder
|
55
|
-
"""
|
56
|
-
|
57
|
-
return # Provisoire
|
58
|
-
|
59
|
-
_data = {
|
60
|
-
'id': NSID(account.id),
|
61
|
-
'amount': account.amount,
|
62
|
-
'frozen': account.frozen,
|
63
|
-
'owner_id': account.owner,
|
64
|
-
'bank': account.bank,
|
65
|
-
'income': account.income
|
66
|
-
}
|
67
|
-
|
68
|
-
self._put_in_db('accounts', _data)
|
69
|
-
|
70
|
-
def freeze_account(self, account: BankAccount):
|
71
|
-
"""
|
72
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
73
|
-
Gèle un compte bancaire pour empêcher toute transaction.
|
74
|
-
|
75
|
-
## Paramètres
|
76
|
-
- account: `.BankAccount`\n
|
77
|
-
Compte à geler
|
78
|
-
"""
|
79
|
-
|
80
|
-
return # Provisoire
|
81
|
-
|
82
|
-
account.id = NSID(account.id)
|
83
|
-
account.frozen = True
|
84
|
-
|
85
|
-
self.save_account(account)
|
86
|
-
|
87
|
-
"""
|
88
|
-
---- OBJETS & VENTES ----
|
89
|
-
"""
|
90
|
-
|
91
|
-
def save_item(self, item: Item):
|
92
|
-
"""
|
93
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
94
|
-
Sauvegarde des infos à propos d'un item.
|
95
|
-
|
96
|
-
## Paramètres
|
97
|
-
item: `.Item`\n
|
98
|
-
Article à sauvegarder
|
99
|
-
"""
|
100
|
-
|
101
|
-
return # Provisoire
|
102
|
-
|
103
|
-
_item = item.__dict__
|
104
|
-
self._put_in_db('items', _item)
|
105
|
-
|
106
|
-
def get_item(self, id: NSID) -> Item | None:
|
107
|
-
"""
|
108
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
109
|
-
Récupère des informations à propos d'un item.
|
110
|
-
|
111
|
-
## Paramètres
|
112
|
-
id: `NSID`\n
|
113
|
-
ID de l'item
|
114
|
-
|
115
|
-
## Retourne
|
116
|
-
- `.Item` si quelque chose est trouvé, sinon
|
117
|
-
- `None`
|
118
|
-
"""
|
119
|
-
|
120
|
-
return Item(NSID(id)) # Provisoire
|
121
|
-
|
122
|
-
_item = self._get_by_ID('items', id)
|
123
|
-
|
124
|
-
if _item is None:
|
125
|
-
return
|
126
|
-
|
127
|
-
item = Item(id)
|
128
|
-
item.title = _item['title']
|
129
|
-
item.emoji = _item['emoji']
|
130
|
-
|
131
|
-
return item
|
132
|
-
|
133
|
-
def delete_item(self, item: Item):
|
134
|
-
"""
|
135
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
136
|
-
Annule le référencement d'un item.
|
137
|
-
|
138
|
-
## Paramètres
|
139
|
-
item: `.Item`\n
|
140
|
-
Item à supprimer
|
141
|
-
"""
|
142
|
-
|
143
|
-
return # Provisoire
|
144
|
-
|
145
|
-
self._delete_by_ID('items', item.id)
|
146
|
-
|
147
|
-
def get_sale(self, id: NSID) -> Sale | None:
|
148
|
-
"""
|
149
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
150
|
-
Récupère une vente disponible sur le marketplace.
|
151
|
-
|
152
|
-
## Paramètres
|
153
|
-
id: `NSID`\n
|
154
|
-
ID de la vente.
|
155
|
-
|
156
|
-
## Renvoie
|
157
|
-
- `.Sale | None`: Le résultat de la vente
|
158
|
-
"""
|
159
|
-
|
160
|
-
return Sale(NSID(id), Item(NSID(id))) # Provisoire
|
161
|
-
|
162
|
-
id = NSID(id)
|
163
|
-
|
164
|
-
_data = self._get_by_ID('market', id)
|
165
|
-
|
166
|
-
if _data is None:
|
167
|
-
return None
|
168
|
-
|
169
|
-
item = self.get_item(_data['id'])
|
170
|
-
|
171
|
-
sale = Sale(NSID(id), Item(_data['id']) if item is None else item)
|
172
|
-
sale.__dict__ = _data
|
173
|
-
|
174
|
-
return sale
|
175
|
-
|
176
|
-
def sell_item(self, item: Item, quantity: int, price: int, seller: NSID):
|
177
|
-
"""
|
178
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
179
|
-
Vend un item sur le marché.
|
180
|
-
|
181
|
-
## Paramètres
|
182
|
-
item: `.Item`\n
|
183
|
-
Item à vendre
|
184
|
-
quantity: `int`\n
|
185
|
-
Nombre d'items à vendre
|
186
|
-
price: `int`\n
|
187
|
-
Prix à l'unité de chaque objet
|
188
|
-
seller: `NSID`\n
|
189
|
-
ID de l'auteur de la vente
|
190
|
-
"""
|
191
|
-
|
192
|
-
return # Provisoire
|
193
|
-
|
194
|
-
sale = Sale(NSID(round(time.time()) * 16 ** 3), item)
|
195
|
-
sale.quantity = quantity
|
196
|
-
sale.price = price
|
197
|
-
sale.seller_id = seller
|
198
|
-
|
199
|
-
_data = sale.__dict__.copy()
|
200
|
-
|
201
|
-
self._put_in_db('market', _data)
|
202
|
-
|
203
|
-
def delete_sale(self, sale: Sale) -> None:
|
204
|
-
"""
|
205
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
206
|
-
Annule une vente sur le marketplace.
|
207
|
-
"""
|
208
|
-
|
209
|
-
return # Provisoire
|
210
|
-
|
211
|
-
sale.id = NSID(sale.id)
|
212
|
-
self._delete_by_ID('market', NSID(sale.id))
|
213
|
-
|
214
|
-
"""
|
215
|
-
---- INVENTAIRES ----
|
216
|
-
"""
|
217
|
-
|
218
|
-
def get_inventory(self, id: NSID) -> Inventory | None:
|
219
|
-
"""
|
220
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
221
|
-
Récupérer un inventaire dans la base des inventaires.
|
222
|
-
|
223
|
-
## Paramètres
|
224
|
-
id: `NSID`\n
|
225
|
-
ID du propriétaire de l'inventaire
|
226
|
-
|
227
|
-
## Retourne
|
228
|
-
- `.Inventory | None`: L'inventaire s'il a été trouvé
|
229
|
-
"""
|
230
|
-
|
231
|
-
return Inventory(NSID(id)) # Provisoire
|
232
|
-
|
233
|
-
_data = self._get_by_ID('inventories', id)
|
234
|
-
|
235
|
-
if _data is None:
|
236
|
-
return None
|
237
|
-
|
238
|
-
inventory = Inventory(id)
|
239
|
-
|
240
|
-
for _item in _data['objects']:
|
241
|
-
item = self.get_item(_item)
|
242
|
-
|
243
|
-
inventory.objects.append(item)
|
244
|
-
|
245
|
-
return inventory
|
246
|
-
|
247
|
-
def save_inventory(self, inventory: Inventory):
|
248
|
-
"""
|
249
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
250
|
-
Sauvegarder un inventaire
|
251
|
-
|
252
|
-
## Paramètres
|
253
|
-
inventory: `.Inventory`\n
|
254
|
-
Inventaire à sauvegarder
|
255
|
-
"""
|
256
|
-
|
257
|
-
return # Provisoire
|
258
|
-
|
259
|
-
_data = inventory.__dict__
|
260
|
-
|
261
|
-
self._put_in_db('inventories', _data)
|
262
|
-
|
263
|
-
def delete_inventory(self, inventory: Inventory):
|
264
|
-
"""
|
265
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
266
|
-
Supprime un inventaire
|
267
|
-
|
268
|
-
## Paramètres
|
269
|
-
inventory: `.Inventory`
|
270
|
-
Inventaire à supprimer
|
271
|
-
"""
|
272
|
-
|
273
|
-
return # Provisoire
|
274
|
-
|
275
|
-
self._delete_by_ID('inventories', inventory.owner_id)
|
276
|
-
|
277
|
-
"""
|
278
|
-
---- ARCHIVES ----
|
279
|
-
"""
|
280
|
-
|
281
|
-
def _add_archive(self, archive: Archive):
|
282
|
-
"""
|
283
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
284
|
-
Ajoute une archive d'une transaction ou d'une vente dans la base de données.
|
285
|
-
|
286
|
-
## Paramètres
|
287
|
-
- archive: `.Archive`\n
|
288
|
-
Archive à ajouter
|
289
|
-
"""
|
290
|
-
|
291
|
-
return # Provisoire
|
292
|
-
|
293
|
-
archive.id = NSID(archive.id)
|
294
|
-
archive.author = NSID(archive.author)
|
295
|
-
archive.target = NSID(archive.target)
|
296
|
-
|
297
|
-
_data = archive.__dict__.copy()
|
298
|
-
|
299
|
-
if type(archive) == Transaction:
|
300
|
-
_data['_type'] = "transaction"
|
301
|
-
else:
|
302
|
-
_data['_type'] = "action"
|
303
|
-
|
304
|
-
self._put_in_db('archives', _data)
|
305
|
-
|
306
|
-
def _get_archive(self, id: NSID) -> Archive | Transaction:
|
307
|
-
"""
|
308
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
309
|
-
Récupère une archive spécifique.
|
310
|
-
|
311
|
-
## Paramètres
|
312
|
-
id: `NSID`\n
|
313
|
-
ID de l'archive.
|
314
|
-
|
315
|
-
## Renvoie
|
316
|
-
- `.Archive | .Transaction`
|
317
|
-
"""
|
318
|
-
|
319
|
-
return Archive() # Provisoire
|
320
|
-
|
321
|
-
id = NSID(id)
|
322
|
-
_data = self._get_by_ID('archives', id)
|
323
|
-
|
324
|
-
if _data is None:
|
325
|
-
return None
|
326
|
-
|
327
|
-
if _data['_type'] == "transaction":
|
328
|
-
archive = Transaction(_data['author'], _data['target'])
|
329
|
-
else:
|
330
|
-
archive = Archive(_data['author'], _data['target'])
|
331
|
-
|
332
|
-
archive.id = id
|
333
|
-
archive.action = _data['action']
|
334
|
-
archive.date = _data['date']
|
335
|
-
archive.details = _data['details']
|
336
|
-
|
337
|
-
return archive
|
338
|
-
|
339
|
-
def _fetch_archives(self, **query) -> list[ Archive | Transaction ]:
|
340
|
-
"""
|
341
|
-
*INDISPONIBLE DANS CETTE VERSION.*\n
|
342
|
-
Récupère une liste d'archives correspondant à la requête.
|
343
|
-
|
344
|
-
## Paramètres
|
345
|
-
query: `dict`\n
|
346
|
-
Requête pour filtrer les archives.
|
347
|
-
|
348
|
-
## Renvoie
|
349
|
-
- `list[.Archive | .Transaction]`
|
350
|
-
"""
|
351
|
-
|
352
|
-
return [] # Provisoire
|
353
|
-
|
354
|
-
_res = self.fetch('archives', **query)
|
355
|
-
|
356
|
-
return [ self._get_archive(archive['id']) for archive in _res ]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|