nsarchive 1.2.7__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 CHANGED
@@ -200,6 +200,9 @@ class EntityInstance:
200
200
  groups.remove(group)
201
201
  continue
202
202
 
203
+ if group.owner.id == id:
204
+ continue
205
+
203
206
  for member in group.members:
204
207
  if member.id == id:
205
208
  break
@@ -252,7 +255,7 @@ class EntityInstance:
252
255
  _data['type'] = "report"
253
256
  else:
254
257
  _data['type'] = "unknown"
255
-
258
+
256
259
  self.archives.put(key = archive.id, data = _data)
257
260
 
258
261
  def _get_archive(self, id: str | NSID) -> Action | Sanction | AdminAction:
@@ -272,7 +275,7 @@ class EntityInstance:
272
275
 
273
276
  if _data is None:
274
277
  return None
275
-
278
+
276
279
  if _data['type'] == "sanction": # Mute, ban, GAV, kick, détention, prune (xp seulement)
277
280
  archive = Sanction(_data['author'], _data['target'])
278
281
 
@@ -585,6 +588,7 @@ class BankInstance:
585
588
  self.accounts = self.db.Base('accounts')
586
589
  self.registry = self.db.Base('banks')
587
590
  self.marketplace = self.db.Base('shop')
591
+ self.inventories = self.db.Base('inventories')
588
592
 
589
593
  def get_account(self, id: str | NSID) -> BankAccount:
590
594
  """
@@ -632,9 +636,9 @@ class BankInstance:
632
636
 
633
637
  self.save_account(account)
634
638
 
635
- def get_item(self, id: str | NSID) -> Item | None:
639
+ def get_sale(self, id: str | NSID) -> Sale | None:
636
640
  """
637
- Récupère un item du marché.
641
+ Récupère une vente disponible sur le marketplace.
638
642
 
639
643
  ## Paramètres
640
644
  id: `str | NSID`
@@ -651,28 +655,98 @@ class BankInstance:
651
655
  if _data is None:
652
656
  return None
653
657
 
654
- item = Item(id)
655
- item.title = _data['title']
656
- item.emoji = _data['emoji']
657
- item.seller_id = _data['seller']
658
- item.price = _data['price']
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
+ """
679
+
680
+ sale = Sale(NSID(round(time.time()) * 16 ** 3), item)
681
+ sale.quantity = quantity
682
+ sale.price = price
683
+ sale.seller_id = seller
659
684
 
660
- return item
685
+ _data = sale.__dict__.copy()
686
+ del _data['id']
661
687
 
662
- def save_item(self, item: Item) -> None:
663
- """Sauvegarde un item dans la base de données du marché."""
688
+ self.marketplace.put(key = sale.id, data = _data)
664
689
 
665
- item.id = NSID(item.id)
690
+ def delete_sale(self, sale: Sale) -> None:
691
+ """Annule une vente sur le marketplace."""
666
692
 
667
- _data = item.__dict__.copy()
693
+ sale.id = NSID(sale.id)
694
+ self.marketplace.delete(sale.id)
668
695
 
669
- self.marketplace.put(key = item.id, data = _data)
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
670
711
 
671
- def delete_item(self, item: Item) -> None:
672
- """Supprime un item du marché."""
712
+ inventory = Inventory(id)
673
713
 
674
- item.id = NSID(item.id)
675
- self.marketplace.delete(item.id)
714
+ del _data['key']
715
+
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)
676
750
 
677
751
  def _add_archive(self, archive: Action):
678
752
  """Ajoute une archive d'une transaction ou d'une vente dans la base de données."""
@@ -686,8 +760,6 @@ class BankInstance:
686
760
  if type(archive) == Transaction:
687
761
  _data['type'] = "transaction"
688
762
  archive.currency = archive.currency.upper()
689
- elif type(archive) == Sale:
690
- _data['type'] = "sale"
691
763
  else:
692
764
  _data['type'] = "unknown"
693
765
 
@@ -716,10 +788,6 @@ class BankInstance:
716
788
 
717
789
  archive.reason = _data['reason']
718
790
  archive.currency = _data['currency']
719
- elif _data['type'] == "sale":
720
- archive = Sale(_data['author'], _data['target'])
721
-
722
- archive.price = _data['price']
723
791
  else:
724
792
  archive = Action(_data['author'], _data['target'])
725
793
 
@@ -740,7 +808,7 @@ class BankInstance:
740
808
  ## Renvoie
741
809
  - `list[Action | Transaction]`
742
810
  """
743
-
811
+
744
812
  _res = self.archives.fetch(query).items
745
813
 
746
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
- self.seller_id: NSID = NSID(0)
20
- self.price: int = 0
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nsarchive
3
- Version: 1.2.7
3
+ Version: 1.3.0
4
4
  Summary:
5
5
  License: GPL-3.0
6
6
  Author: happex
@@ -1,13 +1,13 @@
1
- nsarchive/__init__.py,sha256=em_ZUYYNq0FQ5ggy_ArfJm_PpnAVx3IebsFs7X-uwi8,25361
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=Nmt3C0Zq9oGQdCXSzm_wo70VbNq89SY3dx9KKqEpoCg,2182
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=RjFu3VzNunazslbd4Ia5p1Jr-jJP5CvIcbVOzkDTwTU,549
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.2.7.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
11
- nsarchive-1.2.7.dist-info/METADATA,sha256=tleGPFqAzbaDj0MV1_15VEZm4j4hyHULz6InJS0XWSw,5629
12
- nsarchive-1.2.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
- nsarchive-1.2.7.dist-info/RECORD,,
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,,