refractor lib code

This commit is contained in:
2022-08-22 03:23:25 +03:00
parent e1b782c2cb
commit 89707a7e9a
4 changed files with 16 additions and 14 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@
*.json
*.pyc
!/main.py
!/test.2.py

View File

@@ -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

View File

@@ -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

View File

@@ -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: