nsarchive 3.0.0a7__py3-none-any.whl → 3.0.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nsarchive/__init__.py +17 -10
- nsarchive/{instances → interfaces}/_economy.py +15 -30
- nsarchive/interfaces/_entities.py +206 -0
- nsarchive/interfaces/_justice.py +122 -0
- nsarchive/interfaces/_state.py +196 -0
- nsarchive/mandate.py +50 -0
- nsarchive/{cls → models}/base.py +28 -7
- nsarchive/{cls → models}/economy.py +34 -14
- nsarchive/{cls → models}/entities.py +143 -77
- nsarchive/models/justice.py +108 -0
- nsarchive/models/republic.py +128 -0
- nsarchive/models/scale.py +23 -0
- nsarchive/models/state.py +75 -0
- {nsarchive-3.0.0a7.dist-info → nsarchive-3.0.0b1.dist-info}/METADATA +3 -2
- nsarchive-3.0.0b1.dist-info/RECORD +19 -0
- {nsarchive-3.0.0a7.dist-info → nsarchive-3.0.0b1.dist-info}/WHEEL +1 -1
- nsarchive/cls/archives.py +0 -93
- nsarchive/cls/republic.py +0 -149
- nsarchive/instances/_entities.py +0 -281
- nsarchive/instances/_republic.py +0 -339
- nsarchive-3.0.0a7.dist-info/RECORD +0 -15
- {nsarchive-3.0.0a7.dist-info → nsarchive-3.0.0b1.dist-info}/LICENSE +0 -0
nsarchive/mandate.py
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
import math
|
2
|
+
import time
|
3
|
+
|
4
|
+
EPOCH = 1577833200 # 1er Janvier 2020
|
5
|
+
PATIENTAGE_DATE = 1725141600 # 1er Septembre 2024
|
6
|
+
OPEN_DATE = 1756677600 # 1er Septembre 2025
|
7
|
+
|
8
|
+
MANDATE_DURATION = 2419200
|
9
|
+
|
10
|
+
def get_cycle(ts: int = round(time.time())):
|
11
|
+
if EPOCH <= ts < PATIENTAGE_DATE:
|
12
|
+
return 0
|
13
|
+
elif PATIENTAGE_DATE <= ts < OPEN_DATE:
|
14
|
+
return 1
|
15
|
+
elif OPEN_DATE <= ts:
|
16
|
+
return math.floor((ts - OPEN_DATE) / MANDATE_DURATION) + 2
|
17
|
+
else:
|
18
|
+
raise ValueError(f"Timestamp {ts} is out of range (must be greater than or equal to {EPOCH}).")
|
19
|
+
|
20
|
+
def get_day(ts: int = round(time.time())) -> int:
|
21
|
+
cycle = get_cycle(ts)
|
22
|
+
|
23
|
+
if cycle == 0:
|
24
|
+
return math.floor((ts - EPOCH) / 86400)
|
25
|
+
elif cycle == 1:
|
26
|
+
return math.floor((ts - PATIENTAGE_DATE) / 86400)
|
27
|
+
else:
|
28
|
+
return math.floor(((ts - OPEN_DATE) % MANDATE_DURATION) / 86400)
|
29
|
+
|
30
|
+
def get_phase(ts: int = round(time.time())) -> str:
|
31
|
+
cycle = get_cycle(ts)
|
32
|
+
|
33
|
+
if cycle < 2: # Les deux premiers cycles durent (beaucoup) plus longtemps qu'un cycle normal.
|
34
|
+
return 'undefined'
|
35
|
+
|
36
|
+
day = get_day(ts)
|
37
|
+
|
38
|
+
if day == 0:
|
39
|
+
return 'investiture' # Investiture du PR
|
40
|
+
elif 1 <= day < 24:
|
41
|
+
return 'paix' # Rien du tout
|
42
|
+
elif 24 <= day < 28:
|
43
|
+
return 'partials' # Élections législatives
|
44
|
+
elif 28 <= day < 52:
|
45
|
+
return 'paix' # Toujours rien
|
46
|
+
elif 52 <= day < 56:
|
47
|
+
return 'elections' # Élections législatives et présidentielles
|
48
|
+
|
49
|
+
else:
|
50
|
+
raise ValueError(f"Idk what happened but it seems that {day} is greater than 55...")
|
nsarchive/{cls → models}/base.py
RENAMED
@@ -1,4 +1,3 @@
|
|
1
|
-
import io
|
2
1
|
import json
|
3
2
|
import requests
|
4
3
|
import typing
|
@@ -40,23 +39,28 @@ class NSID(str):
|
|
40
39
|
if value.startswith("0x"):
|
41
40
|
value = value[2:]
|
42
41
|
|
43
|
-
|
44
|
-
return
|
42
|
+
interface = super(NSID, cls).__new__(cls, value.upper())
|
43
|
+
return interface
|
45
44
|
|
46
|
-
class
|
45
|
+
class Interface:
|
47
46
|
"""
|
48
|
-
Instance qui servira de base à toutes les
|
47
|
+
Instance qui servira de base à toutes les interfaces.
|
49
48
|
"""
|
50
49
|
|
51
50
|
def __init__(self, url: str, token: str = None):
|
52
51
|
self.url = url
|
53
52
|
self.token = token
|
53
|
+
self.zone = 20 # 10 = Serveur test, 20 = Serveur principal, 30 = Serveur de patientage, 40 = Scratch World
|
54
54
|
|
55
55
|
self.default_headers = {
|
56
56
|
"Authorization": f"Bearer {self.token}",
|
57
57
|
"Content-Type": "application/json",
|
58
58
|
}
|
59
59
|
|
60
|
+
return
|
61
|
+
|
62
|
+
# Vérification (ralentit considérablement les requêtes)*
|
63
|
+
|
60
64
|
try:
|
61
65
|
test_res = requests.get(f'{self.url}/ping')
|
62
66
|
|
@@ -71,6 +75,24 @@ class Instance:
|
|
71
75
|
except:
|
72
76
|
utils.warn("NationDB is not responding.")
|
73
77
|
|
78
|
+
def alias(self, alias: NSID) -> typing.Self:
|
79
|
+
"""
|
80
|
+
Duplique l'interface en se faisant passer pour une autre entité. Aucune erreur ne sera levée si l'entité n'existe pas (hormis les éventuels 401 ou 404 renvoyés par le serveur).
|
81
|
+
|
82
|
+
## Paramètres
|
83
|
+
alias: `NSID`\n
|
84
|
+
ID de l'entité à simuler
|
85
|
+
|
86
|
+
## Renvoie
|
87
|
+
- `self` avec le token de l'alias
|
88
|
+
"""
|
89
|
+
|
90
|
+
alias = NSID(alias)
|
91
|
+
|
92
|
+
token = self.token + ':' + str(alias)
|
93
|
+
|
94
|
+
return self.__class__(self.url, token)
|
95
|
+
|
74
96
|
def request_token(self, username: str, password: str) -> str | None:
|
75
97
|
res = requests.post(f"{self.url}/auth/login", json = {
|
76
98
|
"username": username,
|
@@ -120,7 +142,7 @@ class Instance:
|
|
120
142
|
|
121
143
|
return _data
|
122
144
|
|
123
|
-
def _put_in_db(self, endpoint: str, body: dict, headers: dict = None, use_PUT: bool = False) -> None:
|
145
|
+
def _put_in_db(self, endpoint: str, body: dict = {}, headers: dict = None, use_PUT: bool = False) -> None:
|
124
146
|
"""
|
125
147
|
Publie des données JSON dans une table nation-db.
|
126
148
|
|
@@ -144,7 +166,6 @@ class Instance:
|
|
144
166
|
if 200 <= res.status_code < 300:
|
145
167
|
return res.json()
|
146
168
|
else:
|
147
|
-
print(res.text)
|
148
169
|
res.raise_for_status()
|
149
170
|
|
150
171
|
def _delete(self, _class: str, ids: list[NSID]) -> None:
|
@@ -4,7 +4,6 @@ import urllib
|
|
4
4
|
|
5
5
|
from .base import NSID
|
6
6
|
|
7
|
-
default_headers = {}
|
8
7
|
|
9
8
|
class BankAccount:
|
10
9
|
"""
|
@@ -27,6 +26,7 @@ class BankAccount:
|
|
27
26
|
|
28
27
|
def __init__(self, owner_id: NSID) -> None:
|
29
28
|
self._url: str = ""
|
29
|
+
self._headers: dict = {}
|
30
30
|
|
31
31
|
self.id: NSID = NSID(owner_id)
|
32
32
|
self.owner_id: NSID = NSID(owner_id)
|
@@ -40,7 +40,12 @@ class BankAccount:
|
|
40
40
|
self.frozen: bool = False
|
41
41
|
self.flagged: bool = False
|
42
42
|
|
43
|
-
def _load(self, _data: dict):
|
43
|
+
def _load(self, _data: dict, url: str, headers: dict) -> None:
|
44
|
+
self._url = url + '/bank/accounts/' + _data['id']
|
45
|
+
self._headers = headers
|
46
|
+
|
47
|
+
self.id = NSID(_data['id'])
|
48
|
+
|
44
49
|
self.owner_id = NSID(_data['owner_id'])
|
45
50
|
self.register_date = _data['register_date']
|
46
51
|
self.tag = _data['tag']
|
@@ -53,18 +58,17 @@ class BankAccount:
|
|
53
58
|
self.flagged = _data['flagged']
|
54
59
|
|
55
60
|
def freeze(self, frozen: bool = True, reason: str = None) -> None:
|
56
|
-
res = requests.post(f"{self._url}/freeze?frozen={str(frozen).lower()}", headers =
|
61
|
+
res = requests.post(f"{self._url}/freeze?frozen={str(frozen).lower()}", headers = self._headers, json = {
|
57
62
|
"reason": reason
|
58
63
|
})
|
59
64
|
|
60
65
|
if res.status_code == 200:
|
61
66
|
self.frozen = frozen
|
62
67
|
else:
|
63
|
-
print(res.text)
|
64
68
|
res.raise_for_status()
|
65
69
|
|
66
70
|
def flag(self, flagged: bool = True, reason: str = None) -> None:
|
67
|
-
res = requests.post(f"{self._url}/flag?flagged={str(flagged).lower()}", headers =
|
71
|
+
res = requests.post(f"{self._url}/flag?flagged={str(flagged).lower()}", headers = self._headers, json = {
|
68
72
|
"reason": reason
|
69
73
|
})
|
70
74
|
|
@@ -77,7 +81,7 @@ class BankAccount:
|
|
77
81
|
_target_query = f"&target={target}"
|
78
82
|
_loan_query = f"&loan_id={loan}"
|
79
83
|
|
80
|
-
res = requests.post(f"{self._url}/debit?amount={amount}{_target_query if target else ''}{_loan_query if loan else ''}", headers =
|
84
|
+
res = requests.post(f"{self._url}/debit?amount={amount}{_target_query if target else ''}{_loan_query if loan else ''}", headers = self._headers, json = {
|
81
85
|
"reason": reason,
|
82
86
|
"digicode": digicode
|
83
87
|
})
|
@@ -88,7 +92,7 @@ class BankAccount:
|
|
88
92
|
res.raise_for_status()
|
89
93
|
|
90
94
|
def deposit(self, amount: int, reason: str = None) -> None:
|
91
|
-
res = requests.post(f"{self._url}/deposit?amount={amount}", headers =
|
95
|
+
res = requests.post(f"{self._url}/deposit?amount={amount}", headers = self._headers, json = {
|
92
96
|
"reason": reason,
|
93
97
|
})
|
94
98
|
|
@@ -111,20 +115,28 @@ class Item:
|
|
111
115
|
"""
|
112
116
|
|
113
117
|
def __init__(self) -> None:
|
118
|
+
self._url: str = ""
|
119
|
+
self._headers: dict = {}
|
120
|
+
|
114
121
|
self.id: NSID = NSID(round(time.time()))
|
115
122
|
self.name: str = "Unknown Object"
|
116
123
|
self.emoji: str = ":light_bulb:"
|
117
124
|
self.category: str = "common"
|
118
125
|
self.craft: dict = {}
|
119
126
|
|
120
|
-
def _load(self, _data: dict):
|
127
|
+
def _load(self, _data: dict, url: str, headers: dict) -> None:
|
128
|
+
self._url = url + '/marketplace/items/' + _data['id']
|
129
|
+
self._headers = headers
|
130
|
+
|
131
|
+
self.id = NSID(_data['id'])
|
132
|
+
|
121
133
|
self.name = _data['name']
|
122
134
|
self.emoji = _data['emoji']
|
123
135
|
self.category = _data['category']
|
124
136
|
self.craft = _data['craft']
|
125
137
|
|
126
138
|
def rename(self, new_name: str):
|
127
|
-
res = requests.post(f"{self._url}/rename?name={new_name}", headers =
|
139
|
+
res = requests.post(f"{self._url}/rename?name={new_name}", headers = self._headers)
|
128
140
|
|
129
141
|
if res.status_code == 200:
|
130
142
|
self.name = new_name
|
@@ -150,6 +162,7 @@ class Sale:
|
|
150
162
|
|
151
163
|
def __init__(self, item: Item) -> None:
|
152
164
|
self._url: str = ""
|
165
|
+
self._headers: dict = {}
|
153
166
|
|
154
167
|
self.id: NSID = NSID(round(time.time()))
|
155
168
|
self.open: bool = True
|
@@ -159,8 +172,11 @@ class Sale:
|
|
159
172
|
self.quantity: int = 1
|
160
173
|
self.price: int = 0
|
161
174
|
|
162
|
-
def _load(self, _data: dict):
|
163
|
-
self.
|
175
|
+
def _load(self, _data: dict, url: str, headers: dict) -> None:
|
176
|
+
self._url = url + '/marketplace/sales/' + _data['id']
|
177
|
+
self._headers = headers
|
178
|
+
|
179
|
+
self.id = _data['id']
|
164
180
|
self.open = _data['open']
|
165
181
|
self.seller_id = NSID(_data['seller_id'])
|
166
182
|
|
@@ -187,6 +203,7 @@ class Inventory:
|
|
187
203
|
|
188
204
|
def __init__(self, owner_id: NSID) -> None:
|
189
205
|
self._url: str = ""
|
206
|
+
self._headers: dict = {}
|
190
207
|
|
191
208
|
self.id: NSID = NSID(owner_id)
|
192
209
|
self.owner_id: NSID = NSID(owner_id)
|
@@ -196,7 +213,10 @@ class Inventory:
|
|
196
213
|
|
197
214
|
self.items: dict[NSID, int] = {}
|
198
215
|
|
199
|
-
def _load(self, _data: dict):
|
216
|
+
def _load(self, _data: dict, url: str, headers: dict):
|
217
|
+
self._url = url + '/bank/inventories/' + _data['id']
|
218
|
+
self._headers = headers
|
219
|
+
|
200
220
|
self.id = NSID(_data['id'])
|
201
221
|
self.owner_id = NSID(_data['owner_id'])
|
202
222
|
|
@@ -206,7 +226,7 @@ class Inventory:
|
|
206
226
|
self.items = _data['items']
|
207
227
|
|
208
228
|
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 =
|
229
|
+
res = requests.post(f"{self._url}/deposit?item={item.id}&amount={quantity}", headers = self._headers, json = {
|
210
230
|
"giver": giver,
|
211
231
|
"digicode": digicode
|
212
232
|
})
|
@@ -220,7 +240,7 @@ class Inventory:
|
|
220
240
|
res.raise_for_status()
|
221
241
|
|
222
242
|
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 =
|
243
|
+
res = requests.post(f"{self._url}/sell_item?item={item.id}&quantity={quantity}&price={price}", headers = self._headers, json = {
|
224
244
|
"digicode": digicode
|
225
245
|
})
|
226
246
|
|