71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
from discord import SlashCommandGroup, option, CategoryChannel, ApplicationContext, TextChannel
|
|
from discord.ext.commands import Cog
|
|
|
|
from classes import PycordGuild
|
|
from classes.pycord_bot import PycordBot
|
|
|
|
|
|
class Config(Cog):
|
|
"""Cog with guild configuration commands."""
|
|
|
|
def __init__(self, bot: PycordBot):
|
|
self.bot: PycordBot = bot
|
|
|
|
# TODO Introduce i18n
|
|
command_group: SlashCommandGroup = SlashCommandGroup("config", "Guild management")
|
|
|
|
# TODO Introduce i18n
|
|
@command_group.command(
|
|
name="set",
|
|
description="Configure the guild",
|
|
)
|
|
@option("category", description="Category where channels for each user will be created", required=True)
|
|
@option("channel", description="Text channel for admin notifications", required=True)
|
|
async def command_config_set(
|
|
self, ctx: ApplicationContext, category: CategoryChannel, channel: TextChannel
|
|
) -> None:
|
|
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
|
|
|
await guild.set_channel(channel.id, cache=self.bot.cache)
|
|
await guild.set_category(category.id, cache=self.bot.cache)
|
|
|
|
# TODO Make a nice message
|
|
await ctx.respond("Okay.")
|
|
|
|
# TODO Introduce i18n
|
|
@command_group.command(
|
|
name="reset",
|
|
description="Reset the guild's configuration",
|
|
)
|
|
@option("confirm", description="Confirmation of the operation", required=False)
|
|
async def command_config_reset(self, ctx: ApplicationContext, confirm: bool = False) -> None:
|
|
if confirm is None or not confirm:
|
|
# TODO Make a nice message
|
|
await ctx.respond("Operation not confirmed.")
|
|
return
|
|
|
|
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
|
|
|
await guild.reset_channel(cache=self.bot.cache)
|
|
await guild.reset_category(cache=self.bot.cache)
|
|
|
|
# TODO Make a nice message
|
|
await ctx.respond("Okay.")
|
|
|
|
# TODO Introduce i18n
|
|
@command_group.command(
|
|
name="show",
|
|
description="Show the guild's configuration",
|
|
)
|
|
async def command_config_reset(self, ctx: ApplicationContext) -> None:
|
|
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
|
|
|
# TODO Make a nice message
|
|
await ctx.respond(
|
|
f"**Guild config**\n\nChannel: <#{guild.channel_id}>\nCategory: <#{guild.category_id}>"
|
|
)
|
|
|
|
|
|
def setup(bot: PycordBot) -> None:
|
|
bot.add_cog(Config(bot))
|