nsarchive 1.2.8__py3-none-any.whl → 1.4.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
@@ -97,6 +97,12 @@ class EntityInstance:
97
97
  entity.legalPosition = _data['legalPosition'] # Métier si c'est un utilisateur, domaine professionnel si c'est un collectif
98
98
  entity.registerDate = _data['registerDate']
99
99
 
100
+ for key, value in _data.get('additional', {}):
101
+ if isinstance(value, str) and value.startswith('\n'):
102
+ entity.add_link(key, int(value[1:]))
103
+ else:
104
+ entity.add_link(key, value)
105
+
100
106
  return entity
101
107
 
102
108
  def save_entity(self, entity: Entity) -> None:
@@ -115,9 +121,16 @@ class EntityInstance:
115
121
  '_type': 'user' if type(entity) == User else 'organization' if type(entity) == Organization else 'unknown',
116
122
  'name': entity.name,
117
123
  'legalPosition': entity.legalPosition,
118
- 'registerDate': entity.registerDate
124
+ 'registerDate': entity.registerDate,
125
+ 'additional': {}
119
126
  }
120
127
 
128
+ for key, value in entity.additional.items():
129
+ if isinstance(value, int) and len(str(int)) >= 15:
130
+ _data['additional'][key] = '\n' + str(value)
131
+ elif type(value) in (str, int):
132
+ _data['additional'][key] = value
133
+
121
134
  if type(entity) == Organization:
122
135
  _data['owner_id'] = NSID(entity.owner.id) if entity.owner else NSID("0")
123
136
  _data['members'] = []
@@ -255,7 +268,7 @@ class EntityInstance:
255
268
  _data['type'] = "report"
256
269
  else:
257
270
  _data['type'] = "unknown"
258
-
271
+
259
272
  self.archives.put(key = archive.id, data = _data)
260
273
 
261
274
  def _get_archive(self, id: str | NSID) -> Action | Sanction | AdminAction:
@@ -275,7 +288,7 @@ class EntityInstance:
275
288
 
276
289
  if _data is None:
277
290
  return None
278
-
291
+
279
292
  if _data['type'] == "sanction": # Mute, ban, GAV, kick, détention, prune (xp seulement)
280
293
  archive = Sanction(_data['author'], _data['target'])
281
294
 
@@ -588,6 +601,7 @@ class BankInstance:
588
601
  self.accounts = self.db.Base('accounts')
589
602
  self.registry = self.db.Base('banks')
590
603
  self.marketplace = self.db.Base('shop')
604
+ self.inventories = self.db.Base('inventories')
591
605
 
592
606
  def get_account(self, id: str | NSID) -> BankAccount:
593
607
  """
@@ -635,9 +649,9 @@ class BankInstance:
635
649
 
636
650
  self.save_account(account)
637
651
 
638
- def get_item(self, id: str | NSID) -> Item | None:
652
+ def get_sale(self, id: str | NSID) -> Sale | None:
639
653
  """
640
- Récupère un item du marché.
654
+ Récupère une vente disponible sur le marketplace.
641
655
 
642
656
  ## Paramètres
643
657
  id: `str | NSID`
@@ -654,28 +668,98 @@ class BankInstance:
654
668
  if _data is None:
655
669
  return None
656
670
 
657
- item = Item(id)
658
- item.title = _data['title']
659
- item.emoji = _data['emoji']
660
- item.seller_id = _data['seller']
661
- item.price = _data['price']
671
+ sale = Sale(NSID(id))
672
+
673
+ del _data['key']
674
+ sale.__dict__ = _data
675
+
676
+ return sale
677
+
678
+ def sell_item(self, item: Item, quantity: int, price: int, seller: NSID) -> None:
679
+ """
680
+ Vend un item sur le marché.
681
+
682
+ ## Paramètres
683
+ item: `.Item`
684
+ Item à vendre
685
+ quantity: `int`
686
+ Nombre d'items à vendre
687
+ price: `int`
688
+ Prix à l'unité de chaque objet
689
+ seller: `NSID`
690
+ ID de l'auteur de la vente
691
+ """
692
+
693
+ sale = Sale(NSID(round(time.time()) * 16 ** 3), item)
694
+ sale.quantity = quantity
695
+ sale.price = price
696
+ sale.seller_id = seller
697
+
698
+ _data = sale.__dict__.copy()
699
+ del _data['id']
700
+
701
+ self.marketplace.put(key = sale.id, data = _data)
702
+
703
+ def delete_sale(self, sale: Sale) -> None:
704
+ """Annule une vente sur le marketplace."""
705
+
706
+ sale.id = NSID(sale.id)
707
+ self.marketplace.delete(sale.id)
708
+
709
+ def get_inventory(self, id: NSID) -> Inventory | None:
710
+ """
711
+ Récupérer un inventaire dans la base des inventaires.
712
+
713
+ ## Paramètres
714
+ id: `NSID`
715
+ ID du propriétaire de l'inventaire
716
+
717
+ ## Retourne
718
+ - `.Inventory | None`
719
+ """
720
+ _data = self.inventories.get(id)
721
+
722
+ if _data is None:
723
+ return None
724
+
725
+ inventory = Inventory(id)
726
+
727
+ del _data['key']
728
+
729
+ for _item in _data['objects']:
730
+ item = Item(_item['id'])
731
+ item.__dict__ = _item
732
+
733
+ inventory.objects.append(item)
734
+
735
+ return inventory
662
736
 
