mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-16 18:50:13 +00:00
Delete PluralKit posts by reaction
Add a 🗑 reaction to posts like system cards and member lists that deletes the message when the command author reacts
This commit is contained in:
parent
15ccc4e27a
commit
d5e36d7f81
4 changed files with 46 additions and 7 deletions
|
|
@ -164,6 +164,16 @@ class CommandContext:
|
|||
except asyncio.TimeoutError:
|
||||
raise CommandError("Timed out - try again.")
|
||||
|
||||
async def delete_by_react(self, user: Union[discord.Member, discord.User], message: discord.Message):
|
||||
try:
|
||||
await message.add_reaction("🗑") # Wastebasket
|
||||
reaction, _ = await self.client.wait_for("reaction_add", check=lambda r, u: u.id == user.id and r.emoji in ["🗑"],
|
||||
timeout=60 * 10) # 10 minute timeout
|
||||
return reaction.emoji == "🗑"
|
||||
except asyncio.TimeoutError:
|
||||
# Delete the reaction if the user doesn't react within the timeout period
|
||||
await message.remove_reaction("🗑", self.client.user)
|
||||
|
||||
|
||||
import pluralkit.bot.commands.api_commands
|
||||
import pluralkit.bot.commands.import_commands
|
||||
|
|
|
|||
|
|
@ -51,7 +51,10 @@ async def specific_member_root(ctx: CommandContext):
|
|||
|
||||
|
||||
async def member_info(ctx: CommandContext, member: Member):
|
||||
await ctx.reply(embed=await pluralkit.bot.embeds.member_card(ctx.conn, member))
|
||||
msg = await ctx.reply(embed=await pluralkit.bot.embeds.member_card(ctx.conn, member))
|
||||
if await ctx.delete_by_react(ctx.message.author, msg):
|
||||
await msg.delete()
|
||||
await ctx.message.delete()
|
||||
|
||||
|
||||
async def new_member(ctx: CommandContext):
|
||||
|
|
|
|||
|
|
@ -15,4 +15,7 @@ async def message_info(ctx: CommandContext):
|
|||
raise CommandError(
|
||||
"Message with ID '{}' not found. Are you sure it's a message proxied by PluralKit?".format(mid))
|
||||
|
||||
await ctx.reply(embed=await embeds.message_card(ctx.client, message))
|
||||
msg = await ctx.reply(embed=await embeds.message_card(ctx.client, message))
|
||||
if await ctx.delete_by_react(ctx.message.author, msg):
|
||||
await msg.delete()
|
||||
await ctx.message.delete()
|
||||
|
|
@ -74,8 +74,11 @@ async def specified_system_root(ctx: CommandContext):
|
|||
|
||||
async def system_info(ctx: CommandContext, system: System):
|
||||
this_system = await ctx.get_system()
|
||||
await ctx.reply(embed=await pluralkit.bot.embeds.system_card(ctx.conn, ctx.client, system, this_system and this_system.id == system.id))
|
||||
msg = await ctx.reply(embed=await pluralkit.bot.embeds.system_card(ctx.conn, ctx.client, system, this_system and this_system.id == system.id))
|
||||
|
||||
if await ctx.delete_by_react(ctx.message.author, msg):
|
||||
await msg.delete()
|
||||
await ctx.message.delete()
|
||||
|
||||
async def system_new(ctx: CommandContext):
|
||||
new_name = ctx.remaining() or None
|
||||
|
|
@ -265,7 +268,11 @@ async def system_fronthistory(ctx: CommandContext, system: System):
|
|||
|
||||
embed = embeds.status("\n".join(lines) or "(none)")
|
||||
embed.title = "Past switches"
|
||||
await ctx.reply(embed=embed)
|
||||
msg = await ctx.reply(embed=embed)
|
||||
|
||||
if await ctx.delete_by_react(ctx.message.author, msg):
|
||||
await msg.delete()
|
||||
await ctx.message.delete()
|
||||
|
||||
|
||||
async def system_delete(ctx: CommandContext):
|
||||
|
|
@ -362,7 +369,11 @@ async def system_frontpercent(ctx: CommandContext, system: System):
|
|||
|
||||
embed.set_footer(text="Since {} ({} ago)".format(ctx.format_time(span_start),
|
||||
display_relative(span_start)))
|
||||
await ctx.reply(embed=embed)
|
||||
msg = await ctx.reply(embed=embed)
|
||||
|
||||
if await ctx.delete_by_react(ctx.message.author, msg):
|
||||
await msg.delete()
|
||||
await ctx.message.delete()
|
||||
|
||||
async def system_list(ctx: CommandContext, system: System):
|
||||
# TODO: refactor this
|
||||
|
|
@ -372,7 +383,10 @@ async def system_list(ctx: CommandContext, system: System):
|
|||
page_size = 8
|
||||
if len(all_members) <= page_size:
|
||||
# If we have less than 8 members, don't bother paginating
|
||||
await ctx.reply(embed=embeds.member_list_full(system, all_members, 0, page_size))
|
||||
msg = await ctx.reply(embed=embeds.member_list_full(system, all_members, 0, page_size))
|
||||
if await ctx.delete_by_react(ctx.message.author, msg):
|
||||
await msg.delete()
|
||||
await ctx.message.delete()
|
||||
else:
|
||||
current_page = 0
|
||||
msg: discord.Message = None
|
||||
|
|
@ -385,6 +399,9 @@ async def system_list(ctx: CommandContext, system: System):
|
|||
msg = await ctx.reply(embed=embed)
|
||||
await msg.add_reaction("\u2B05")
|
||||
await msg.add_reaction("\u27A1")
|
||||
if await ctx.delete_by_react(ctx.message.author, msg):
|
||||
await msg.delete()
|
||||
await ctx.message.delete()
|
||||
else:
|
||||
await msg.edit(embed=embed)
|
||||
|
||||
|
|
@ -413,7 +430,10 @@ async def system_list(ctx: CommandContext, system: System):
|
|||
page_size = 25
|
||||
if len(all_members) <= page_size:
|
||||
# If we have less than 25 members, don't bother paginating
|
||||
await ctx.reply(embed=embeds.member_list_short(system, all_members, 0, page_size))
|
||||
msg = await ctx.reply(embed=embeds.member_list_short(system, all_members, 0, page_size))
|
||||
if await ctx.delete_by_react(ctx.message.author, msg):
|
||||
await msg.delete()
|
||||
await ctx.message.delete()
|
||||
else:
|
||||
current_page = 0
|
||||
msg: discord.Message = None
|
||||
|
|
@ -425,6 +445,9 @@ async def system_list(ctx: CommandContext, system: System):
|
|||
msg = await ctx.reply(embed=embed)
|
||||
await msg.add_reaction("\u2B05")
|
||||
await msg.add_reaction("\u27A1")
|
||||
if await ctx.delete_by_react(ctx.message.author, msg):
|
||||
await msg.delete()
|
||||
await ctx.message.delete()
|
||||
else:
|
||||
await msg.edit(embed=embed)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue