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

@@ -12,5 +12,5 @@ class Audio(commands.Cog):
logging.info(f'Cog {__name__.split(".")[1]} is ready!.')
def setup(bot): # a extension must have a setup function
def setup(bot): # an extension must have a setup function
bot.add_cog(Audio(bot)) # adding a cog

View File

@@ -1,36 +0,0 @@
import logging
import discord
from discord.ext import commands
class Test_Cog(commands.Cog):
def __init__(self, bot):
self.bot = bot # defining bot as global var in class
@commands.Cog.listener() # this is a decorator for events/listeners
async def on_ready(self):
logging.info(f'Cog {__name__.split(".")[1]} is ready!.')
@commands.command() # this is for making a command
async def bot_info(self, ctx, bot):
# await ctx.send(f'Pong! {round(self.bot.latency * 1000)}')
emb = discord.Embed(
title=f"General information",
description=f"General information on about {bot}",
icon=bot.avatar_url
)
emb.set_thumbnail(url=bot.avatar_url)
emb.add_field(name="General info",
value=f"Username: {bot}\n"
f"Nickname: {bot.nick}\n"
f"Joined at: {bot.joined_at.strftime('%A, %B %d %Y @ %H:%M:%S')}", inline=False)
# emb.add_field(name="Audio list", value=f"{audios}", inline=True)
# emb.add_field(name="Roles list", value=f"{roles}", inline=True)
emb.set_footer(text="Information requested by: {}".format(ctx.author.display_name))
await ctx.reply(embed=emb, ephemeral=True)
def setup(bot): # a extension must have a setup function
bot.add_cog(Test_Cog(bot)) # adding a cog

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

31
cogs/info.py Normal file
View File

@@ -0,0 +1,31 @@
import logging
import discord
from discord.ext import commands
from dislash import slash_command
class Bot_info(commands.Cog):
def __init__(self, bot):
self.bot = bot # defining bot as global var in class
@commands.Cog.listener() # this is a decorator for events/listeners
async def on_ready(self):
logging.info(f'Cog {__name__.split(".")[1]} is ready!.')
@slash_command(name="info_bot") # this is for making a command
async def info_bot(self, ctx):
# await ctx.send(f'Pong! {round(self.bot.latency * 1000)}')
emb = discord.Embed(
title=f"General information",
description=f"General information on about bot",
)
emb.add_field(name="Bot ping", value=f'Bot ping: {round(self.bot.latency * 1000)}', inline=True)
# emb.add_field(name="Roles list", value=f"{roles}", inline=True)
emb.set_footer(text="Information requested by: {}".format(ctx.author.display_name))
await ctx.reply(embed=emb, ephemeral=True)
def setup(bot): # an extension must have a setup function
bot.add_cog(Bot_info(bot)) # adding a cog