verein.reply_private -> ClubInfo.is_allowed
This commit is contained in:
parent
c913e63f51
commit
385999a2f3
2 changed files with 22 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue