diff --git a/.gitignore b/.gitignore index 45710aa..e287c0c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.json *.pyc !/main.py +!/test.2.py diff --git a/cogs/general.py b/cogs/general.py index 96cf727..8fe475c 100644 --- a/cogs/general.py +++ b/cogs/general.py @@ -4,7 +4,7 @@ import disnake from disnake import Option, OptionType, Colour from disnake.ext import commands -from lib.Comands import read_json, set_prefix, write_json +from lib.Comands import read_json, write_json from lib.DB import fill_bd, prepare_db, work_with_db, read_db @@ -106,7 +106,7 @@ class General(commands.Cog): @commands.command(name="set_prefix") @commands.has_permissions(administrator=True) async def command_set_prefix(self, ctx, prefix: str): - await set_prefix(ctx.guild.id, prefix) + await write_json(ctx.guild.id, "prefix", prefix) await ctx.reply(f"Prefix set to: `{prefix}`") @commands.guild_only() @@ -119,7 +119,7 @@ class General(commands.Cog): ) @commands.has_permissions(administrator=True) async def slash_set_prefix(self, inter, prefix: str): - await set_prefix(inter.guild.id, prefix) + await write_json(inter.guild.id, "prefix", prefix) await inter.response.send_message(f"Prefix set to: `{prefix}`", ephemeral=True) @commands.guild_only() @@ -152,7 +152,7 @@ class General(commands.Cog): @set_trigger_role.error @slash_set_prefix.error async def set_prefix_error(self, inter, prefix): - await inter.response.send_message('You don`t have permissions', ephemeral=True) + await inter.response.send_message("You don`t have permissions", ephemeral=True) def setup(bot): # an extension must have a setup function diff --git a/lib/Comands.py b/lib/Comands.py index ce2f4d3..e2764a0 100644 --- a/lib/Comands.py +++ b/lib/Comands.py @@ -2,10 +2,6 @@ import json from os import walk -async def set_prefix(guildid: int, prefix: str) -> None: - await write_json(guildid, "prefix", prefix) - - async def list_files(fold: str = 'audio'): fl = [] for filenames in walk(fold): @@ -17,7 +13,13 @@ async def list_files(fold: str = 'audio'): return fl[2] -async def read_json(guild: int, param: str): +async def read_json(guild: int, _param: str) -> int or str: + """ + Reads Json file to determite config strings + :param guild: ID of Guild + :param _param: Parameter in json file + :return: value of parameter + """ with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON try: _json = json.load(fp) # Load the custom prefixes @@ -27,9 +29,9 @@ async def read_json(guild: int, param: str): try: guild_conf = _json[f"{guild}"] try: - parameter = guild_conf[f"{param}"] + parameter = guild_conf[f"{_param}"] except: - pass + parameter = None except: pass diff --git a/lib/DB.py b/lib/DB.py index 78c6764..f66dd29 100644 --- a/lib/DB.py +++ b/lib/DB.py @@ -5,9 +5,8 @@ async def prepare_db(guild: int): try: connect = sqlite3.connect('user.db') cursor = connect.cursor() - create_table = (f'''CREATE TABLE IF NOT EXISTS "{guild}" - ([userid] INTEGER PRIMARY KEY, [username] TEXT, [nick] TEXT, [isbot] BOOL, [defaulttracks] TEXT, [usertracks] TEXT) - ''') + create_table = (f'''CREATE TABLE IF NOT EXISTS "{guild}" ([userid] INTEGER PRIMARY KEY, [username] TEXT, + [nick] TEXT, [isbot] BOOL, [defaulttracks] TEXT, [usertracks] TEXT) ''') cursor.execute(create_table) cursor.close() except sqlite3.Error as _error: