nsarchive 0.0.8a0__py3-none-any.whl → 0.0.9a0__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 CHANGED
@@ -3,6 +3,7 @@ import time
3
3
  import deta
4
4
 
5
5
  from .cls.entities import *
6
+ from .cls.archives import *
6
7
  from .cls.votes import *
7
8
  from .cls.bank import *
8
9
 
@@ -13,6 +14,7 @@ class EntityInstance:
13
14
  self.db = deta.Deta(token)
14
15
  self.base = self.db.Base('entities')
15
16
  self.electors = self.db.Base('electors')
17
+ self.archives = self.db.Base('archives')
16
18
 
17
19
  def get_entity(self, id: str) -> User | Organization | Entity:
18
20
  id = id.upper()
@@ -63,6 +65,9 @@ class EntityInstance:
63
65
  _data['boosts'] = entity.boosts
64
66
 
65
67
  _base.put(_data, entity.id.upper(), expire_in = 3 * 31536000) # Données supprimées tous les trois ans
68
+
69
+ def delete_entity(self, entity: Entity) -> None:
70
+ self.base.delete(entity.id.upper())
66
71
 
67
72
  def get_elector(self, id: str) -> Elector:
68
73
  id = id.upper()
@@ -99,12 +104,52 @@ class EntityInstance:
99
104
  groups = self.fetch({'_type': 'organization'}, {'members': id})
100
105
 
101
106
  return [ self.get_entity(group['key']) for group in groups ]
107
+
108
+ def _add_archive(self, archive: Action):
109
+ _data = archive.__dict__.copy()
110
+
111
+ if type(archive) == ModAction:
112
+ _data['type'] = "sanction"
113
+ elif type(archive) == AdminAction:
114
+ _data['type'] = "adminaction"
115
+ else:
116
+ _data['type'] = "unknown"
117
+
118
+ del _data['id']
119
+
120
+ self.archives.put(key = archive.id, data = _data)
121
+
122
+ def _get_archive(self, id: str) -> Action | ModAction | AdminAction:
123
+ _data = self.archives.get(id)
124
+
125
+ if _data is None:
126
+ return None
127
+
128
+ if _data['type'] == "sanction": # Mute, ban, GAV, kick, détention, prune (xp seulement)
129
+ archive = ModAction(id, _data['author'], _data['target'])
130
+
131
+ archive.details = _data['details']
132
+ archive.major = _data['major']
133
+ archive.duration = _data['duration']
134
+ elif _data['type'] == "adminaction": # Renommage, promotion, démotion
135
+ archive = AdminAction(id, _data['author'], _data['target'])
102
136
 
137
+ archive.details = _data['details']
138
+ archive.new_state = _data['new_state']
139
+ else:
140
+ archive = Action(id, _data['author'], _data['target'])
141
+
142
+ archive.action = _data['action']
143
+ archive.date = _data['date']
144
+
145
+ return archive
146
+
103
147
  class RepublicInstance:
104
148
  def __init__(self, token: str) -> None:
105
149
  self.db = deta.Deta(token)
106
150
  self.votes = self.db.Base('votes')
107
151
  self.archives = self.db.Base('archives')
152
+ self.functions = self.db.base('functions') # Liste des fonctionnaires
108
153
 
109
154
  def get_vote(self, id: str) -> Vote | ClosedVote:
110
155
  id = id.upper()
@@ -139,9 +184,50 @@ class RepublicInstance:
139
184
 
140
185
  self.votes.put(_data, vote.id.upper())
141
186
 
187
+ def _add_archive(self, archive: Action):
188
+ _data = archive.__dict__.copy()
189
+
190
+ if type(archive) == Election:
191
+ _data['type'] = "election"
192
+ elif type(archive) == Promotion:
193
+ _data['type'] = "promotion"
194
+ elif type(archive) == Demotion:
195
+ _data['type'] = "demotion"
196
+ else:
197
+ _data['type'] = "unknown"
198
+
199
+ del _data['id']
200
+
201
+ self.archives.put(key = archive.id, data = _data)
202
+
203
+ def _get_archive(self, id: str) -> Action | Election | Promotion | Demotion:
204
+ _data = self.archives.get(id)
205
+
206
+ if _data is None:
207
+ return None
208
+
209
+ if _data['type'] == "election":
210
+ archive = Election(id, _data['author'], _data['target'], _data['position'])
211
+
212
+ archive.positive_votes = _data['positive_votes']
213
+ archive.total_votes = _data['total_votes']
214
+ elif _data['type'] == "adminaction": # Renommage, promotion, démotion
215
+ archive = AdminAction(id, _data['author'], _data['target'])
216
+
217
+ archive.details = _data['details']
218
+ archive.new_state = _data['new_state']
219
+ else:
220
+ archive = Action(id, _data['author'], _data['target'])
221
+
222
+ archive.action = _data['action']
223
+ archive.date = _data['date']
224
+
225
+ return archive
226
+
142
227
  class BankInstance:
143
228
  def __init__(self, token: str) -> None:
144
229
  self.db = deta.Deta(token)
230
+ self.archives = self.db.Base('archives')
145
231
  self.accounts = self.db.Base('accounts')
146
232
  self.registry = self.db.Base('banks')
147
233
 
@@ -168,4 +254,35 @@ class BankInstance:
168
254
  'bank': acc.bank
169
255
  }
170
256
 
171
- self.accounts.put(_data, acc.id.upper())
257
+ self.accounts.put(_data, acc.id.upper())
258
+
259
+ def _add_archive(self, _archive: Action):
260
+ _data = _archive.__dict__.copy()
261
+
262
+ if type(_archive) == Transaction:
263
+ _data['type'] = "transaction"
264
+ else:
265
+ _data['type'] = "unknown"
266
+
267
+ del _data['id']
268
+
269
+ self.archives.put(key = _archive.id, data = _data)
270
+
271
+ def _get_archive(self, id: str) -> Action | Transaction:
272
+ _data = self.archives.get(id)
273
+
274
+ if _data is None:
275
+ return None
276
+
277
+ if _data['type'] == "transaction":
278
+ archive = Transaction(id, _data['author'], _data['target'], _data['amount'])
279
+
280
+ archive.reason = _data['reason']
281
+ archive.currency = _data['currency']
282
+ else:
283
+ archive = Action(id, _data['author'], _data['target'])
284
+
285
+ archive.action = _data['action']
286
+ archive.date = _data['date']
287
+
288
+ return archive
nsarchive/cls/archives.py CHANGED
@@ -1,8 +1,52 @@
1
1
  class Action:
2
- def __init__(self, author: str = '11625D9061021010', target: str = '123') -> None:
2
+ def __init__(self, id: str, author: str = '11625D9061021010', target: str = '0') -> None:
3
+ self.id: str = id
4
+ self.date: int = 0
5
+ self.action: str = ""
3
6
  self.author: str = author
4
7
  self.target: str = target
5
8
 
6
- class Sanction(Action):
7
- def __init__(self, author: str, target: str) -> None:
8
- super().__init__(author, target)
9
+ # Entities
10
+
11
+ class ModAction(Action):
12
+ def __init__(self, id: str, author: str, target: str) -> None:
13
+ super().__init__(id, author, target)
14
+ self.details: str = ""
15
+ self.major: bool = False # Sanction majeure ou non
16
+ self.duration: int = 0 # Durée en secondes, 0 = définitif
17
+
18
+ class AdminAction(Action):
19
+ def __init__(self, id: str, author: str, target: str) -> None:
20
+ super().__init__(id, author, target)
21
+ self.details: str = ""
22
+ self.new_state: str | int | bool = None
23
+
24
+
25
+ # Community
26
+
27
+ class Election(Action):
28
+ def __init__(self, id: str, author: str, target: str, position: str) -> None:
29
+ super().__init__(id, author, target)
30
+ self.position: str = position
31
+ self.positive_votes: int = 0
32
+ self.total_votes: int = 0
33
+
34
+ class Promotion(Action):
35
+ def __init__(self, id: str, author: str, target: str, position: str) -> None:
36
+ super().__init__(id, author, target)
37
+ self.position: str = position
38
+
39
+ class Demotion(Action):
40
+ def __init__(self, id: str, author: str, target: str) -> None:
41
+ super().__init__(id, author, target)
42
+ self.reason: str = None
43
+
44
+ # Bank
45
+
46
+ class Transaction(Action):
47
+ def __init__(self, id: str, author: str, target: str, amount: int) -> None:
48
+ super().__init__(id, author, target)
49
+
50
+ self.amount: int = amount
51
+ self.currency: str = 'XC'
52
+ self.reason: str = None
nsarchive/cls/entities.py CHANGED
@@ -5,7 +5,7 @@ from .exceptions import *
5
5
  class Entity:
