115 lines
3.5 KiB
Python
115 lines
3.5 KiB
Python
from discord import (
|
|
ApplicationContext,
|
|
SlashCommandGroup,
|
|
User,
|
|
option,
|
|
)
|
|
from discord.ext.commands import Cog
|
|
|
|
from classes import PycordUser
|
|
from classes.pycord_bot import PycordBot
|
|
from modules.utils import is_operation_confirmed
|
|
|
|
|
|
class CogUser(Cog):
|
|
"""Cog with user management commands."""
|
|
|
|
def __init__(self, bot: PycordBot):
|
|
self.bot: PycordBot = bot
|
|
|
|
# TODO Introduce i18n
|
|
command_group: SlashCommandGroup = SlashCommandGroup("user", "User management")
|
|
|
|
# TODO Implement the command
|
|
@command_group.command(
|
|
name="create_channel",
|
|
description="Create channel for the user",
|
|
)
|
|
@option(
|
|
"user",
|
|
description="Selected user",
|
|
)
|
|
async def command_user_create_channel(self, ctx: ApplicationContext, user: User) -> None:
|
|
await ctx.respond("Not implemented.")
|
|
|
|
# TODO Implement the command
|
|
@command_group.command(
|
|
name="update_channel",
|
|
description="Update user's channel",
|
|
)
|
|
@option(
|
|
"user",
|
|
description="Selected user",
|
|
)
|
|
async def command_user_update_channel(self, ctx: ApplicationContext, user: User) -> None:
|
|
await ctx.respond("Not implemented.")
|
|
|
|
# TODO Implement the command
|
|
@command_group.command(
|
|
name="delete_channel",
|
|
description="Delete user's channel",
|
|
)
|
|
@option(
|
|
"user",
|
|
description="Selected user",
|
|
)
|
|
@option("confirm", description="Confirmation of the operation", required=False)
|
|
async def command_user_delete_channel(self, ctx: ApplicationContext, user: User, confirm: bool = False) -> None:
|
|
await ctx.respond("Not implemented.")
|
|
|
|
# TODO Introduce i18n
|
|
@command_group.command(
|
|
name="jail",
|
|
description="Jail the user",
|
|
)
|
|
@option(
|
|
"user",
|
|
description="Selected user",
|
|
)
|
|
@option("confirm", description="Confirmation of the operation", required=False)
|
|
async def command_user_jail(self, ctx: ApplicationContext, user: User, confirm: bool = False) -> None:
|
|
if not (await is_operation_confirmed(ctx, confirm)):
|
|
return
|
|
|
|
pycord_user: PycordUser = await self.bot.find_user(user, ctx.guild)
|
|
|
|
if pycord_user.is_jailed:
|
|
# TODO Introduce i18n
|
|
await ctx.respond(f"User **{user.display_name}** is already jailed.")
|
|
return
|
|
|
|
await pycord_user.jail(self.bot.cache)
|
|
|
|
# TODO Introduce i18n
|
|
await ctx.respond(f"User **{user.display_name}** has been jailed and cannot interact with events anymore.")
|
|
|
|
# TODO Introduce i18n
|
|
@command_group.command(
|
|
name="unjail",
|
|
description="Unjail the user",
|
|
)
|
|
@option(
|
|
"user",
|
|
description="Selected user",
|
|
)
|
|
@option("confirm", description="Confirmation of the operation", required=False)
|
|
async def command_user_unjail(self, ctx: ApplicationContext, user: User, confirm: bool = False) -> None:
|
|
if not (await is_operation_confirmed(ctx, confirm)):
|
|
return
|
|
|
|
pycord_user: PycordUser = await self.bot.find_user(user, ctx.guild)
|
|
|
|
if not pycord_user.is_jailed:
|
|
# TODO Introduce i18n
|
|
await ctx.respond(f"User **{user.display_name}** is not jailed.")
|
|
return
|
|
|
|
await pycord_user.unjail(self.bot.cache)
|
|
|
|
# TODO Introduce i18n
|
|
await ctx.respond(f"User **{user.display_name}** has been unjailed and can interact with events again.")
|
|
|
|
|
|
def setup(bot: PycordBot) -> None:
|
|
bot.add_cog(CogUser(bot))
|