Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions cogs/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,19 @@
import utils.logger
import asyncio
import framework.isobot.currency
from framework.isobot.shop import ShopData
from framework.isobot.db import levelling
from random import randint
from discord import option, ApplicationContext
from discord.ext import commands

# Classes
class ShopData:
def __init__(self, db_path: str):
self.db_path = db_path
with open(db_path, 'r') as f: self.config = json.load(f)

def get_item_ids(self) -> list:
json_list = list()
for h in self.config: json_list.append(str(h))
return json_list

def get_item_names(self) -> list:
json_list = list()
for h in self.config: json_list.append(str(h["stylized name"]))
return json_list

# Variables
color = discord.Color.random()
currency = framework.isobot.currency.CurrencyAPI("database/currency.json", "logs/currency.log")
levelling = levelling.Levelling()
shop_data = ShopData("config/shop.json")
all_item_ids = shop_data.get_item_ids()
shopitem = shop_data.get_raw_data()
jobs = [
"Discord mod",
"YouTuber",
Expand All @@ -46,7 +32,6 @@ def get_item_names(self) -> list:
]

with open("database/items.json", 'r') as f: items = json.load(f)
with open("config/shop.json", 'r') as f: shopitem = json.load(f)
with open("database/user_data.json", 'r') as f: userdat = json.load(f)

def save():
Expand Down Expand Up @@ -563,7 +548,7 @@ async def deposit(self, ctx: ApplicationContext, amount):
elif int(amount) > currency.get_wallet(ctx.author.id): return await ctx.respond('The amount to deposit must not be more than what you have in your wallet!', ephemeral=True)
currency.deposit(ctx.author.id, int(amount))
localembed = discord.Embed(title="Deposit successful", description=f"You deposited `{amount}` coin(s) to your bank account.", color=color)
localembed.add_field(name="You previously had", value=f"`{currency.get_bank(ctx.author.id) - amount} coins` in your bank account")
localembed.add_field(name="You previously had", value=f"`{currency.get_bank(ctx.author.id) - int(amount)} coins` in your bank account")
localembed.add_field(name="Now you have", value=f"`{currency.get_bank(ctx.author.id)} coins` in your bank account")
await ctx.respond(embed=localembed)

Expand All @@ -581,7 +566,7 @@ async def withdraw(self, ctx: ApplicationContext, amount):
elif int(amount) > currency.get_bank(ctx.author.id): return await ctx.respond('The amount to withdraw must not be more than what you have in your bank account!', ephemeral=True)
currency.withdraw(ctx.author.id, int(amount))
localembed = discord.Embed(title="Withdraw successful", description=f"You withdrew `{amount}` coin(s) from your bank account.", color=color)
localembed.add_field(name="You previously had", value=f"`{currency.get_wallet(ctx.author.id) - amount} coins` in your wallet")
localembed.add_field(name="You previously had", value=f"`{currency.get_wallet(ctx.author.id) - int(amount)} coins` in your wallet")
localembed.add_field(name="Now you have", value=f"`{currency.get_wallet(ctx.author.id)} coins` in your wallet")
await ctx.respond(embed=localembed)

Expand Down
53 changes: 53 additions & 0 deletions framework/isobot/db/items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""The framework module library used for managing isobot's items database."""
# Imports
import json
from framework.isobot.shop import ShopData

# Variables
shop = ShopData("config/shop.json")
shopitem = shop.get_item_ids()

# Functions
class Items():
"""Used to initialize the items database."""
def __init__(self):
print("[framework/db/Levelling] Items db library initialized.")

def load(self) -> dict:
"""Fetches and returns the latest data from the items database."""
with open("database/items.json", 'r', encoding="utf8") as f: db = json.load(f)
return db

def save(self, data: dict) -> int:
"""Dumps all cached data to your local machine."""
with open("database/items.json", 'w+', encoding="utf8") as f: json.dump(data, f, indent=4)
return 0

