mirror of
https://code.lenaisten.de/Lenaisten/lenaverse-bot.git
synced 2024-12-22 19:13:01 +00:00
code deduplication
This commit is contained in:
parent
29af971c39
commit
320126fc23
3 changed files with 43 additions and 128 deletions
|
@ -1,15 +0,0 @@
|
|||
import discord
|
||||
from discord.app_commands import locale_str
|
||||
from discord.utils import MISSING
|
||||
|
||||
from .config import CONFIG
|
||||
|
||||
|
||||
def ev_command(
|
||||
name: str,
|
||||
description: str | locale_str = MISSING,
|
||||
):
|
||||
return discord.app_commands.command(
|
||||
name=CONFIG.command_prefix + name,
|
||||
description=description,
|
||||
)
|
|
@ -4,7 +4,6 @@ from enum import Enum, auto
|
|||
import discord
|
||||
from discord import ui
|
||||
|
||||
from ._helpers import ev_command
|
||||
from .config import CONFIG
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
@ -93,7 +92,7 @@ class PostModal(ui.Modal, title="Post verfassen"):
|
|||
)
|
||||
|
||||
|
||||
@ev_command(name="post")
|
||||
@discord.app_commands.command(name=CONFIG.command_prefix + "post")
|
||||
async def post(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Einen Post im Lenaisten-Bereich verfassen (nur für ausgewählte Mitglieder verfügbar)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import functools
|
||||
import logging
|
||||
|
||||
import discord
|
||||
|
||||
from ._helpers import ev_command
|
||||
from .config import CONFIG
|
||||
from .config import CONFIG, FileCommand, InfoCommand
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -13,122 +13,53 @@ def reply_private(interaction: discord.Interaction, name: str) -> bool:
|
|||
return interaction.channel_id not in CONFIG.ev_info.channels
|
||||
|
||||
|
||||
@ev_command(
|
||||
name=CONFIG.ev_info.info.name,
|
||||
description=CONFIG.ev_info.info.description,
|
||||
)
|
||||
async def info(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Allgemeine Infos zum Verein
|
||||
"""
|
||||
@functools.singledispatch
|
||||
def make_command(command) -> discord.app_commands.Command:
|
||||
raise NotImplementedError
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.info.content,
|
||||
suppress_embeds=True,
|
||||
ephemeral=reply_private(interaction, CONFIG.ev_info.info.name),
|
||||
|
||||
@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:
|
||||
if (file := await command.as_discord_file) is not None:
|
||||
await interaction.response.send_message(
|
||||
content=command.content,
|
||||
suppress_embeds=True,
|
||||
ephemeral=reply_private(interaction, command.name),
|
||||
file=file,
|
||||
)
|
||||
|
||||
else:
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.command_failed,
|
||||
ephemeral=True,
|
||||
)
|
||||
|
||||
return cmd
|
||||
|
||||
|
||||
@ev_command(
|
||||
name=CONFIG.ev_info.vorstand.name,
|
||||
description=CONFIG.ev_info.vorstand.description,
|
||||
)
|
||||
async def vorstand(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Wer ist im Vereinsvorstand?
|
||||
"""
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.vorstand.content,
|
||||
silent=True,
|
||||
suppress_embeds=True,
|
||||
ephemeral=reply_private(interaction, CONFIG.ev_info.vorstand.name),
|
||||
@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:
|
||||
await interaction.response.send_message(
|
||||
content=command.content,
|
||||
suppress_embeds=True,
|
||||
ephemeral=reply_private(interaction, command.name),
|
||||
)
|
||||
|
||||
|
||||
@ev_command(
|
||||
name=CONFIG.ev_info.linktree.name,
|
||||
description=CONFIG.ev_info.linktree.description,
|
||||
)
|
||||
async def linktree(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Links rund um den Verein
|
||||
"""
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.linktree.content,
|
||||
suppress_embeds=True,
|
||||
ephemeral=reply_private(interaction, CONFIG.ev_info.linktree.name),
|
||||
)
|
||||
|
||||
|
||||
@ev_command(
|
||||
name=CONFIG.ev_info.beitreten.name,
|
||||
description=CONFIG.ev_info.beitreten.description,
|
||||
)
|
||||
async def beitreten(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Wie und warum dem Verein beitreten
|
||||
"""
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.beitreten.content,
|
||||
suppress_embeds=True,
|
||||
ephemeral=reply_private(interaction, CONFIG.ev_info.beitreten.name),
|
||||
)
|
||||
|
||||
# if (file := await CONFIG.ev_info.beitreten.as_discord_file) is not None:
|
||||
# await interaction.response.send_message(
|
||||
# content=CONFIG.ev_info.beitreten.content,
|
||||
# file=file,
|
||||
# suppress_embeds=True,
|
||||
# ephemeral=reply_private(interaction, CONFIG.ev_info.beitreten.name),
|
||||
# )
|
||||
|
||||
# else:
|
||||
# await interaction.response.send_message(
|
||||
# content=CONFIG.command_failed,
|
||||
# ephemeral=True,
|
||||
# )
|
||||
|
||||
|
||||
@ev_command(
|
||||
name=CONFIG.ev_info.fest.name,
|
||||
description=CONFIG.ev_info.fest.description,
|
||||
)
|
||||
async def fest(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Infos zum nächsten Vereinsfest
|
||||
"""
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.fest.content,
|
||||
suppress_embeds=True,
|
||||
ephemeral=reply_private(interaction, CONFIG.ev_info.fest.name),
|
||||
)
|
||||
|
||||
|
||||
@ev_command(
|
||||
name=CONFIG.ev_info.aktion.name,
|
||||
description=CONFIG.ev_info.aktion.description,
|
||||
)
|
||||
async def aktion(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Infos zu aktuellen Aktionen
|
||||
"""
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.aktion.content,
|
||||
suppress_embeds=True,
|
||||
ephemeral=reply_private(interaction, CONFIG.ev_info.aktion.name),
|
||||
)
|
||||
return cmd
|
||||
|
||||
|
||||
COMMANDS = [
|
||||
info,
|
||||
vorstand,
|
||||
linktree,
|
||||
beitreten,
|
||||
fest,
|
||||
aktion,
|
||||
make_command(attr)
|
||||
for name in CONFIG.ev_info.model_dump().keys()
|
||||
if isinstance(attr := getattr(CONFIG.ev_info, name), InfoCommand)
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue