Skip to content

Commit

Permalink
Add /snipe
Browse files Browse the repository at this point in the history
  • Loading branch information
stekc committed Sep 5, 2024
1 parent 1a26d60 commit 3211bfd
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cogs/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import io
import platform

Expand All @@ -15,6 +16,19 @@ class Utilities(commands.Cog, name="utilities"):
def __init__(self, bot):
self.bot = bot
self.bot.allowed_mentions = discord.AllowedMentions.none()
self.last_deleted_messages = {}

@commands.Cog.listener()
async def on_message_delete(self, message):
if not message.guild:
return
self.last_deleted_messages[message.channel.id] = message

asyncio.create_task(self.remove_deleted_message(message.channel.id))

async def remove_deleted_message(self, channel_id):
await asyncio.sleep(60)
self.last_deleted_messages.pop(channel_id, None)

@commands.hybrid_command(
name="steal",
Expand Down Expand Up @@ -75,6 +89,34 @@ async def info(self, context: Context) -> None:
)
await context.send(embed=embed)

@commands.hybrid_command(
name="snipe",
description="Show the last deleted message in the channel.",
)
@commands.has_permissions(manage_messages=True)
@app_commands.guild_only()
async def snipe(self, context: Context) -> None:
message = self.last_deleted_messages.get(context.channel.id)
if message is None:
embed = discord.Embed(
description="There are no recently deleted messages in this channel.",
color=discord.Color.red(),
)
await context.send(embed=embed, ephemeral=True)
return

embed = discord.Embed(
description=message.content,
color=await get_color(message.author.avatar.url),
)
embed.set_author(
name=message.author.display_name + " deleted a message",
icon_url=message.author.avatar.url,
)
embed.timestamp = message.created_at

await context.send(embed=embed)


async def setup(bot):
await bot.add_cog(Utilities(bot))

0 comments on commit 3211bfd

Please sign in to comment.