def generate(self, user_id: int) -> int:
"""Generates a new database key for the specified user id in the items database."""
items = self.load()
if str(user_id) not in items: items[str(user_id)] = {}
for z in shopitem:
if z not in items[str(user_id)]:
items[str(user_id)][str(z)] = 0
self.save(items)
return 0

def add_item(self, user_id: int, item: str, *, quantity: int = 1) -> int:
"""Adds an item of choice to a specific user id."""
items = self.load()
items[str(user_id)][item] += quantity
self.save()
return 0

def remove_item(self, user_id: int, item: str, *, quantity: int = 1) -> int:
"""Removes an item of choice from a specific user id."""
items = self.load()
items[str(user_id)][item] += quantity
self.save()
return 0

def fetch_item_count(self, user_id: int, item: str) -> int:
"""Fetches and returns the amount of a specific item owned by the user."""
items = self.load()
return items[str(user_id)][item]
27 changes: 27 additions & 0 deletions framework/isobot/shop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Framework module used to fetch information on isobot's item shop."""

# Imports
import json

# Functions
class ShopData:
"""Initializes the isobot shop."""
def __init__(self, db_path: str):
self.db_path = db_path
with open(db_path, 'r') as f: self.db = json.load(f)

def get_item_ids(self) -> list:
"""Fetches and returns all of the shop item ids."""
json_list = list()
for h in self.db: json_list.append(str(h))
return json_list

def get_item_names(self) -> list:
"""Fetches and returns all of the shop item names."""
json_list = list()
for h in self.db: json_list.append(str(h["stylized name"]))
return json_list

def get_raw_data(self) -> dict:
"""Fetches the entire raw shop data, in a `dict` format."""
return self.db
11 changes: 3 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from math import floor
from random import randint
from framework.isobot import currency, colors, settings
from framework.isobot.db import levelling
from framework.isobot.db import levelling, items
from discord import ApplicationContext, option
from discord.ext import commands
from cogs.economy import new_userdat
Expand All @@ -25,7 +25,6 @@
#Variables
client = discord.Bot()
color = discord.Color.random()
with open('database/items.json', 'r', encoding="utf-8") as f: items = json.load(f)
with open('config/shop.json', 'r', encoding="utf-8") as f: shopitem = json.load(f)
with open('database/presence.json', 'r', encoding="utf-8") as f: presence = json.load(f)
with open('config/commands.json', 'r', encoding="utf-8") as f: commandsdb = json.load(f)
Expand All @@ -35,7 +34,6 @@
#Pre-Initialization Commands
def save():
"""Dumps all cached data to the local databases."""
with open('database/items.json', 'w+', encoding="utf-8") as e: json.dump(items, e, indent=4)
with open('database/presence.json', 'w+', encoding="utf-8") as e: json.dump(presence, e, indent=4)
with open('database/automod.json', 'w+', encoding="utf-8") as e: json.dump(automod_config, e, indent=4)

Expand All @@ -58,6 +56,7 @@ def save():
currency = currency.CurrencyAPI("database/currency.json", "logs/currency.log")
settings = settings.Configurator()
levelling = levelling.Levelling()
items = items.Items()

# Theme Loader
themes = False # True: enables themes; False: disables themes;
Expand Down Expand Up @@ -99,8 +98,7 @@ async def on_message(ctx):
create_isocoin_key(ctx.author.id)
new_userdat(ctx.author.id)
settings.generate(ctx.author.id)
if str(ctx.author.id) not in items:
items[str(ctx.author.id)] = {}
items.generate(ctx.author.id)
levelling.generate(ctx.author.id)
if str(ctx.guild.id) not in automod_config:
automod_config[str(ctx.guild.id)] = {
Expand All @@ -113,9 +111,6 @@ async def on_message(ctx):
}
}
}
for z in shopitem:
if z in items[str(ctx.author.id)]: pass
else: items[str(ctx.author.id)][str(z)] = 0
save()
uList = list()
if str(ctx.guild.id) in presence:
Expand Down