From 9e7f79b12d7699b116a87a6b515abe36950298de Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 11:18:06 +0530 Subject: [PATCH 01/18] Convert levels and items db to modules --- main.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 54cefd2b..32a23a0a 100644 --- a/main.py +++ b/main.py @@ -17,6 +17,8 @@ import framework.isobank.authorize import framework.isobank.manager import framework.isobot.embedengine +import framework.isobot.db.Items +import framework.isobot.db.Levels from discord import ApplicationContext, option from discord.ext import commands from discord.ext.commands import * @@ -32,19 +34,19 @@ client = discord.Bot() color = discord.Color.random() wdir = os.getcwd() -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/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('database/levels.json', 'r', encoding="utf-8") as f: levels = json.load(f) +# with open('database/levels.json', 'r', encoding="utf-8") as f: levels = json.load(f) with open('config/commands.json', 'r', encoding="utf-8") as f: commandsdb = json.load(f) with open('database/automod.json', 'r', encoding="utf-8") as f: automod_config = json.load(f) cmd_list = commandsdb.keys() #Pre-Initialization Commands def save(): - with open('database/items.json', 'w+', encoding="utf-8") as f: json.dump(items, f, indent=4) + # with open('database/items.json', 'w+', encoding="utf-8") as f: json.dump(items, f, indent=4) with open('database/presence.json', 'w+', encoding="utf-8") as f: json.dump(presence, f, indent=4) - with open('database/levels.json', 'w+', encoding="utf-8") as f: json.dump(levels, f, indent=4) + # with open('database/levels.json', 'w+', encoding="utf-8") as f: json.dump(levels, f, indent=4) with open('database/automod.json', 'w+', encoding="utf-8") as f: json.dump(automod_config, f, indent=4) if not os.path.isdir("logs"): @@ -63,6 +65,8 @@ def save(): #Framework Module Loader colors = framework.isobot.colors.Colors() currency = framework.isobot.currency.CurrencyAPI("database/currency.json", "logs/currency.log") +items = framework.isobot.currency.Items("database/items.json", None) +levels = framework.isobot.currency.Levels("database/levels.json", None) # Theme Loader themes = False # True: enables themes; False: disables themes; @@ -101,8 +105,8 @@ async def on_message(ctx): currency.new_bank(ctx.author.id) create_isocoin_key(ctx.author.id) new_userdat(ctx.author.id) - if str(ctx.author.id) not in items: items[str(ctx.author.id)] = {} - if str(ctx.author.id) not in levels: levels[str(ctx.author.id)] = {"xp": 0, "level": 0} + items.new(ctx.author.id) + levels.new(ctx.author.id) if str(ctx.guild.id) not in automod_config: automod_config[str(ctx.guild.id)] = { "swear_filter": { @@ -114,9 +118,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: @@ -133,15 +134,15 @@ async def on_message(ctx): await asyncio.sleep(5) await m1.delete() if not ctx.author.bot: - levels[str(ctx.author.id)]["xp"] += randint(1, 5) + levels.add_xp(ctx.author.id) += randint(1, 5) xpreq = 0 - for level in range(int(levels[str(ctx.author.id)]["level"])): + for level in range(int(levels.get_level(ctx.author.id))): xpreq += 50 if xpreq >= 5000: break - if levels[str(ctx.author.id)]["xp"] >= xpreq: - levels[str(ctx.author.id)]["xp"] = 0 - levels[str(ctx.author.id)]["level"] += 1 - await ctx.author.send(f"{ctx.author.mention}, you just ranked up to **level {levels[str(ctx.author.id)]['level']}**. Nice!") + if levels.get_xp(ctx.author.id) >= xpreq: + levels.reset_xp(ctx.author.id) = 0 + levels.add_levels(ctx.author.id) += 1 + await ctx.author.send(f"{ctx.author.mention}, you just ranked up to **level {levels.get_level(ctx.author.id)}**. Nice!") save() if automod_config[str(ctx.guild.id)]["swear_filter"]["enabled"] == True: if automod_config[str(ctx.guild.id)]["swear_filter"]["keywords"]["use_default"] and any(x in ctx.content.lower() for x in automod_config[str(ctx.guild.id)]["swear_filter"]["keywords"]["default"]): From 9515d795ac570bd0ddeda271576a52265724d34b Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 11:19:02 +0530 Subject: [PATCH 02/18] Create database management module --- framework/isobot/db.py | 116 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 framework/isobot/db.py diff --git a/framework/isobot/db.py b/framework/isobot/db.py new file mode 100644 index 00000000..87430670 --- /dev/null +++ b/framework/isobot/db.py @@ -0,0 +1,116 @@ +import json +import discord +import datetime + +def get_time(self): + return datetime.datetime.now().strftime("%H:%M:%S") + +class Colors: + """Contains general stdout colors.""" + cyan = '\033[96m' + red = '\033[91m' + green = '\033[92m' + end = '\033[0m' + +class Items(Colors): + def __init__(self, db_path: str, log_path: str): + self.db_path = db_path + self.log_path = log_path + print(f"[Framework/Loader] {Colors.green}Items database initialized.{Colors.end}") + + def new(user_id: discord.User) -> int: + with open(self.db_path, 'r') as f: items = json.load(f) + if str(user_id) not in items: items[str(user_id)] = {} + with open("config/shop.json", "r") as f: + all_shopitems = json.load(f) + shopitem = list() + for x in all_shopitems: shopitem.append(x) + for z in shopitem.keys(): + if z in items[str(user_id)]: pass + else: items[str(user_id)][str(z)] = 0 + with open(self.db_path, 'w+') as f: json.dump(items, f, indent=4) + return 0 + + def add_item(user_id: discord.User, item: str, quantity: int) -> int: + with open(self.db_path, 'r') as f: items = json.load(f) + items[str(user_id)][item] += quantity + with open(self.db_path, 'w+') as f: json.dump(items, f, indent=4) + return 0 + + def remove_item(user_id: discord.User, item: str, quantity: int) -> int: + with open(self.db_path, 'r') as f: items = json.load(f) + items[str(user_id)][item] -= quantity + with open(self.db_path, 'w+') as f: json.dump(items, f, indent=4) + return 0 + +class Levels(Colors): + def __init__(self, db_path: str, log_path: str): + self.db_path = db_path + self.log_path = log_path + print(f"[Framework/Loader] {Colors.green}Levels database initialized.{Colors.end}") + + def new(user_id: discord.User) -> int: + with open(self.db_path, 'r') as f: levels = json.load(f) + if str(user_id) not in levels: levels[str(user_id)] = { + "xp": 0, + "level": 0 + } + with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) + return 0 + + def get_level(user_id: discord.User) -> int: + with open(self.db_path, 'r') as f: levels = json.load(f) + return levels[str(user_id)]["level"] + + def get_xp(user_id: discord.User) -> int: + with open(self.db_path, 'r') as f: levels = json.load(f) + return levels[str(user_id)]["xp"] + + def add_levels(user_id: discord.User, level: int): + with open(self.db_path, 'r') as f: levels = json.load(f) + levels[str(user_id)]["level"] += level + with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) + return 0 + + def remove_levels(user_id: discord.User, level: int): + with open(self.db_path, 'r') as f: levels = json.load(f) + levels[str(user_id)]["level"] += level + with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) + return 0 + + def reset_level(user_id: discord.User): + with open(self.db_path, 'r') as f: levels = json.load(f) + levels[str(user_id)]["level"] = 0 + with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) + return 0 + + def add_xp(user_id: discord.User, xp: int): + with open(self.db_path, 'r') as f: levels = json.load(f) + levels[str(user_id)]["xp"] += xp + with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) + return 0 + + def remove_xp(user_id: discord.User, xp: int): + with open(self.db_path, 'r') as f: levels = json.load(f) + levels[str(user_id)]["xp"] += xp + with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) + return 0 + + def reset_xp(user_id: discord.User): + with open(self.db_path, 'r') as f: levels = json.load(f) + levels[str(user_id)]["xp"] = 0 + with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) + return 0 + + def edit_level(user_id: discord.User, level: int): + with open(self.db_path, 'r') as f: levels = json.load(f) + levels[str(user_id)]["level"] = level + with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) + return 0 + + def edit_xp(user_id: discord.User, xp: int): + with open(self.db_path, 'r') as f: levels = json.load(f) + levels[str(user_id)]["xp"] = xp + with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) + return 0 + From 15a27bce4d831be19790818d7bae574354929aac Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 11:20:06 +0530 Subject: [PATCH 03/18] Add db library support to levelling cog --- cogs/levelling.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cogs/levelling.py b/cogs/levelling.py index 4b134f82..1b91b6dc 100644 --- a/cogs/levelling.py +++ b/cogs/levelling.py @@ -4,24 +4,26 @@ import discord import json import os.path +import framework.isobot.db.Levels from discord import option, ApplicationContext from discord.ext import commands # Variables wdir = os.getcwd() color = discord.Color.random() +levels = framework.isobot.db.Levels(f"{wdir}/database/levels.json", None) -with open(f"{wdir}/database/levels.json", 'r', encoding="utf-8") as f: levels = json.load(f) +# with open(f"{wdir}/database/levels.json", 'r', encoding="utf-8") as f: levels = json.load(f) -def save(): - with open(f"{wdir}/database/levels.json", 'w+', encoding="utf-8") as f: json.dump(levels, f, indent=4) +# def save(): +# with open(f"{wdir}/database/levels.json", 'w+', encoding="utf-8") as f: json.dump(levels, f, indent=4) # Functions -def get_xp(id: int) -> int: - return levels[str(id)]["xp"] +# def get_xp(id: int) -> int: +# return levels[str(id)]["xp"] -def get_level(id: int) -> int: - return levels[str(id)]["level"] +# def get_level(id: int) -> int: +# return levels[str(id)]["level"] # Commands class Levelling(commands.Cog): @@ -37,8 +39,8 @@ async def rank(self, ctx: ApplicationContext, user:discord.User=None): if user is None: user = ctx.author try: localembed = discord.Embed(title=f"{user.display_name}'s rank", color=color) - localembed.add_field(name="Level", value=levels[str(user.id)]["level"]) - localembed.add_field(name="XP", value=levels[str(user.id)]["xp"]) + localembed.add_field(name="Level", value=levels.get_level(user.id)) + localembed.add_field(name="XP", value=levels.get_xp(user.id)) localembed.set_footer(text="Keep chatting to earn levels!") await ctx.respond(embed = localembed) except KeyError: return await ctx.respond("Looks like that user isn't indexed yet. Try again later.", ephemeral=True) @@ -52,8 +54,8 @@ async def rank(self, ctx: ApplicationContext, user:discord.User=None): async def edit_rank(self, ctx: ApplicationContext, user:discord.User, new_rank:int): if ctx.author.id != 738290097170153472: return await ctx.respond("This command isn't for you.", ephemeral=True) try: - levels[str(user.id)]["level"] = new_rank - await ctx.respond(f"{user.display_name}\'s rank successfully edited. `New Rank: {levels[str(user.id)]['level']}`") + levels.edit_level(user.id) = new_rank + await ctx.respond(f"{user.display_name}\'s rank successfully edited. `New Rank: {levels.get_level(user.id)}`") except KeyError: return await ctx.respond("That user isn't indexed yet.", ephemeral=True) @commands.slash_command( @@ -65,8 +67,8 @@ async def edit_rank(self, ctx: ApplicationContext, user:discord.User, new_rank:i async def edit_xp(self, ctx: ApplicationContext, user:discord.User, new_xp:int): if ctx.author.id != 738290097170153472: return await ctx.respond("This command isn't for you.", ephemeral=True) try: - levels[str(user.id)]["xp"] = new_xp - await ctx.respond(f"{user.display_name}\'s XP count successfully edited. `New XP: {levels[str(user.id)]['xp']}`") + levels.edit_xp(user.id) = new_xp + await ctx.respond(f"{user.display_name}\'s XP count successfully edited. `New XP: {levels.get_xp(user.id)}`") except KeyError: return await ctx.respond("That user isn't indexed yet.", ephemeral=True) @commands.slash_command( @@ -76,7 +78,7 @@ async def edit_xp(self, ctx: ApplicationContext, user:discord.User, new_xp:int): async def leaderboard_levels(self, ctx: ApplicationContext): levels_dict = dict() for person in levels: - levels_dict[str(person)] = levels[str(person)]["level"] + levels_dict[str(person)] = levels.get_level(person) undicted_leaderboard = sorted(levels_dict.items(), key=lambda x:x[1], reverse=True) dicted_leaderboard = dict(undicted_leaderboard) parsed_output = str() From 581b0bb829171e513fbd6a5ce0890def63a4a0ca Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 11:23:41 +0530 Subject: [PATCH 04/18] Add db library support for utils cog --- cogs/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cogs/utils.py b/cogs/utils.py index 5cfa9c87..955ac73f 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -8,9 +8,9 @@ import openai import framework.isobot.embedengine import framework.isobot.currency +import framework.isobot.db.Levels from discord import option, ApplicationContext from discord.ext import commands -from cogs.levelling import get_level, get_xp from cogs.afk import get_presence # Variables @@ -18,6 +18,7 @@ currency = framework.isobot.currency.CurrencyAPI("database/currency.json", "logs/currency.log") openai.api_key = os.getenv("chatgpt_API_KEY") chatgpt_conversation = dict() +levels = framework.isobot.db.Levels("database/levels.json", None) # Commands class Utils(commands.Cog): @@ -95,7 +96,7 @@ async def profile(self, ctx: ApplicationContext, user: discord.User = None): if user is None: user = ctx.author localembed = discord.Embed(title=f"{user.display_name}'s isobot stats", color=color) localembed.set_thumbnail(url=user.avatar) - localembed.add_field(name="Level", value=f"Level {get_level(user.id)} ({get_xp(user.id)} XP)", inline=False) + localembed.add_field(name="Level", value=f"Level {levels.get_level(user.id)} ({levels.get_xp(user.id)} XP)", inline=False) localembed.add_field(name="Balance in Wallet", value=f"{currency.get_wallet(user.id)} coins", inline=True) localembed.add_field(name="Balance in Bank Account", value=f"{currency.get_bank(user.id)} coins", inline=True) localembed.add_field(name="Net-Worth", value=f"{currency.get_user_networth(user.id)} coins", inline=True) From fab10f371311f5810ef43857f7c1f697fcdf5131 Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 11:24:52 +0530 Subject: [PATCH 05/18] Add db library support for economy cog --- cogs/economy.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cogs/economy.py b/cogs/economy.py index 7fb7654a..e89289c4 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -9,6 +9,7 @@ import utils.logger import asyncio import framework.isobot.currency +import framework.isobot.db.Levels from random import randint from discord import option, ApplicationContext from discord.ext import commands @@ -34,6 +35,7 @@ def get_item_names(self) -> list: wdir = os.getcwd() color = discord.Color.random() currency = framework.isobot.currency.CurrencyAPI("database/currency.json", "logs/currency.log") +levels = framework.isobot.db.Levels("database/levels.json", None) shop_data = ShopData(f"{wdir}/config/shop.json") all_item_ids = shop_data.get_item_ids() jobs = [ @@ -467,12 +469,12 @@ async def work_list(self, ctx: ApplicationContext): @commands.cooldown(1, 1800, commands.BucketType.user) async def work_select(self, ctx: ApplicationContext, job: str): if job not in jobs: return await ctx.respond(f"This job does not exist. What kind of a job is even {job}??", ephemeral=True) - if job == "YouTuber" and get_level(ctx.author.id) < 3: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) - elif job == "Streamer" and get_level(ctx.author.id) < 5: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) - elif job == "Developer" and get_level(ctx.author.id) < 10: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) - elif job == "Scientist" and get_level(ctx.author.id) < 20: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) - elif job == "Engineer" and get_level(ctx.author.id) < 25: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) - elif job == "Doctor" and get_level(ctx.author.id) < 40: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + if job == "YouTuber" and levels.get_level(ctx.author.id) < 3: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + elif job == "Streamer" and levels.get_level(ctx.author.id) < 5: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + elif job == "Developer" and levels.get_level(ctx.author.id) < 10: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + elif job == "Scientist" and levels.get_level(ctx.author.id) < 20: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + elif job == "Engineer" and levels.get_level(ctx.author.id) < 25: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + elif job == "Doctor" and levels.get_level(ctx.author.id) < 40: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) userdat[str(ctx.author.id)]["work_job"] = job save() localembed = discord.Embed(title="New job!", description=f"You are now working as a {job}!") From 5760d9fa14f911b43f141b7a9cccc39c7fc39036 Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 12:00:14 +0530 Subject: [PATCH 06/18] Add weather db support to weather cog --- cogs/weather.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/cogs/weather.py b/cogs/weather.py index 5f94b64e..41308ed1 100644 --- a/cogs/weather.py +++ b/cogs/weather.py @@ -3,17 +3,13 @@ import json import requests import os +import framework.isobot.db from discord import ApplicationContext, option from discord.ext import commands # Variables api_key = os.environ['openweathermap_API_KEY'] -with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) - -# Functions -def save(): - """Dumps all cached databases to storage.""" - with open("database/weather.json", 'w+', encoding="utf-8") as f: json.dump(user_db, f, indent=4) +weather_db = framework.isobot.db.Weather("database/weather.json", None) # Commands class Weather(commands.Cog): @@ -26,13 +22,12 @@ def __init__(self, bot): ) @option(name="location", description="What location do you want to set?", type=str) async def weather_set_location(self, ctx: ApplicationContext, location: str): - if str(ctx.author.id) not in user_db: user_db[str(ctx.author.id)] = {"location": None, "scale": "Celsius"} + weather_db.new(ctx.author.id) test_ping = requests.get(f"https://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}").content test_ping_json = json.loads(test_ping) if test_ping_json["cod"] == '404': return await ctx.respond(":warning: This location does not exist.", ephemeral=True) else: - user_db[str(ctx.author.id)]["location"] = location.lower() - save() + weather_db.set_default_location(ctx.author.id, location.lower()) localembed = discord.Embed(description="Your default location has been updated.", color=discord.Color.green()) await ctx.respond(embed=localembed) @@ -42,10 +37,9 @@ async def weather_set_location(self, ctx: ApplicationContext, location: str): ) @option(name="scale", description="Which scale do you want to use?", type=str, choices=["Celsius", "Fahrenheit", "Kelvin"]) async def weather_set_scale(self, ctx: ApplicationContext, scale: str): - if str(ctx.author.id) not in user_db: user_db[str(ctx.author.id)] = {"location": None, "scale": "Celsius"} + weather_db.new(ctx.author.id) if scale not in ["Celsius", "Fahrenheit", "Kelvin"]: return 1 - user_db[str(ctx.author.id)]["scale"] = scale - save() + weather_db.set_scale(ctx.author.id, scale) localembed = discord.Embed(description="Your preferred unit scale has been updated.", color=discord.Color.green()) await ctx.respond(embed=localembed) @@ -55,10 +49,10 @@ async def weather_set_scale(self, ctx: ApplicationContext, scale: str): ) @option(name="location", description="The location you want weather info about (leave empty for set location)", type=str, default=None) async def weather(self, ctx: ApplicationContext, location: str = None): - if str(ctx.author.id) not in user_db: user_db[str(ctx.author.id)] = {"location": None, "scale": "Celsius"} + weather_db.new(ctx.author.id) if location == None: - if user_db[str(ctx.author.id)]["location"] == None: return await ctx.respond("You do not have a default location set yet.\nEnter a location name and try again.", ephemeral=True) - else: location = user_db[str(ctx.author.id)]["location"] + if weather_db.get_location(ctx.author.id) == None: return await ctx.respond("You do not have a default location set yet.\nEnter a location name and try again.", ephemeral=True) + else: location = weather_db.get_default_location(ctx.author.id) location = location.replace(" ", "%20") api_request = requests.get(f"https://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}").content req: dict = json.loads(api_request) @@ -71,11 +65,11 @@ async def weather(self, ctx: ApplicationContext, location: str = None): # Stripped API request data loc_name = req["name"] - if user_db[str(ctx.author.id)]["scale"] == "Celsius": + if weather_db.get_scale(ctx.author.id) == "Celsius": temp = round(req["main"]["temp"] - 273) temp_max = round(req["main"]["temp_max"] - 273) temp_min = round(req["main"]["temp_min"] - 273) - elif user_db[str(ctx.author.id)]["scale"] == "Fahrenheit": + elif weather_db.get_scale(ctx.author.id) == "Fahrenheit": temp = round(((req["main"]["temp"] - 273) * 9/5) + 32) temp_max = round(((req["main"]["temp_max"] - 273) * 9/5) + 32) temp_min = round(((req["main"]["temp_min"] - 273) * 9/5) + 32) @@ -94,8 +88,8 @@ async def weather(self, ctx: ApplicationContext, location: str = None): description=f"**{forcast}**\n{forcast_description}", color=discord.Color.blue() ) - if user_db[str(ctx.author.id)]["scale"] == "Celsius": localembed.add_field(name="Temperature", value=f"**{temp}C** (max: {temp_max}C, min: {temp_min}C)") - elif user_db[str(ctx.author.id)]["scale"] == "Fahrenheit": localembed.add_field(name="Temperature", value=f"**{temp}F** (max: {temp_max}F, min: {temp_min}F)") + if weather_db.get_scale(ctx.author.id) == "Celsius": localembed.add_field(name="Temperature", value=f"**{temp}C** (max: {temp_max}C, min: {temp_min}C)") + elif weather_db.get_scale(ctx.author.id) == "Fahrenheit": localembed.add_field(name="Temperature", value=f"**{temp}F** (max: {temp_max}F, min: {temp_min}F)") else: localembed.add_field(name="Temperature", value=f"**{temp}K** (max: {temp_max}K, min: {temp_min}K)") localembed.add_field(name="Humidity", value=f"{humidity}%") localembed.add_field(name="Sunrise", value=f"", inline=False) From f237fe85dcc1923fb1ab96ee73ee3a983ada862c Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 12:01:17 +0530 Subject: [PATCH 07/18] Add support for weather db Also added missing `self` params in functions --- framework/isobot/db.py | 63 ++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/framework/isobot/db.py b/framework/isobot/db.py index 87430670..9978bbd4 100644 --- a/framework/isobot/db.py +++ b/framework/isobot/db.py @@ -1,3 +1,6 @@ +"""A module to manage the databases in isobot.""" + +# Imports import json import discord import datetime @@ -18,7 +21,7 @@ def __init__(self, db_path: str, log_path: str): self.log_path = log_path print(f"[Framework/Loader] {Colors.green}Items database initialized.{Colors.end}") - def new(user_id: discord.User) -> int: + def new(self, user_id: discord.User) -> int: with open(self.db_path, 'r') as f: items = json.load(f) if str(user_id) not in items: items[str(user_id)] = {} with open("config/shop.json", "r") as f: @@ -31,13 +34,13 @@ def new(user_id: discord.User) -> int: with open(self.db_path, 'w+') as f: json.dump(items, f, indent=4) return 0 - def add_item(user_id: discord.User, item: str, quantity: int) -> int: + def add_item(self, user_id: discord.User, item: str, quantity: int) -> int: with open(self.db_path, 'r') as f: items = json.load(f) items[str(user_id)][item] += quantity with open(self.db_path, 'w+') as f: json.dump(items, f, indent=4) return 0 - def remove_item(user_id: discord.User, item: str, quantity: int) -> int: + def remove_item(self, user_id: discord.User, item: str, quantity: int) -> int: with open(self.db_path, 'r') as f: items = json.load(f) items[str(user_id)][item] -= quantity with open(self.db_path, 'w+') as f: json.dump(items, f, indent=4) @@ -49,7 +52,7 @@ def __init__(self, db_path: str, log_path: str): self.log_path = log_path print(f"[Framework/Loader] {Colors.green}Levels database initialized.{Colors.end}") - def new(user_id: discord.User) -> int: + def new(self, user_id: discord.User) -> int: with open(self.db_path, 'r') as f: levels = json.load(f) if str(user_id) not in levels: levels[str(user_id)] = { "xp": 0, @@ -58,59 +61,91 @@ def new(user_id: discord.User) -> int: with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def get_level(user_id: discord.User) -> int: + def get_level(self, user_id: discord.User) -> int: with open(self.db_path, 'r') as f: levels = json.load(f) return levels[str(user_id)]["level"] - def get_xp(user_id: discord.User) -> int: + def get_xp(self, user_id: discord.User) -> int: with open(self.db_path, 'r') as f: levels = json.load(f) return levels[str(user_id)]["xp"] - def add_levels(user_id: discord.User, level: int): + def add_levels(self, user_id: discord.User, level: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["level"] += level with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def remove_levels(user_id: discord.User, level: int): + def remove_levels(self, user_id: discord.User, level: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["level"] += level with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def reset_level(user_id: discord.User): + def reset_level(self, user_id: discord.User): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["level"] = 0 with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def add_xp(user_id: discord.User, xp: int): + def add_xp(self, user_id: discord.User, xp: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["xp"] += xp with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def remove_xp(user_id: discord.User, xp: int): + def remove_xp(self, user_id: discord.User, xp: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["xp"] += xp with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def reset_xp(user_id: discord.User): + def reset_xp(self, user_id: discord.User): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["xp"] = 0 with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def edit_level(user_id: discord.User, level: int): + def edit_level(self, user_id: discord.User, level: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["level"] = level with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def edit_xp(user_id: discord.User, xp: int): + def edit_xp(self, user_id: discord.User, xp: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["xp"] = xp with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 + +class Weather(Colors): + """Class to manage the weather db""" + def __init__(self, db_path: str, log_path: str): + self.db_path = db_path + self.log_path = log_path + print(f"[Framework/Loader] {Colors.green}Weather database initialized.{Colors.end}") + + def new(self, user_id: discord.User): + with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) + if str(user_id) not in user_db: user_db[str(user_id)] = {"location": None, "scale": "Celsius"} + with open("database/weather.json", 'w+', encoding="utf-8") as f: json.dump(user_db, f, indent=4) + return 0 + def set_scale(self, user_id: discord.User, scale: str) -> int: + with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) + user_db[str(user_id)]["scale"] = scale + with open("database/weather.json", 'w+', encoding="utf-8") as f: json.dump(user_db, f, indent=4) + return 0 + + def set_default_location(self, user_id: discord.User, location: str) -> int: + with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) + user_db[str(user_id)]["location"] = location + with open("database/weather.json", 'w+', encoding="utf-8") as f: json.dump(user_db, f, indent=4) + return 0 + + def get_scale(self, user_id: discord.User): + with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) + return user_db[str(user_id)]["scale"] + + def get_default_location(self, user_id: discord.User): + with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) + return user_db[str(user_id)]["location"] From 119dc6231199e7d63ce599a2a6b37dba5075a3de Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 12:02:51 +0530 Subject: [PATCH 08/18] Fix framework import structure --- main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.py b/main.py index 32a23a0a..d597cd06 100644 --- a/main.py +++ b/main.py @@ -17,8 +17,7 @@ import framework.isobank.authorize import framework.isobank.manager import framework.isobot.embedengine -import framework.isobot.db.Items -import framework.isobot.db.Levels +import framework.isobot.db from discord import ApplicationContext, option from discord.ext import commands from discord.ext.commands import * From e6ebd024f1bfbb3aa9c22d8e70b528c385a43827 Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 12:03:40 +0530 Subject: [PATCH 09/18] Remove inactive database initializations --- main.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.py b/main.py index d597cd06..08c8bb9d 100644 --- a/main.py +++ b/main.py @@ -33,19 +33,14 @@ client = discord.Bot() color = discord.Color.random() wdir = os.getcwd() -# 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('database/levels.json', 'r', encoding="utf-8") as f: levels = json.load(f) with open('config/commands.json', 'r', encoding="utf-8") as f: commandsdb = json.load(f) with open('database/automod.json', 'r', encoding="utf-8") as f: automod_config = json.load(f) cmd_list = commandsdb.keys() #Pre-Initialization Commands def save(): - # with open('database/items.json', 'w+', encoding="utf-8") as f: json.dump(items, f, indent=4) with open('database/presence.json', 'w+', encoding="utf-8") as f: json.dump(presence, f, indent=4) - # with open('database/levels.json', 'w+', encoding="utf-8") as f: json.dump(levels, f, indent=4) with open('database/automod.json', 'w+', encoding="utf-8") as f: json.dump(automod_config, f, indent=4) if not os.path.isdir("logs"): From f9103d666ea4420c2df71749538a45278cf59f01 Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 12:05:00 +0530 Subject: [PATCH 10/18] Fix some arithmetic syntax errors --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 08c8bb9d..2ce42fe7 100644 --- a/main.py +++ b/main.py @@ -128,14 +128,14 @@ async def on_message(ctx): await asyncio.sleep(5) await m1.delete() if not ctx.author.bot: - levels.add_xp(ctx.author.id) += randint(1, 5) + levels.add_xp(ctx.author.id, randint(1, 5)) xpreq = 0 for level in range(int(levels.get_level(ctx.author.id))): xpreq += 50 if xpreq >= 5000: break if levels.get_xp(ctx.author.id) >= xpreq: - levels.reset_xp(ctx.author.id) = 0 - levels.add_levels(ctx.author.id) += 1 + levels.reset_xp(ctx.author.id) + levels.add_levels(ctx.author.id, 1) await ctx.author.send(f"{ctx.author.mention}, you just ranked up to **level {levels.get_level(ctx.author.id)}**. Nice!") save() if automod_config[str(ctx.guild.id)]["swear_filter"]["enabled"] == True: From 27f192beaf2666f857095d844a7043f4310f5c3f Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 12:06:37 +0530 Subject: [PATCH 11/18] Fix import structure error --- cogs/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/utils.py b/cogs/utils.py index 955ac73f..f68fb0a0 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -8,7 +8,7 @@ import openai import framework.isobot.embedengine import framework.isobot.currency -import framework.isobot.db.Levels +import framework.isobot.db from discord import option, ApplicationContext from discord.ext import commands from cogs.afk import get_presence From 88c241991ec06ee9ae1527ad042c9e2c40a57bab Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 12:07:43 +0530 Subject: [PATCH 12/18] Fix import structure error --- cogs/economy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/economy.py b/cogs/economy.py index e89289c4..d5d2cd1b 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -9,7 +9,7 @@ import utils.logger import asyncio import framework.isobot.currency -import framework.isobot.db.Levels +import framework.isobot.db from random import randint from discord import option, ApplicationContext from discord.ext import commands From 5126ef268b2770d063ad7dd47cde3fb747bab055 Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 12:09:13 +0530 Subject: [PATCH 13/18] Fix import structure error --- cogs/levelling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/levelling.py b/cogs/levelling.py index 1b91b6dc..e71df16f 100644 --- a/cogs/levelling.py +++ b/cogs/levelling.py @@ -4,7 +4,7 @@ import discord import json import os.path -import framework.isobot.db.Levels +import framework.isobot.db from discord import option, ApplicationContext from discord.ext import commands From c77a1b025bccb145d58b2b4b1b523aace090cab7 Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 12:10:04 +0530 Subject: [PATCH 14/18] Fix some arithmetic errors --- cogs/levelling.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/levelling.py b/cogs/levelling.py index e71df16f..77cc4fd4 100644 --- a/cogs/levelling.py +++ b/cogs/levelling.py @@ -54,7 +54,7 @@ async def rank(self, ctx: ApplicationContext, user:discord.User=None): async def edit_rank(self, ctx: ApplicationContext, user:discord.User, new_rank:int): if ctx.author.id != 738290097170153472: return await ctx.respond("This command isn't for you.", ephemeral=True) try: - levels.edit_level(user.id) = new_rank + levels.edit_level(user.id, new_rank) await ctx.respond(f"{user.display_name}\'s rank successfully edited. `New Rank: {levels.get_level(user.id)}`") except KeyError: return await ctx.respond("That user isn't indexed yet.", ephemeral=True) @@ -67,7 +67,7 @@ async def edit_rank(self, ctx: ApplicationContext, user:discord.User, new_rank:i async def edit_xp(self, ctx: ApplicationContext, user:discord.User, new_xp:int): if ctx.author.id != 738290097170153472: return await ctx.respond("This command isn't for you.", ephemeral=True) try: - levels.edit_xp(user.id) = new_xp + levels.edit_xp(user.id, new_xp) await ctx.respond(f"{user.display_name}\'s XP count successfully edited. `New XP: {levels.get_xp(user.id)}`") except KeyError: return await ctx.respond("That user isn't indexed yet.", ephemeral=True) From 73585cd2734e28fd05ff44dd98118826bd7a5be5 Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 06:55:41 +0000 Subject: [PATCH 15/18] Fix `shopitem` parsing error in `Items.new()` --- framework/isobot/db.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/framework/isobot/db.py b/framework/isobot/db.py index 9978bbd4..6a77a5a1 100644 --- a/framework/isobot/db.py +++ b/framework/isobot/db.py @@ -24,10 +24,7 @@ def __init__(self, db_path: str, log_path: str): def new(self, user_id: discord.User) -> int: with open(self.db_path, 'r') as f: items = json.load(f) if str(user_id) not in items: items[str(user_id)] = {} - with open("config/shop.json", "r") as f: - all_shopitems = json.load(f) - shopitem = list() - for x in all_shopitems: shopitem.append(x) + with open("config/shop.json", 'r') as f: shopitem = json.load(f) for z in shopitem.keys(): if z in items[str(user_id)]: pass else: items[str(user_id)][str(z)] = 0 From d865c040d8965ec39cd3fce6a791554a86cf3ed6 Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 06:58:02 +0000 Subject: [PATCH 16/18] Improve code quality --- framework/isobot/db.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/framework/isobot/db.py b/framework/isobot/db.py index 6a77a5a1..2b76bfaf 100644 --- a/framework/isobot/db.py +++ b/framework/isobot/db.py @@ -5,7 +5,7 @@ import discord import datetime -def get_time(self): +def get_time(): return datetime.datetime.now().strftime("%H:%M:%S") class Colors: @@ -16,6 +16,7 @@ class Colors: end = '\033[0m' class Items(Colors): + """Class to interact the items db""" def __init__(self, db_path: str, log_path: str): self.db_path = db_path self.log_path = log_path @@ -44,6 +45,7 @@ def remove_item(self, user_id: discord.User, item: str, quantity: int) -> int: return 0 class Levels(Colors): + """Class to interact the levels db""" def __init__(self, db_path: str, log_path: str): self.db_path = db_path self.log_path = log_path @@ -51,10 +53,11 @@ def __init__(self, db_path: str, log_path: str): def new(self, user_id: discord.User) -> int: with open(self.db_path, 'r') as f: levels = json.load(f) - if str(user_id) not in levels: levels[str(user_id)] = { - "xp": 0, - "level": 0 - } + if str(user_id) not in levels: + levels[str(user_id)] = { + "xp": 0, + "level": 0 + } with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 From 6ff0a1a0a41c2b57e0c4cafc2c014e22cb261217 Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 06:59:52 +0000 Subject: [PATCH 17/18] Simplify `discord.User` --- framework/isobot/db.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/framework/isobot/db.py b/framework/isobot/db.py index 2b76bfaf..ac2b12ed 100644 --- a/framework/isobot/db.py +++ b/framework/isobot/db.py @@ -2,7 +2,7 @@ # Imports import json -import discord +from discord import User import datetime def get_time(): @@ -22,7 +22,7 @@ def __init__(self, db_path: str, log_path: str): self.log_path = log_path print(f"[Framework/Loader] {Colors.green}Items database initialized.{Colors.end}") - def new(self, user_id: discord.User) -> int: + def new(self, user_id: User) -> int: with open(self.db_path, 'r') as f: items = json.load(f) if str(user_id) not in items: items[str(user_id)] = {} with open("config/shop.json", 'r') as f: shopitem = json.load(f) @@ -32,13 +32,13 @@ def new(self, user_id: discord.User) -> int: with open(self.db_path, 'w+') as f: json.dump(items, f, indent=4) return 0 - def add_item(self, user_id: discord.User, item: str, quantity: int) -> int: + def add_item(self, user_id: User, item: str, quantity: int) -> int: with open(self.db_path, 'r') as f: items = json.load(f) items[str(user_id)][item] += quantity with open(self.db_path, 'w+') as f: json.dump(items, f, indent=4) return 0 - def remove_item(self, user_id: discord.User, item: str, quantity: int) -> int: + def remove_item(self, user_id: User, item: str, quantity: int) -> int: with open(self.db_path, 'r') as f: items = json.load(f) items[str(user_id)][item] -= quantity with open(self.db_path, 'w+') as f: json.dump(items, f, indent=4) @@ -51,7 +51,7 @@ def __init__(self, db_path: str, log_path: str): self.log_path = log_path print(f"[Framework/Loader] {Colors.green}Levels database initialized.{Colors.end}") - def new(self, user_id: discord.User) -> int: + def new(self, user_id: User) -> int: with open(self.db_path, 'r') as f: levels = json.load(f) if str(user_id) not in levels: levels[str(user_id)] = { @@ -61,57 +61,57 @@ def new(self, user_id: discord.User) -> int: with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def get_level(self, user_id: discord.User) -> int: + def get_level(self, user_id: User) -> int: with open(self.db_path, 'r') as f: levels = json.load(f) return levels[str(user_id)]["level"] - def get_xp(self, user_id: discord.User) -> int: + def get_xp(self, user_id: User) -> int: with open(self.db_path, 'r') as f: levels = json.load(f) return levels[str(user_id)]["xp"] - def add_levels(self, user_id: discord.User, level: int): + def add_levels(self, user_id: User, level: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["level"] += level with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def remove_levels(self, user_id: discord.User, level: int): + def remove_levels(self, user_id: User, level: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["level"] += level with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def reset_level(self, user_id: discord.User): + def reset_level(self, user_id: User): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["level"] = 0 with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def add_xp(self, user_id: discord.User, xp: int): + def add_xp(self, user_id: User, xp: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["xp"] += xp with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def remove_xp(self, user_id: discord.User, xp: int): + def remove_xp(self, user_id: User, xp: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["xp"] += xp with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def reset_xp(self, user_id: discord.User): + def reset_xp(self, user_id: User): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["xp"] = 0 with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def edit_level(self, user_id: discord.User, level: int): + def edit_level(self, user_id: User, level: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["level"] = level with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) return 0 - def edit_xp(self, user_id: discord.User, xp: int): + def edit_xp(self, user_id: User, xp: int): with open(self.db_path, 'r') as f: levels = json.load(f) levels[str(user_id)]["xp"] = xp with open(self.db_path, 'w+') as f: json.dump(levels, f, indent=4) @@ -124,28 +124,28 @@ def __init__(self, db_path: str, log_path: str): self.log_path = log_path print(f"[Framework/Loader] {Colors.green}Weather database initialized.{Colors.end}") - def new(self, user_id: discord.User): + def new(self, user_id: User): with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) if str(user_id) not in user_db: user_db[str(user_id)] = {"location": None, "scale": "Celsius"} with open("database/weather.json", 'w+', encoding="utf-8") as f: json.dump(user_db, f, indent=4) return 0 - def set_scale(self, user_id: discord.User, scale: str) -> int: + def set_scale(self, user_id: User, scale: str) -> int: with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) user_db[str(user_id)]["scale"] = scale with open("database/weather.json", 'w+', encoding="utf-8") as f: json.dump(user_db, f, indent=4) return 0 - def set_default_location(self, user_id: discord.User, location: str) -> int: + def set_default_location(self, user_id: User, location: str) -> int: with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) user_db[str(user_id)]["location"] = location with open("database/weather.json", 'w+', encoding="utf-8") as f: json.dump(user_db, f, indent=4) return 0 - def get_scale(self, user_id: discord.User): + def get_scale(self, user_id: User): with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) return user_db[str(user_id)]["scale"] - def get_default_location(self, user_id: discord.User): + def get_default_location(self, user_id: User): with open("database/weather.json", 'r', encoding="utf-8") as f: user_db = json.load(f) return user_db[str(user_id)]["location"] From 56ea0e8b47cdbab1f6058df1d86a8c01fc70d0cb Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Sat, 24 Jun 2023 07:01:33 +0000 Subject: [PATCH 18/18] Add missing docstring --- framework/isobot/db.py | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/isobot/db.py b/framework/isobot/db.py index ac2b12ed..b1c9b08c 100644 --- a/framework/isobot/db.py +++ b/framework/isobot/db.py @@ -6,6 +6,7 @@ import datetime def get_time(): + """Fetches and returns the current time.""" return datetime.datetime.now().strftime("%H:%M:%S") class Colors: