refractor lib code

This commit is contained in:
2022-08-22 01:17:27 +03:00
parent ea3e9dd105
commit e1b782c2cb
5 changed files with 34 additions and 47 deletions

View File

@@ -25,6 +25,7 @@ class Audio(commands.Cog):
audio = await read_db(member.guild.id, member.id, 'usertracks')
from lib.Comands import list_files
audio_files = await list_files(f'audio/{member.id}')
logging.info(f"state changed to user {member}")
f = await list_files()
if role is not None and before.channel is None and role in member.roles:
track = randrange(0, len(f) - 1, 1)

View File

@@ -4,9 +4,8 @@ import disnake
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
from lib.DB import fill_bd, prepare_db, work_with_db, read_db
class General(commands.Cog):
@@ -29,12 +28,12 @@ class General(commands.Cog):
@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)
await fill_bd(member.name, member.id, member.bot, member.nick, member.guild.id)
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 bot_role or guest_role:
if member.bot == 0:
role = disnake.utils.get(member.guild.roles, id=guest_role)
else:
@@ -57,8 +56,8 @@ class General(commands.Cog):
)
async def info(self, inter, user=None):
user = user or inter.author
user_audio = await lib.DB.read_db(inter.guild.id, user.id, column='usertracks')
default_audio = await lib.DB.read_db(inter.guild.id, user.id, column='defaulttracks')
user_audio = await read_db(inter.guild.id, user.id, column='usertracks')
default_audio = await read_db(inter.guild.id, user.id, column='defaulttracks')
rolelist = [r.mention for r in user.roles if r != inter.guild.default_role]
if rolelist:
roles = "\n".join(rolelist)
@@ -100,9 +99,9 @@ class General(commands.Cog):
]
)
@commands.has_permissions(administrator=True)
async def set_guest_role(self, ctx, role):
await write_json(ctx.guild.id, "guest_role", role.id)
await ctx.send(f"Setted up dsss bot role to: `{role.name}`", ephemeral=True)
async def set_guest_role(self, inter, role):
await write_json(inter.guild.id, "guest_role", role.id)
await inter.response.send_message(f"Setted up dsss bot role to: `{role.name}`", ephemeral=True)
@commands.command(name="set_prefix")
@commands.has_permissions(administrator=True)
@@ -110,6 +109,7 @@ class General(commands.Cog):
await set_prefix(ctx.guild.id, prefix)
await ctx.reply(f"Prefix set to: `{prefix}`")
@commands.guild_only()
@commands.slash_command(
name="set_prefix",
description="Setting up bot prefix",
@@ -120,12 +120,9 @@ 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 inter.responce.send_message(f"Prefix set to: `{prefix}`", ephemeral=True)
@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(f"Prefix set to: `{prefix}`", ephemeral=True)
@commands.guild_only()
@commands.slash_command(
name="set_trigger_role",
description="Setting up role to trigger bot",
@@ -145,24 +142,17 @@ class General(commands.Cog):
Option("role", "Specify role", OptionType.role, required=True),
]
)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def set_bot_role(self, ctx, role):
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()
async def help(self, inter):
embed = disnake.Embed(
title='Help', description='', colour=disnake.Colour.blue())
embed.set_footer(text='Have fun!')
embed.add_field(
name='Prefix',
value=f'The current prefix for this server is {self.bot.command_prefix}',
inline=True)
logging.info(f'server prefix {self.bot.command_prefix}')
await inter.response.send_message(embed=embed, ephemeral=True)
@set_bot_role.error
@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)
def setup(bot): # an extension must have a setup function

View File

@@ -5,6 +5,8 @@ import disnake
import psutil
from disnake.ext import commands
from lib.Comands import determine_prefix
class Bot_info(commands.Cog, name='Bot Info'):
def __init__(self, bot):
@@ -23,10 +25,10 @@ class Bot_info(commands.Cog, name='Bot Info'):
description=f"General information on about bot",
)
# emb.set_thumbnail(self.bot.display_avatar)
emb.add_field(name="Bot ping", value=f'Bot ping: {round(self.bot.latency * 1000)}', inline=True)
emb.add_field(name="Memory Usage", value=f"{_process.memory_info()[0]/2**20} Mb", inline=True)
emb.add_field(name="CPU Usage", value=f"{_process.cpu_percent()}%", inline=True)
emb.add_field(name="Prefix", value=f"{self.bot.prefix}")
emb.add_field(name="System info:", value=f"Memory Usage: {round(_process.memory_info().rss / 2 ** 20, 2)} Mb\n"
f"CPU Usage: {_process.cpu_percent()}%\n"
f'Bot ping: {round(self.bot.latency * 1000)}\n'
f'Prefix: `{determine_prefix(self.bot, inter)}`')
emb.add_field(name="Bot owner", value=f"<@{self.bot.owner_id}>")
emb.set_footer(text="Information requested by: {}".format(inter.author.display_name))