2023-01-17 16:50:47 +02:00
|
|
|
from discord import ApplicationContext, Option, SlashCommandGroup, CategoryChannel
|
|
|
|
from discord.ext import commands
|
2023-04-19 15:21:39 +03:00
|
|
|
from functions import (
|
|
|
|
getMsg,
|
|
|
|
guildConfGet,
|
|
|
|
guildConfReset,
|
|
|
|
guildConfSet,
|
|
|
|
loadJson,
|
|
|
|
makeEmbed,
|
|
|
|
strToColor,
|
|
|
|
)
|
2023-01-17 16:50:47 +02:00
|
|
|
|
|
|
|
|
2023-04-19 15:21:39 +03:00
|
|
|
# =========================================================================================================================
|
|
|
|
class CogCategory(commands.Cog):
|
2023-01-17 16:50:47 +02:00
|
|
|
def __init__(self, client):
|
|
|
|
self.client = client
|
|
|
|
|
2023-04-19 15:21:39 +03:00
|
|
|
category = SlashCommandGroup(
|
|
|
|
"category", "Commands related to parent channels category"
|
|
|
|
)
|
2023-01-17 16:50:47 +02:00
|
|
|
|
2023-04-19 15:21:39 +03:00
|
|
|
@category.command(
|
|
|
|
name="set",
|
|
|
|
description="Select the voice channel that will be parent to private ones",
|
|
|
|
)
|
|
|
|
async def category_set(self, ctx: ApplicationContext, category: Option(CategoryChannel, "Parent Channel Category")): # type: ignore
|
2023-01-17 16:50:47 +02:00
|
|
|
config = loadJson("config.json")
|
|
|
|
if ctx.guild is not None:
|
|
|
|
guildConfSet(ctx.guild, "category", category.id)
|
2023-04-19 15:21:39 +03:00
|
|
|
await ctx.respond(
|
|
|
|
embed=makeEmbed(
|
|
|
|
title=getMsg("set_category_title", ctx.guild),
|
|
|
|
description=getMsg("set_category_description", ctx.guild).format(
|
|
|
|
category.name
|
|
|
|
),
|
|
|
|
color=strToColor(config["color_ok"]),
|
|
|
|
)
|
|
|
|
)
|
2023-01-17 16:50:47 +02:00
|
|
|
if guildConfGet(ctx.guild, "channel") is None:
|
2023-04-19 15:21:39 +03:00
|
|
|
await ctx.respond(
|
|
|
|
embed=makeEmbed(
|
|
|
|
title=getMsg("hint_none_channel_title", ctx.guild),
|
|
|
|
description=getMsg("hint_none_channel_description", ctx.guild),
|
|
|
|
color=strToColor(config["color_warn"]),
|
|
|
|
)
|
|
|
|
)
|
2023-01-17 16:50:47 +02:00
|
|
|
else:
|
2023-04-19 15:21:39 +03:00
|
|
|
await ctx.respond(
|
|
|
|
embed=makeEmbed(
|
|
|
|
title=getMsg("dm_title", ctx.guild),
|
|
|
|
description=getMsg("dm_description", ctx.guild),
|
|
|
|
color=strToColor(config["color_error"]),
|
|
|
|
)
|
|
|
|
)
|
2023-01-17 16:50:47 +02:00
|
|
|
|
2023-04-19 15:21:39 +03:00
|
|
|
@category.command(
|
|
|
|
name="reset", description="Reset the currently selected parent channel category"
|
|
|
|
)
|
|
|
|
async def category_reset(self, ctx: ApplicationContext): # type: ignore
|
2023-01-17 16:50:47 +02:00
|
|
|
config = loadJson("config.json")
|
|
|
|
if ctx.guild is not None:
|
|
|
|
if guildConfGet(ctx.guild, "category") is not None:
|
|
|
|
guildConfReset(ctx.guild, "category")
|
2023-04-19 15:21:39 +03:00
|
|
|
await ctx.respond(
|
|
|
|
embed=makeEmbed(
|
|
|
|
title=getMsg("reset_category_title", ctx.guild),
|
|
|
|
description=getMsg("reset_category_description", ctx.guild),
|
|
|
|
color=strToColor(config["color_ok"]),
|
|
|
|
)
|
|
|
|
)
|
2023-01-17 16:50:47 +02:00
|
|
|
else:
|
2023-04-19 15:21:39 +03:00
|
|
|
await ctx.respond(
|
|
|
|
embed=makeEmbed(
|
|
|
|
title=getMsg("hint_none_category_title", ctx.guild),
|
|
|
|
description=getMsg("hint_none_category_description", ctx.guild),
|
|
|
|
color=strToColor(config["color_warn"]),
|
|
|
|
)
|
|
|
|
)
|
2023-01-17 16:50:47 +02:00
|
|
|
else:
|
2023-04-19 15:21:39 +03:00
|
|
|
await ctx.respond(
|
|
|
|
embed=makeEmbed(
|
|
|
|
title=getMsg("dm_title", ctx.guild),
|
|
|
|
description=getMsg("dm_description", ctx.guild),
|
|
|
|
color=strToColor(config["color_error"]),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# =========================================================================================================================
|