663
- return item
737
+ def save_inventory(self, inventory: Inventory) -> None:
738
+ """
739
+ Sauvegarder un inventaire
664
740
 
665
- def save_item(self, item: Item) -> None:
666
- """Sauvegarde un item dans la base de données du marché."""
741
+ ## Paramètres
742
+ inventory: `.Inventory`
743
+ Inventaire à sauvegarder
744
+ """
667
745
 
668
- item.id = NSID(item.id)
746
+ _data = {
747
+ "owner_id": inventory.owner_id,
748
+ "objects": [ object.__dict__ for object in inventory.objects ]
749
+ }
669
750
 
670
- _data = item.__dict__.copy()
751
+ self.inventories.put(key = inventory.owner_id, data = _data)
671
752
 
672
- self.marketplace.put(key = item.id, data = _data)
753
+ def delete_inventory(self, inventory: Inventory) -> None:
754
+ """
755
+ Supprime un inventaire
673
756
 
674
- def delete_item(self, item: Item) -> None:
675
- """Supprime un item du marché."""
757
+ ## Paramètres
758
+ inventory: `.Inventory`
759
+ Inventaire à supprimer
760
+ """
676
761
 
677
- item.id = NSID(item.id)
678
- self.marketplace.delete(item.id)
762
+ self.inventories.delete(inventory.id)
679
763
 
680
764
  def _add_archive(self, archive: Action):
681
765
  """Ajoute une archive d'une transaction ou d'une vente dans la base de données."""
@@ -689,8 +773,6 @@ class BankInstance:
689
773
  if type(archive) == Transaction:
690
774
  _data['type'] = "transaction"
691
775
  archive.currency = archive.currency.upper()
692
- elif type(archive) == Sale:
693
- _data['type'] = "sale"
694
776
  else:
695
777
  _data['type'] = "unknown"
696
778
 
@@ -719,10 +801,6 @@ class BankInstance:
719
801
 
720
802
  archive.reason = _data['reason']
721
803
  archive.currency = _data['currency']
722
- elif _data['type'] == "sale":
723
- archive = Sale(_data['author'], _data['target'])
724
-
725
- archive.price = _data['price']
726
804
  else:
727
805
  archive = Action(_data['author'], _data['target'])
728
806
 
@@ -743,7 +821,7 @@ class BankInstance:
743
821
  ## Renvoie
744
822
  - `list[Action | Transaction]`
