mirror of
https://code.lenaisten.de/Lenaisten/lenaverse-bot.git
synced 2024-11-24 16:02:59 +00:00
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
import functools
|
|
import logging
|
|
|
|
import discord
|
|
|
|
from ..core.config import CONFIG, FileCommand, InfoCommand
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
@functools.singledispatch
|
|
def make_command(command) -> discord.app_commands.Command:
|
|
raise NotImplementedError
|
|
|
|
|
|
@make_command.register
|
|
def _(command: FileCommand) -> discord.app_commands.Command:
|
|
@discord.app_commands.command(
|
|
name=CONFIG.command_prefix + command.name,
|
|
description=command.description,
|
|
)
|
|
async def cmd(interaction: discord.Interaction) -> None:
|
|
_logger.debug(
|
|
f"User {interaction.user.name}({interaction.user.id}) used FileCommand /{command.name}"
|
|
)
|
|
|
|
if (file := await command.as_discord_file) is not None:
|
|
await interaction.response.send_message(
|
|
content=command.content,
|
|
suppress_embeds=True,
|
|
ephemeral=not CONFIG.ev_info.in_allowed_channel(interaction),
|
|
file=file,
|
|
)
|
|
|
|
else:
|
|
await interaction.response.send_message(
|
|
content=CONFIG.command_failed,
|
|
ephemeral=True,
|
|
)
|
|
|
|
return cmd
|
|
|
|
|
|
@make_command.register
|
|
def _(command: InfoCommand) -> discord.app_commands.Command:
|
|
@discord.app_commands.command(
|
|
name=CONFIG.command_prefix + command.name,
|
|
description=command.description,
|
|
)
|
|
async def cmd(interaction: discord.Interaction) -> None:
|
|
_logger.debug(
|
|
f"User {interaction.user.name}({interaction.user.id}) used InfoCommand /{command.name}"
|
|
)
|
|
|
|
await interaction.response.send_message(
|
|
content=command.content,
|
|
suppress_embeds=True,
|
|
ephemeral=not CONFIG.ev_info.in_allowed_channel(interaction),
|
|
)
|
|
|
|
return cmd
|
|
|
|
|
|
COMMANDS = [
|
|
make_command(attr)
|
|
for name in CONFIG.ev_info.model_dump().keys()
|
|
if isinstance(attr := getattr(CONFIG.ev_info, name), InfoCommand)
|
|
]
|