refractor lib code
This commit is contained in:
@@ -5,6 +5,8 @@ from disnake import Option, OptionType, Colour
|
||||
from disnake.ext import commands
|
||||
|
||||
import lib
|
||||
from lib.Comands import read_json, set_prefix, write_json
|
||||
from lib.DB import fill_bd, prepare_db, work_with_db
|
||||
|
||||
|
||||
class General(commands.Cog):
|
||||
@@ -14,23 +16,23 @@ class General(commands.Cog):
|
||||
@commands.Cog.listener() # this is a decorator for events/listeners
|
||||
async def on_ready(self):
|
||||
for g in self.bot.get_all_members():
|
||||
await lib.DB.prepare_db(g.guild.id)
|
||||
await prepare_db(g.guild.id)
|
||||
for g in self.bot.get_all_members():
|
||||
await lib.DB.fill_bd(g.name, g.id, g.bot, g.nick, g.guild.id)
|
||||
await fill_bd(g.name, g.id, g.bot, g.nick, g.guild.id)
|
||||
|
||||
logging.info(f'Cog {__name__.split(".")[1]} is ready!.')
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_join(self, guild):
|
||||
for g in guild.members:
|
||||
await lib.DB.fill_bd(g.name, g.id, g.bot, g.nick, guild.id)
|
||||
await fill_bd(g.name, g.id, g.bot, g.nick, guild.id)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_join(self, member):
|
||||
await lib.DB.fill_bd(member.name, member.id, member.bot, member.nick, member.guild.id)
|
||||
|
||||
bot_role = lib.Commands.read_json(member.guild.id, 'bot_role') # Get bot role
|
||||
guest_role = lib.Commands.read_json(member.guild.id, 'guest_role') # Get guest role
|
||||
bot_role = read_json(member.guild.id, 'bot_role') # Get bot role
|
||||
guest_role = read_json(member.guild.id, 'guest_role') # Get guest role
|
||||
|
||||
if bot_role and guest_role:
|
||||
if member.bot == 0:
|
||||
@@ -44,7 +46,7 @@ class General(commands.Cog):
|
||||
async def on_member_update(self, before: disnake.Member, after: disnake.Member):
|
||||
sql_update_query = f"""UPDATE "{after.guild.id}" set nick = ? where userid = ?"""
|
||||
data_tuple = (after.nick, before.id)
|
||||
await lib.DB.work_with_db(sql_update_query, data_tuple)
|
||||
await work_with_db(sql_update_query, data_tuple)
|
||||
|
||||
@commands.slash_command(
|
||||
name="info",
|
||||
@@ -99,13 +101,13 @@ class General(commands.Cog):
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def set_guest_role(self, ctx, role):
|
||||
await lib.Commands.write_json(ctx.guild.id, "guest_role", role.id)
|
||||
await write_json(ctx.guild.id, "guest_role", role.id)
|
||||
await ctx.send(f"Setted up dsss bot role to: `{role.name}`", ephemeral=True)
|
||||
|
||||
@commands.command(name="set_prefix")
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def command_set_prefix(self, ctx, prefix: str):
|
||||
await lib.Commands.set_prefix(ctx, prefix)
|
||||
await set_prefix(ctx.guild.id, prefix)
|
||||
await ctx.reply(f"Prefix set to: `{prefix}`")
|
||||
|
||||
@commands.slash_command(
|
||||
@@ -117,7 +119,7 @@ class General(commands.Cog):
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def slash_set_prefix(self, inter, prefix: str):
|
||||
await lib.Commands.set_prefix(inter, prefix)
|
||||
await set_prefix(inter.guild.id, prefix)
|
||||
await inter.responce.send_message(f"Prefix set to: `{prefix}`", ephemeral=True)
|
||||
|
||||
@slash_set_prefix.error
|
||||
@@ -133,7 +135,7 @@ class General(commands.Cog):
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def set_trigger_role(self, inter, role):
|
||||
await lib.Commands.write_json(inter.guild.id, "tigger_role", role.id)
|
||||
await write_json(inter.guild.id, "tigger_role", role.id)
|
||||
await inter.response.send_message(f"Role to trigger set to : `{role.name}`", ephemeral=True)
|
||||
|
||||
@commands.slash_command(
|
||||
@@ -145,7 +147,7 @@ class General(commands.Cog):
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def set_bot_role(self, ctx, role):
|
||||
await lib.Commands.write_json(ctx.guild.id, "bot_role", role.id)
|
||||
await write_json(ctx.guild.id, "bot_role", role.id)
|
||||
await ctx.send(f"Setted up bot role to: `{role.name}`", ephemeral=True)
|
||||
|
||||
@commands.slash_command()
|
||||
|
||||
Reference in New Issue
Block a user