nsarchive 1.2.8__py3-none-any.whl → 1.3.0__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 +91 -26
- nsarchive/cls/archives.py +1 -7
- nsarchive/cls/economy.py +24 -2
- {nsarchive-1.2.8.dist-info → nsarchive-1.3.0.dist-info}/METADATA +1 -1
- {nsarchive-1.2.8.dist-info → nsarchive-1.3.0.dist-info}/RECORD +7 -7
- {nsarchive-1.2.8.dist-info → nsarchive-1.3.0.dist-info}/LICENSE +0 -0
- {nsarchive-1.2.8.dist-info → nsarchive-1.3.0.dist-info}/WHEEL +0 -0
nsarchive/__init__.py
CHANGED
@@ -255,7 +255,7 @@ class EntityInstance:
|
|
255
255
|
_data['type'] = "report"
|
256
256
|
else:
|
257
257
|
_data['type'] = "unknown"
|
258
|
-
|
258
|
+
|
259
259
|
self.archives.put(key = archive.id, data = _data)
|
260
260
|
|
261
261
|
def _get_archive(self, id: str | NSID) -> Action | Sanction | AdminAction:
|
@@ -275,7 +275,7 @@ class EntityInstance:
|
|
275
275
|
|
276
276
|
if _data is None:
|
277
277
|
return None
|
278
|
-
|
278
|
+
|
279
279
|
if _data['type'] == "sanction": # Mute, ban, GAV, kick, détention, prune (xp seulement)
|
280
280
|
archive = Sanction(_data['author'], _data['target'])
|
281
281
|
|
@@ -588,6 +588,7 @@ class BankInstance:
|
|
588
588
|
self.accounts = self.db.Base('accounts')
|
589
589
|
self.registry = self.db.Base('banks')
|
590
590
|
self.marketplace = self.db.Base('shop')
|
591
|
+
self.inventories = self.db.Base('inventories')
|
591
592
|
|
592
593
|
def get_account(self, id: str | NSID) -> BankAccount:
|
593
594
|
"""
|
@@ -635,9 +636,9 @@ class BankInstance:
|
|
635
636
|
|
636
637
|
self.save_account(account)
|
637
638
|
|
638
|
-
def
|
639
|
+
def get_sale(self, id: str | NSID) -> Sale | None:
|
639
640
|
"""
|
640
|
-
Récupère
|
641
|
+
Récupère une vente disponible sur le marketplace.
|
641
642
|
|
642
643
|
## Paramètres
|
643
644
|
id: `str | NSID`
|
@@ -654,28 +655,98 @@ class BankInstance:
|
|
654
655
|
if _data is None:
|
655
656
|
return None
|
656
657
|
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
658
|
+
sale = Sale(NSID(id))
|
659
|
+
|
660
|
+
del _data['key']
|
661
|
+
sale.__dict__ = _data
|
662
|
+
|
663
|
+
return sale
|
664
|
+
|
665
|
+
def sell_item(self, item: Item, quantity: int, price: int, seller: NSID) -> None:
|
666
|
+
"""
|
667
|
+
Vend un item sur le marché.
|
668
|
+
|
669
|
+
## Paramètres
|
670
|
+
item: `.Item`
|
671
|
+
Item à vendre
|
672
|
+
quantity: `int`
|
673
|
+
Nombre d'items à vendre
|
674
|
+
price: `int`
|
675
|
+
Prix à l'unité de chaque objet
|
676
|
+
seller: `NSID`
|
677
|
+
ID de l'auteur de la vente
|
678
|
+
"""
|
662
679
|
|
663
|
-
|
680
|
+
sale = Sale(NSID(round(time.time()) * 16 ** 3), item)
|
681
|
+
sale.quantity = quantity
|
682
|
+
sale.price = price
|
683
|
+
sale.seller_id = seller
|
664
684
|
|
665
|
-
|
666
|
-
|
685
|
+
_data = sale.__dict__.copy()
|
686
|
+
del _data['id']
|
667
687
|
|
668
|
-
|
688
|
+
self.marketplace.put(key = sale.id, data = _data)
|
669
689
|
|
670
|
-
|
690
|
+
def delete_sale(self, sale: Sale) -> None:
|
691
|
+
"""Annule une vente sur le marketplace."""
|
692
|
+
|
693
|
+
sale.id = NSID(sale.id)
|
694
|
+
self.marketplace.delete(sale.id)
|
695
|
+
|
696
|
+
def get_inventory(self, id: NSID) -> Inventory | None:
|
697
|
+
"""
|
698
|
+
Récupérer un inventaire dans la base des inventaires.
|
699
|
+
|
700
|
+
## Paramètres
|
701
|
+
id: `NSID`
|
702
|
+
ID du propriétaire de l'inventaire
|
703
|
+
|
704
|
+
## Retourne
|
705
|
+
- `.Inventory | None`
|
706
|
+
"""
|
707
|
+
_data = self.inventories.get(id)
|
708
|
+
|
709
|
+
if _data is None:
|
710
|
+
return None
|
671
711
|
|
672
|
-
|
712
|
+
inventory = Inventory(id)
|
673
713
|
|
674
|
-
|
675
|
-
"""Supprime un item du marché."""
|
714
|
+
del _data['key']
|
676
715
|
|
677
|
-
|
678
|
-
|
716
|
+
for _item in _data['objects']:
|
717
|
+
item = Item(_item['id'])
|
718
|
+
item.__dict__ = _item
|
719
|
+
|
720
|
+
inventory.objects.append(item)
|
721
|
+
|
722
|
+
return inventory
|
723
|
+
|
724
|
+
def save_inventory(self, inventory: Inventory) -> None:
|
725
|
+
"""
|
726
|
+
Sauvegarder un inventaire
|
727
|
+
|
728
|
+
## Paramètres
|
729
|
+
inventory: `.Inventory`
|
730
|
+
Inventaire à sauvegarder
|
731
|
+
"""
|
732
|
+
|
733
|
+
_data = {
|
734
|
+
"owner_id": inventory.owner_id,
|
735
|
+
"objects": [ object.__dict__ for object in inventory.objects ]
|
736
|
+
}
|
737
|
+
|
738
|
+
self.inventories.put(key = inventory.owner_id, data = _data)
|
739
|
+
|
740
|
+
def delete_inventory(self, inventory: Inventory) -> None:
|
741
|
+
"""
|
742
|
+
Supprime un inventaire
|
743
|
+
|
744
|
+
## Paramètres
|
745
|
+
inventory: `.Inventory`
|
746
|
+
Inventaire à supprimer
|
747
|
+
"""
|
748
|
+
|
749
|
+
self.inventories.delete(inventory.id)
|
679
750
|
|
680
751
|
def _add_archive(self, archive: Action):
|
681
752
|
"""Ajoute une archive d'une transaction ou d'une vente dans la base de données."""
|
@@ -689,8 +760,6 @@ class BankInstance:
|
|
689
760
|
if type(archive) == Transaction:
|
690
761
|
_data['type'] = "transaction"
|
691
762
|
archive.currency = archive.currency.upper()
|
692
|
-
elif type(archive) == Sale:
|
693
|
-
_data['type'] = "sale"
|
694
763
|
else:
|
695
764
|
_data['type'] = "unknown"
|
696
765
|
|
@@ -719,10 +788,6 @@ class BankInstance:
|
|
719
788
|
|
720
789
|
archive.reason = _data['reason']
|
721
790
|
archive.currency = _data['currency']
|
722
|
-
elif _data['type'] == "sale":
|
723
|
-
archive = Sale(_data['author'], _data['target'])
|
724
|
-
|
725
|
-
archive.price = _data['price']
|
726
791
|
else:
|
727
792
|
archive = Action(_data['author'], _data['target'])
|
728
793
|
|
@@ -743,7 +808,7 @@ class BankInstance:
|
|
743
808
|
## Renvoie
|
744
809
|
- `list[Action | Transaction]`
|
745
810
|
"""
|
746
|
-
|
811
|
+
|
747
812
|
_res = self.archives.fetch(query).items
|
748
813
|
|
749
814
|
return [ self._get_archive(archive['key']) for archive in _res ]
|
nsarchive/cls/archives.py
CHANGED
@@ -67,10 +67,4 @@ class Transaction(Action):
|
|
67
67
|
|
68
68
|
self.amount: int = amount
|
69
69
|
self.currency: str = 'HC'
|
70
|
-
self.reason: str = None
|
71
|
-
|
72
|
-
class Sale(Action):
|
73
|
-
def __init__(self, author: str | NSID = '0', target: str | NSID = '0') -> None:
|
74
|
-
super().__init__(author, target)
|
75
|
-
|
76
|
-
self.price: int = 0
|
70
|
+
self.reason: str = None
|
nsarchive/cls/economy.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
from nsarchive.cls.base import NSID
|
1
2
|
from .base import *
|
2
3
|
|
3
4
|
class BankAccount:
|
@@ -16,5 +17,26 @@ class Item:
|
|
16
17
|
self.title: str = "Unknown Object"
|
17
18
|
self.emoji: str = ":light_bulb:"
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
class Inventory:
|
21
|
+
def __init__(self, owner_id: NSID) -> None:
|
22
|
+
self.owner_id: NSID = NSID(owner_id)
|
23
|
+
self.objects: list[Item] = []
|
24
|
+
|
25
|
+
def append(self, item: Item, quantity: int = 1):
|
26
|
+
self.objects.extend(quantity * [item])
|
27
|
+
|
28
|
+
def throw(self, item: Item, quantity: int = 1):
|
29
|
+
if quantity > self.objects.count(item):
|
30
|
+
quantity = self.objects.count(item)
|
31
|
+
|
32
|
+
for i in range(quantity):
|
33
|
+
self.objects.remove(item)
|
34
|
+
|
35
|
+
class Sale:
|
36
|
+
def __init__(self, id: NSID, item: Item) -> None:
|
37
|
+
self.id: NSID = NSID(id)
|
38
|
+
self.item: NSID = NSID(item.id)
|
39
|
+
self.quantity: int = 1
|
40
|
+
|
41
|
+
self.price: int = 0
|
42
|
+
self.seller_id: NSID = NSID('0')
|
@@ -1,13 +1,13 @@
|
|
1
|
-
nsarchive/__init__.py,sha256=
|
1
|
+
nsarchive/__init__.py,sha256=idTG-9WiUJZ6rkkRXwjBvt_lC-lOKyz6eSS22vSMi3k,27011
|
2
2
|
nsarchive/assets/default_avatar.png,sha256=n-4vG_WPke8LvbY3ZU6oA-H-OtRoIu7woKnRq9DCIlI,51764
|
3
|
-
nsarchive/cls/archives.py,sha256=
|
3
|
+
nsarchive/cls/archives.py,sha256=i4R7NPYXX_1oi0oLAvL_4SqyjqPutXSXKysUetE6hME,2001
|
4
4
|
nsarchive/cls/base.py,sha256=DGDm0uD96M00-qvdKsltU9kAfAOBr85Ov0b18gTnoIM,714
|
5
|
-
nsarchive/cls/economy.py,sha256=
|
5
|
+
nsarchive/cls/economy.py,sha256=JpNB06JHek4uUapdk89-SR3DEoSyxXPn8OqZJkOZH_E,1252
|
6
6
|
nsarchive/cls/entities.py,sha256=Rvu2Q1mTWqQ-z92j-OXhoXSWked7p4tOCJm0gIlnP9c,6179
|
7
7
|
nsarchive/cls/exceptions.py,sha256=QN6Qn7cxTkGoC4lO50hBAq4gZCgo7scQvCkb-xKl6Xs,692
|
8
8
|
nsarchive/cls/republic.py,sha256=6eut6OsFoOm9TVhA41fM3NlMEA3Uhg9TCuXgl46vFko,1985
|
9
9
|
nsarchive/utils/assets.py,sha256=hd0STSpa0yT-OJlUyI_wCYXJqcBiUMQds2pZTXNNg9c,382
|
10
|
-
nsarchive-1.
|
11
|
-
nsarchive-1.
|
12
|
-
nsarchive-1.
|
13
|
-
nsarchive-1.
|
10
|
+
nsarchive-1.3.0.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
|
11
|
+
nsarchive-1.3.0.dist-info/METADATA,sha256=kndn-qxF_P0cYEo92vaKArA1Vpgn35ao_y7poWqQFo8,5629
|
12
|
+
nsarchive-1.3.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
13
|
+
nsarchive-1.3.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|