Skip to content

Commit 87cabcd

Browse files
committed
Initial commit.
1 parent 20d39dd commit 87cabcd

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

isobot/colors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Library used for stdout colors."""
2+
class Colors():
3+
"""Contains general stdout colors."""
4+
cyan = '\033[96m'
5+
red = '\033[91m'
6+
green = '\033[92m'
7+
end = '\033[0m'

isobot/currency.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import json
2+
import discord
3+
from colors import Colors
4+
5+
class CurrencyAPI(Colors):
6+
"""The isobot API used for managing currency.
7+
8+
Valid commands:
9+
- add(user, amount)
10+
- remove(user, amount)
11+
- reset(user)
12+
- deposit(user, amount)
13+
- withdraw(user, amount)"""
14+
def __init__(self, db_path:str):
15+
self.db_path = db_path
16+
print(f"[Framework/Loader] {Colors.green}CurrencyAPI initialized.{Colors.end}")
17+
def save(self):
18+
"""Saves databases cached on memory."""
19+
with open(self.db_path, 'w+') as f: json.dump(currency, f, indent=4)
20+
def add(self, user:discord.User, amount:int):
21+
"""Adds balance to the specified user."""
22+
currency["wallet"][str(user.id)] += amount
23+
self.save()
24+
def remove(self, user:discord.User, amount:int):
25+
"""Removes balance from the specified user."""
26+
currency["wallet"][str(user.id)] -= amount
27+
self.save()
28+
def reset(self, user:discord.User):
29+
"""Resets the specified user's balance."""
30+
currency["wallet"][str(user.id)] = 0
31+
currency["bank"][str(user.id)] = 0
32+
self.save()
33+
print(f"[Framework/CurrencyAPI] Currency data for \"{user.id}\" has been wiped.")
34+
def deposit(self, user:discord.User, amount:int):
35+
"""Moves a specified amount of coins to the user's bank."""
36+
currency["bank"][str(user.id)] += amount
37+
currency["wallet"][str(user.id)] -= amount
38+
save()
39+
print(f"[Framework/CurrencyAPI] Moved {amount} coins to bank. User: {user} [{user.id}]")
40+
def withdraw(self, user:discord.User, amount:int):
41+
"""Moves a specified amount of coins to the user's wallet."""
42+
currency["wallet"][str(user.id)] += amount
43+
currency["bank"][str(user.id)] -= amount
44+
save()
45+
print(f"[Framework/CurrencyAPI] Moved {amount} coins to wallet. User: {user} [{user.id}]")

logger.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import time
2+
import datetime
3+
from isobot.colors import Colors
4+
5+
class Logger(Colors):
6+
"""The library used for logging information.
7+
8+
Valid commands:
9+
- info(text)
10+
- warn(text)
11+
- error(text)"""
12+
def __init__(self, log_path:str, error_path:str):
13+
self.log_path = log_path
14+
self.error_path = error_path
15+
print(f"[Framework/Loader] {Colors.green}Logger initialized.{Colors.end}")
16+
def info(self, text:str, *, nolog=False):
17+
current_time = datetime.datetime.now().strftime("%H:%M:%S")
18+
print(f'[{current_time}/INFO] {text}')
19+
if nolog == True: pass
20+
else:
21+
with open(self.log_path, 'a') as f:
22+
f.write(f'[{current_time}/INFO] {text}\n')
23+
f.close()
24+
def warn(self, text:str, *, nolog=False):
25+
current_time = datetime.datetime.now().strftime("%H:%M:%S")
26+
print(f'[{current_time}/WARN] {text}')
27+
if nolog == True: pass
28+
else:
29+
with open(self.log_path, 'a') as f:
30+
f.write(f'[{current_time}/WARN] {text}\n')
31+
f.close()
32+
def error(self, text:str, *, nolog=False):
33+
current_time = datetime.datetime.now().strftime("%H:%M:%S")
34+
print(f'{Colours.red}[{current_time}/ERROR] {text}{Colours.end}')
35+
if nolog == True: pass
36+
else:
37+
with open(self.error_path, 'a') as f:
38+
f.write(f'[{current_time}/ERROR] {text}\n')
39+
f.close()

0 commit comments

Comments
 (0)