Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit 9e3b384

Browse files
committed
Add some more methods to CurrencyAPI
1 parent 716e46c commit 9e3b384

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

framework/isobot/currency.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ class CurrencyAPI(Colors):
1515
Valid commands:
1616
- add(user, amount)
1717
- remove(user, amount)
18+
- bank_add(user, amount)
19+
- bank_remove(user, amount)
1820
- reset(user)
1921
- deposit(user, amount)
2022
- withdraw(user, amount)
23+
- treasury_add(amount)
24+
- treasury_remove(amount)
2125
- get_wallet(user)
2226
- get_bank(user)
2327
- get_user_networth(user)
@@ -42,6 +46,16 @@ def add(self, user: discord.User, amount: int) -> int:
4246
f.write(f'{self.get_time()} framework.isobot.currency User({user}): Added {amount} coins to wallet\n')
4347
f.close()
4448
return 0
49+
50+
def bank_add(self, user: discord.User, amount: int) -> int:
51+
"""Adds balance to the specified user's bank account."""
52+
with open(self.db_path, 'r') as f: currency = json.load(f)
53+
currency["bank"][str(user)] += int(amount)
54+
with open(self.db_path, 'w+') as f: json.dump(currency, f, indent=4)
55+
with open(self.log_path, 'a') as f:
56+
f.write(f'{self.get_time()} framework.isobot.currency User({user}): Added {amount} coins to bank\n')
57+
f.close()
58+
return 0
4559

4660
def remove(self, user: discord.User, amount: int) -> int:
4761
"""Removes balance from the specified user."""
@@ -52,6 +66,16 @@ def remove(self, user: discord.User, amount: int) -> int:
5266
f.write(f'{self.get_time()} framework.isobot.currency User({user}): Removed {amount} coins from wallet\n')
5367
f.close()
5468
return 0
69+
70+
def bank_remove(self, user: discord.User, amount: int) -> int:
71+
"""Removes balance from the specified user's bank account."""
72+
with open(self.db_path, 'r') as f: currency = json.load(f)
73+
currency["bank"][str(user)] -= int(amount)
74+
with open(self.db_path, 'w+') as f: json.dump(currency, f, indent=4)
75+
with open(self.log_path, 'a') as f:
76+
f.write(f'{self.get_time()} framework.isobot.currency User({user}): Removed {amount} coins from bank\n')
77+
f.close()
78+
return 0
5579

5680
def reset(self, user: discord.User) -> int:
5781
"""Resets the specified user's balance."""
@@ -88,6 +112,24 @@ def withdraw(self, user: discord.User, amount: int) -> int:
88112
f.write(f'{self.get_time()} framework.isobot.currency User({user}): Moved {amount} coins from bank to wallet\n')
89113
f.close()
90114
return 0
115+
116+
def treasury_add(self, amount: int) -> int:
117+
with open(self.db_path, 'r') as f: currency = json.load(f)
118+
currency["treasury"] += int(amount)
119+
with open(self.db_path, 'w+') as f: json.dump(currency, f, indent=4)
120+
with open(self.log_path, 'a') as f:
121+
f.write(f'{self.get_time()} framework.isobot.currency Treasury: Added {amount} coins to treasury\n')
122+
f.close()
123+
return 0
124+
125+
def treasury_remove(self, amount: int) -> int:
126+
with open(self.db_path, 'r') as f: currency = json.load(f)
127+
currency["treasury"] -= int(amount)
128+
with open(self.db_path, 'w+') as f: json.dump(currency, f, indent=4)
129+
with open(self.log_path, 'a') as f:
130+
f.write(f'{self.get_time()} framework.isobot.currency Treasury: Removed {amount} coins from treasury\n')
131+
f.close()
132+
return 0
91133

92134
def get_wallet(self, user: discord.User) -> int:
93135
"""Returns the amount of coins in the user's wallet."""

0 commit comments

Comments
 (0)