Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion modules/operation/factoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,15 @@ async def factoid_call_command(

try:
# define the message and send it
await interaction.response.send_message(content=content, embed=embed)
view = DeleteView(interaction.user.id)

await interaction.response.send_message(
content=content,
embed=embed,
view=view,
)

view.message = await interaction.original_response()
# log it in the logging channel with type info and generic content
log_channel = configuration.get_config_entry(
interaction.guild.id, "core_logging_channel"
Expand Down Expand Up @@ -2834,3 +2842,45 @@ async def enable(
await auxiliary.send_confirm_embed(
message=f"`{factoid_name}` is now enabled", channel=ctx.channel
)


class DeleteView(discord.ui.View):
"""The class to hold the view for the delete button on /factoid call

Args:
author_id (int): The ID of the author of the factoid
"""

def __init__(self: Self, author_id: int) -> None:
super().__init__(timeout=60)
self.author_id = author_id
self.message: discord.Message | None = None

async def on_timeout(self: Self) -> None:
"""Is called after the timeout, with the goal of deleting the buttons from the message"""

if self.message:
await self.message.edit(view=None)

@discord.ui.button(label="Delete", style=discord.ButtonStyle.danger, emoji="🗑️")
async def delete_button(
self: Self,
interaction: discord.Interaction,
button: discord.ui.Button,
) -> None:
"""The function called when the delete button is pressed

Args:
interaction (discord.Interaction): The interaction that pressed the button
button (discord.ui.Button): The button object itself
"""

if interaction.user.id != self.author_id:
await interaction.response.send_message(
"Only the original caller can delete this message.",
ephemeral=True,
)
return

if interaction.message:
await interaction.message.delete()
Loading