refractor lib code
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@
|
|||||||
*.json
|
*.json
|
||||||
*.pyc
|
*.pyc
|
||||||
!/main.py
|
!/main.py
|
||||||
|
!/test.2.py
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import disnake
|
|||||||
from disnake import Option, OptionType, Colour
|
from disnake import Option, OptionType, Colour
|
||||||
from disnake.ext import commands
|
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
|
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.command(name="set_prefix")
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def command_set_prefix(self, ctx, prefix: str):
|
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}`")
|
await ctx.reply(f"Prefix set to: `{prefix}`")
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@@ -119,7 +119,7 @@ class General(commands.Cog):
|
|||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def slash_set_prefix(self, inter, prefix: str):
|
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)
|
await inter.response.send_message(f"Prefix set to: `{prefix}`", ephemeral=True)
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@@ -152,7 +152,7 @@ class General(commands.Cog):
|
|||||||
@set_trigger_role.error
|
@set_trigger_role.error
|
||||||
@slash_set_prefix.error
|
@slash_set_prefix.error
|
||||||
async def set_prefix_error(self, inter, prefix):
|
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
|
def setup(bot): # an extension must have a setup function
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ import json
|
|||||||
from os import walk
|
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'):
|
async def list_files(fold: str = 'audio'):
|
||||||
fl = []
|
fl = []
|
||||||
for filenames in walk(fold):
|
for filenames in walk(fold):
|
||||||
@@ -17,7 +13,13 @@ async def list_files(fold: str = 'audio'):
|
|||||||
return fl[2]
|
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
|
with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON
|
||||||
try:
|
try:
|
||||||
_json = json.load(fp) # Load the custom prefixes
|
_json = json.load(fp) # Load the custom prefixes
|
||||||
@@ -27,9 +29,9 @@ async def read_json(guild: int, param: str):
|
|||||||
try:
|
try:
|
||||||
guild_conf = _json[f"{guild}"]
|
guild_conf = _json[f"{guild}"]
|
||||||
try:
|
try:
|
||||||
parameter = guild_conf[f"{param}"]
|
parameter = guild_conf[f"{_param}"]
|
||||||
except:
|
except:
|
||||||
pass
|
parameter = None
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ async def prepare_db(guild: int):
|
|||||||
try:
|
try:
|
||||||
connect = sqlite3.connect('user.db')
|
connect = sqlite3.connect('user.db')
|
||||||
cursor = connect.cursor()
|
cursor = connect.cursor()
|
||||||
create_table = (f'''CREATE TABLE IF NOT EXISTS "{guild}"
|
create_table = (f'''CREATE TABLE IF NOT EXISTS "{guild}" ([userid] INTEGER PRIMARY KEY, [username] TEXT,
|
||||||
([userid] INTEGER PRIMARY KEY, [username] TEXT, [nick] TEXT, [isbot] BOOL, [defaulttracks] TEXT, [usertracks] TEXT)
|
[nick] TEXT, [isbot] BOOL, [defaulttracks] TEXT, [usertracks] TEXT) ''')
|
||||||
''')
|
|
||||||
cursor.execute(create_table)
|
cursor.execute(create_table)
|
||||||
cursor.close()
|
cursor.close()
|
||||||
except sqlite3.Error as _error:
|
except sqlite3.Error as _error:
|
||||||
|
|||||||
Reference in New Issue
Block a user