-
Notifications
You must be signed in to change notification settings - Fork 4
/
snipe.py
148 lines (111 loc) · 4.95 KB
/
snipe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import discord
from discord.ext import commands
import DiscordUtils
from discord.ext.commands import has_permissions, MissingPermissions
import datetime
class Snipe(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.description = (
" <:sucess:935052640449077248> Commands to snipe out messages that people try to hide"
)
self.theme_color = discord.Color.blue()
self.deleted_msgs = {}
self.edited_msgs = {}
self.snipe_limit = 20
@commands.Cog.listener()
async def on_message_delete(self, message: discord.Message):
ch_id = message.channel.id
if message.content:
if ch_id not in self.deleted_msgs:
self.deleted_msgs[ch_id] = []
self.deleted_msgs[ch_id].append(message)
try:
if len(self.deleted_msgs[ch_id]) > self.snipe_limit:
self.deleted_msgs[ch_id].pop(0)
except:
pass
@commands.Cog.listener()
async def on_message_edit(
self, before: discord.Message, after: discord.Message
):
ch_id = before.channel.id
if not before.author.bot:
if before.content and after.content:
if ch_id not in self.edited_msgs:
self.edited_msgs[ch_id] = []
self.edited_msgs[ch_id].append((before, after))
if len(self.edited_msgs[ch_id]) > self.snipe_limit:
self.edited_msgs[ch_id].pop(0)
@commands.command(
name="snipe",
aliases=["sn"],
help="See recently deleted messages in the current channel",
)
@has_permissions(manage_messages=True)
async def snipe(self, ctx: commands.Context):
limit = self.snipe_limit
try:
msgs: list[discord.Message] = self.deleted_msgs[ctx.channel.id][
::-1
][:limit]
print(msgs)
embeds=[]
for msg in msgs:
snipe_embed = discord.Embed(
title="Snipe",description=f"Most recent deleted messages\n Channel {ctx.channel.mention}", color=self.theme_color
)
a=str(msg.created_at)
b = datetime.datetime.strptime(a, '%Y-%m-%d %H:%M:%S.%f')
c = b.timestamp()
snipe_embed.add_field(
name=f"{msg.author} @<t:{round(c)}>", value=f"{msg.content}", inline=False
)
embeds.append(snipe_embed)
paginator = DiscordUtils.Pagination.CustomEmbedPaginator(ctx, remove_reactions=True)
paginator.add_reaction('<:arrow_left:940845517703889016>', "first")
paginator.add_reaction('<:leftarrow:941994549935472670>', "back")
paginator.add_reaction('<:rightarrow:941994550124245013>', "next")
paginator.add_reaction('<:arrow_right:940608259075764265>', "last")
paginator.add_reaction('<:DiscordCross:940914829781270568>', "lock")
await paginator.run(embeds)
except KeyError:
await ctx.send(embed=discord.Embed(description="**There's nothing to snipe here...**\n Wait for a deleted message",color=discord.Color.dark_grey()))
@commands.command(
name="editsnipe",
aliases=["esn"],
help="See recently edited messages in the current channel",
)
@has_permissions(manage_messages=True)
async def editsnipe(self, ctx: commands.Context):
limit = self.snipe_limit
try:
msgs = self.edited_msgs[ctx.channel.id][::-1][:limit]
embeds=[]
for msg in msgs:
editsnipe_embed = discord.Embed(title=f"Edit Snipe ({len(self.edited_msgs[ctx.channel.id][::-1][:limit])} Entries)",
description=f"Author • {msg[1].author} | Edited", color=self.theme_color
)
editsnipe_embed.add_field(
name='Before',
value=f"{msg[0].content}",
inline=True,
)
editsnipe_embed.add_field(
name='After',
value=f" {msg[1].content}",
inline=True,
)
editsnipe_embed.set_footer(text=f"Edited at {msg[1].created_at}")
embeds.append(editsnipe_embed)
paginator = DiscordUtils.Pagination.CustomEmbedPaginator(ctx, remove_reactions=True)
paginator.add_reaction('<:arrow_left:940845517703889016>', "first")
paginator.add_reaction('<:leftarrow:941994549935472670>', "back")
paginator.add_reaction('<:rightarrow:941994550124245013>', "next")
paginator.add_reaction('<:arrow_right:940608259075764265>', "last")
paginator.add_reaction('<:DiscordCross:940914829781270568>', "lock")
await paginator.run(embeds)
except KeyError:
await ctx.send(embed=discord.Embed(description="**There's nothing to snipe here...**\n Wait for a edited message",color=discord.Color.dark_grey()))
def setup(bot):
bot.add_cog(Snipe(bot))