all classes moved into file

some commands moved into cogs
This commit is contained in:
2022-07-02 12:46:43 +03:00
parent 0588a0c01c
commit 19e1d4226b
8 changed files with 278 additions and 331 deletions

View File

@@ -1,10 +1,12 @@
import logging
import discord
from discord.ext import commands
from dislash import Option, OptionType
import dislash
from test import DB
import lib
import discord
from discord.ext import commands
from dislash import Option, OptionType, slash_command
class General(commands.Cog):
@@ -13,18 +15,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():
lib.DB.prepare_db(g.guild.id)
for g in self.bot.get_all_members():
lib.DB.fill_bd(g.name, g.id, g.bot, g.nick, g.guild.id)
logging.info(f'Cog {__name__.split(".")[1]} is ready!.')
@cog_ext.cog_slash(
@slash_command(
name="info",
description="Read list of tracks for user",
options=[
Option("user", "Specify any user", OptionType.USER),
]
)
async def info(ctx, user=None):
async def info(self, ctx, user=None):
user = user or ctx.author
audio = DB.read_db(ctx.guild.id, user.id)
audio = lib.DB.read_db(ctx.guild.id, user.id)
rolelist = [r.mention for r in user.roles if r != ctx.guild.default_role]
if rolelist:
roles = "\n".join(rolelist)
@@ -52,6 +59,63 @@ class General(commands.Cog):
await ctx.reply(embed=emb, ephemeral=True)
@slash_command(
name="set_guest_role",
description="Set Default bot role",
options=[
Option("role", "Specify role", OptionType.ROLE, required=True),
]
)
@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 ctx.send(f"Setted up dsss bot role to: `{role.name}`", ephemeral=True)
def setup(bot): # a extension must have a setup function
@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)
@slash_command(
name="set_prefix",
description="Setting up bot prefix",
options=[
Option("prefix", "Specify prefix", OptionType.STRING, required=True),
]
)
@dislash.has_permissions(administrator=True)
async def slash_set_prefix(self, ctx, prefix: str):
await lib.Commands.set_prefix(ctx, prefix)
@slash_set_prefix.error
@command_set_prefix.error
async def set_prefix_error(self, ctx, prefix):
await ctx.reply('You don`t have permissions', ephemeral=True)
@slash_command(
name="set_trigger_role",
description="Setting up role to trigger bot",
options=[
Option("role", "Specify role", OptionType.ROLE, required=True),
]
)
@commands.has_permissions(administrator=True)
async def set_trigger_role(self, ctx, role):
await lib.Commands.write_json(ctx.guild.id, "tigger_role", role.id)
await ctx.send(f"Role to trigger set to : `{role.name}`", ephemeral=True)
@slash_command(
name="set_bot_role",
description="Set Default bot role",
options=[
Option("role", "Specify role", OptionType.ROLE, required=True),
]
)
@dislash.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 ctx.send(f"Setted up bot role to: `{role.name}`", ephemeral=True)
def setup(bot): # an extension must have a setup function
bot.add_cog(General(bot)) # adding a cog