745
823
  """
746
-
824
+
747
825
  _res = self.archives.fetch(query).items
748
826
 
749
827
  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')
nsarchive/cls/entities.py CHANGED
@@ -45,6 +45,7 @@ class Entity:
45
45
  self.name: str = "Entité Inconnue"
46
46
  self.registerDate: int = 0
47
47
  self.legalPosition: Position = Position()
48
+ self.additional: dict = {}
48
49
 
49
50
  def set_name(self, new_name: str) -> None:
50
51
  if len(new_name) > 32:
@@ -55,6 +56,13 @@ class Entity:
55
56
  def set_position(self, position: str) -> None:
56
57
  self.legalPosition = position
57
58
 
59
+ def add_link(self, key: str, value: str | int) -> None:
60
+ if isinstance(value, str) or isinstance(value, int):
61
+ self.additional[key] = value
62
+
63
+ def unlink(self, key: str) -> None:
64
+ del self.additional[key]
65
+
58
66
  class User(Entity):
59
67
  def __init__(self, id: str | NSID) -> None:
60
68
  super().__init__(NSID(id))
@@ -134,8 +142,14 @@ class Organization(Entity):
134
142
  self.members: list[GroupMember] = []
135
143
  self.avatar: bytes = assets.open('default_avatar.png')
136
144
 
137
- def add_certification(self, certif: str) -> None:
138
- self.certifications[certif] = round(time.time())
145
+ def add_certification(self, certification: str) -> None:
146
+ self.certifications[certification] = round(time.time())
147
+
148
+ def has_certification(self, certification: str) -> bool:
149
+ return certification in self.certifications.keys()
150
+
151
+ def remove_certification(self, certification: str) -> None:
152
+ del self.certifications[certification]
139
153
 
140
154
  def add_member(self, member: GroupMember) -> None:
141
155
  if not isinstance(member, GroupMember):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nsarchive
3
- Version: 1.2.8
3
+ Version: 1.4.0
4
4
  Summary:
5
5
  License: GPL-3.0
6
6
  Author: happex
@@ -0,0 +1,13 @@
1
+ nsarchive/__init__.py,sha256=85kvYTT-TSJgTX1AX-nVNI9GJANJS4S6UXCE3SpyUjE,27563
2
+ nsarchive/assets/default_avatar.png,sha256=n-4vG_WPke8LvbY3ZU6oA-H-OtRoIu7woKnRq9DCIlI,51764
3
+ nsarchive/cls/archives.py,sha256=i4R7NPYXX_1oi0oLAvL_4SqyjqPutXSXKysUetE6hME,2001
4
+ nsarchive/cls/base.py,sha256=DGDm0uD96M00-qvdKsltU9kAfAOBr85Ov0b18gTnoIM,714
5
+ nsarchive/cls/economy.py,sha256=JpNB06JHek4uUapdk89-SR3DEoSyxXPn8OqZJkOZH_E,1252
6
+ nsarchive/cls/entities.py,sha256=7vhD6r6DuvTlyGyPmm1scpWFsqPGMUw7JQ9Ks8sHWpQ,6712
7
+ nsarchive/cls/exceptions.py,sha256=QN6Qn7cxTkGoC4lO50hBAq4gZCgo7scQvCkb-xKl6Xs,692
8
+ nsarchive/cls/republic.py,sha256=6eut6OsFoOm9TVhA41fM3NlMEA3Uhg9TCuXgl46vFko,1985
9
+ nsarchive/utils/assets.py,sha256=hd0STSpa0yT-OJlUyI_wCYXJqcBiUMQds2pZTXNNg9c,382
10
+ nsarchive-1.4.0.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
11
+ nsarchive-1.4.0.dist-info/METADATA,sha256=MK4hOKyqSERSJtko967gMBPPdnzyqY-GFfx5pzaimts,5629
12
+ nsarchive-1.4.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
+ nsarchive-1.4.0.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- nsarchive/__init__.py,sha256=qfD-Uu9FGlXNtKzIBKtZ-6DEJY3coxtfvAi7Qv4RVH4,25427
2
- nsarchive/assets/default_avatar.png,sha256=n-4vG_WPke8LvbY3ZU6oA-H-OtRoIu7woKnRq9DCIlI,51764
3
- nsarchive/cls/archives.py,sha256=Nmt3C0Zq9oGQdCXSzm_wo70VbNq89SY3dx9KKqEpoCg,2182
4
- nsarchive/cls/base.py,sha256=DGDm0uD96M00-qvdKsltU9kAfAOBr85Ov0b18gTnoIM,714
5
- nsarchive/cls/economy.py,sha256=RjFu3VzNunazslbd4Ia5p1Jr-jJP5CvIcbVOzkDTwTU,549
6
- nsarchive/cls/entities.py,sha256=Rvu2Q1mTWqQ-z92j-OXhoXSWked7p4tOCJm0gIlnP9c,6179
7
- nsarchive/cls/exceptions.py,sha256=QN6Qn7cxTkGoC4lO50hBAq4gZCgo7scQvCkb-xKl6Xs,692
8
- nsarchive/cls/republic.py,sha256=6eut6OsFoOm9TVhA41fM3NlMEA3Uhg9TCuXgl46vFko,1985
9
- nsarchive/utils/assets.py,sha256=hd0STSpa0yT-OJlUyI_wCYXJqcBiUMQds2pZTXNNg9c,382
10
- nsarchive-1.2.8.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
11
- nsarchive-1.2.8.dist-info/METADATA,sha256=obiwVhJXEpzgosI1yLK1RxsOcnxaRoOnmuco6-xEkF8,5629
12
- nsarchive-1.2.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
- nsarchive-1.2.8.dist-info/RECORD,,