6
6
  def __init__(self, id: str):
7
7
  self.id: str = id # ID hexadécimal de l'entité
8
- self.name: str = 'Entité Inconnue'
8
+ self.name: str = "Entité Inconnue"
9
9
  self.registerDate: int = 0
10
10
  self.legalPosition: int = 'Normal'
11
11
  self.xp: int = 0
nsarchive/cls/votes.py CHANGED
@@ -7,7 +7,7 @@ class Vote:
7
7
  self.id: str = id
8
8
  self.title: str = title
9
9
  self.choices = { choice : 0 for choice in choices }
10
- self.author: str = "0"
10
+ self.author: str = '0'
11
11
  self.startDate: int = 0
12
12
  self.endDate: int = 0
13
13
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nsarchive
3
- Version: 0.0.8a0
3
+ Version: 0.0.9a0
4
4
  Summary:
5
5
  License: GPL-3.0
6
6
  Author: happex
@@ -0,0 +1,10 @@
1
+ nsarchive/__init__.py,sha256=uno-FOUWDtdaMVeufH4C7FuRq8l_dp46EgoJokI-Sm0,9516
2
+ nsarchive/cls/archives.py,sha256=FNE8U3IVgjYCUZkBoDqeyQJSHKmRjP2UAzBfmg8nK0M,1735
3
+ nsarchive/cls/bank.py,sha256=OactEpRn8PGv7BwnBUbMpzgHqrvv4yx526AMzh9uBO8,220
4
+ nsarchive/cls/entities.py,sha256=eY5Fjxt5iixvJCxDnCNbD_lIMq9ojbCLDduPqe52oWM,2556
5
+ nsarchive/cls/exceptions.py,sha256=TrH9PvHhVZi7wap9ZfBLGRWJY3OBCYgWAMnco5uadYY,420
6
+ nsarchive/cls/votes.py,sha256=q_Y_KcFoqoXWzh_FSWz-1tJH7fGdGJDCORYUOWCtdS8,502
7
+ nsarchive-0.0.9a0.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
8
+ nsarchive-0.0.9a0.dist-info/METADATA,sha256=7piU3_JrfSVGMC12pC02kwbio2JPRqLxyKlRk47bvnE,5554
9
+ nsarchive-0.0.9a0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
10
+ nsarchive-0.0.9a0.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- nsarchive/__init__.py,sha256=VQPxaG4KMatlSWZa8A_UbYmnBVIdMuqrsGFsvrIcmE4,5538
2
- nsarchive/cls/archives.py,sha256=RroqiA85YCCbj48IYDqX4PBYKxnT43jL9NWlqxSlllc,299
3
- nsarchive/cls/bank.py,sha256=OactEpRn8PGv7BwnBUbMpzgHqrvv4yx526AMzh9uBO8,220
4
- nsarchive/cls/entities.py,sha256=mhBHZBtYK1E2dfTDoFHNdw1uu5QsnOc-Utuu5EjtV7c,2556
5
- nsarchive/cls/exceptions.py,sha256=TrH9PvHhVZi7wap9ZfBLGRWJY3OBCYgWAMnco5uadYY,420
6
- nsarchive/cls/votes.py,sha256=qaWVgfhk5GBccilFSwoZ0E9qE--IX_3HuOBoQAHD2jA,502
7
- nsarchive-0.0.8a0.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
8
- nsarchive-0.0.8a0.dist-info/METADATA,sha256=J3sYVVCdRQLp1jxP3Ak2kfxoNbQ-sDBYPQcvWH7bB0c,5554
9
- nsarchive-0.0.8a0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
10
- nsarchive-0.0.8a0.dist-info/RECORD,,