From 385999a2f314ecdecbc2a6e20701c6ba53daf2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Sun, 3 Dec 2023 00:38:14 +0100 Subject: [PATCH] verein.reply_private -> ClubInfo.is_allowed --- lenaverse_bot/commands/verein.py | 25 ++++++++++--------------- lenaverse_bot/core/config.py | 12 ++++++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lenaverse_bot/commands/verein.py b/lenaverse_bot/commands/verein.py index c3cbeef..2161f5b 100644 --- a/lenaverse_bot/commands/verein.py +++ b/lenaverse_bot/commands/verein.py @@ -8,19 +8,6 @@ from ..core.config import CONFIG, FileCommand, InfoCommand _logger = logging.getLogger(__name__) -def reply_private(interaction: discord.Interaction, name: str) -> bool: - _logger.debug(f"User {interaction.user.name}({interaction.user.id}) used /{name}") - - # öffentliche Antwort in DM channels und in "allowed" channels - in_dm_channel = interaction.channel is not None and isinstance( - interaction.channel, discord.DMChannel - ) - in_allowed_channel = interaction.channel_id in CONFIG.ev_info.channels - - # private Antwort sonst - return not (in_dm_channel or in_allowed_channel) - - @functools.singledispatch def make_command(command) -> discord.app_commands.Command: raise NotImplementedError @@ -33,11 +20,15 @@ def _(command: FileCommand) -> discord.app_commands.Command: 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=reply_private(interaction, command.name), + ephemeral=not CONFIG.ev_info.in_allowed_channel(interaction), file=file, ) @@ -57,10 +48,14 @@ def _(command: InfoCommand) -> discord.app_commands.Command: 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=reply_private(interaction, command.name), + ephemeral=not CONFIG.ev_info.in_allowed_channel(interaction), ) return cmd diff --git a/lenaverse_bot/core/config.py b/lenaverse_bot/core/config.py index 490c54d..eb5bdcb 100644 --- a/lenaverse_bot/core/config.py +++ b/lenaverse_bot/core/config.py @@ -68,6 +68,18 @@ class ClubInfo(BaseModel): fest: InfoCommand aktion: InfoCommand + def in_allowed_channel(self, interaction: discord.Interaction) -> bool: + if interaction.channel is None: + return False + + # öffentliche Antwort erlaubt in: + # - DM channels + # - "allowed" channels + is_dm_channel = isinstance(interaction.channel, discord.DMChannel) + is_listed = interaction.channel.id in self.channels + + return is_dm_channel or is_listed + class Config(BaseModel): discord_token: str