-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_emoji.py
291 lines (258 loc) Β· 10.2 KB
/
main_emoji.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import ezcord
import discord
import os
from datetime import datetime as dt
from dotenv import load_dotenv
load_dotenv()
website = (
"https://caltrop.asterisk.lol" # Will save a lot of time if the domain changes
)
numembeds = 0
numfiles = 0
oneimage = 0
embed = None
webhookurl = str(os.getenv("WEBHOOK_URL"))
intents = discord.Intents.default()
bot = ezcord.Bot(
language="en", error_webhook_url=webhookurl, intents=intents, ready_event=None
)
@bot.event
async def on_ready():
activity = discord.CustomActivity(name="ποΈ Archiving your messages")
await bot.change_presence(status=discord.Status.online, activity=activity)
bot.add_view(DeleteBookmark())
bot.ready(
style=ezcord.ReadyEvent.default,
)
class TagSet(discord.ui.Modal):
def __init__(self, *args, **kwargs) -> None:
super().__init__(timeout=None, *args, **kwargs)
# Modal for tag input
self.add_item(discord.ui.InputText(label="", required=False))
async def callback(self, interaction: discord.Interaction):
await interaction.response.defer()
class ColourModal(discord.ui.Modal):
def __init__(self):
super().__init__(title="Customizer")
self.add_item(
discord.ui.InputText(
label="Colour (hex code)", placeholder="#FF5733", required=True
)
)
async def callback(self, interaction: discord.Interaction):
color_input = self.children[0].value
# Validate the color input
if not color_input.startswith("#") or len(color_input) != 7:
await interaction.response.send_message(
"Please enter a valid hex code (e.g., `#FF5733`).", ephemeral=True
)
# Update the global embed color
global embed
embed.color = int(color_input[1:], 16)
# Edit the original message with the updated embed
await interaction.response.edit_message(embed=embed)
class DeleteBookmark(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
@discord.ui.button(
label="", custom_id="delete", style=discord.ButtonStyle.secondary, emoji="ποΈ"
)
async def button_callback(self, button, interaction):
await interaction.response.defer()
self.disable_all_items()
await interaction.message.delete()
global numembeds
global numfiles
global oneimage
if numembeds or numfiles != 0 and oneimage != 1:
channel = interaction.channel
to_delete = int(numembeds + numfiles)
messages = await channel.history(
limit=to_delete, after=interaction.message.created_at
).flatten()
for i in messages:
await i.delete()
@discord.ui.button(
label="", custom_id="pin", style=discord.ButtonStyle.secondary, emoji="π"
)
async def pin_callback(self, button, interaction):
await interaction.message.pin()
await interaction.response.defer()
@discord.ui.button(
label="",
custom_id="move_to_bottom",
style=discord.ButtonStyle.secondary,
emoji="π½",
)
async def button2_callback(self, button, interaction):
for i in interaction.message.embeds:
i.set_footer(
text="πΌ Go back to the original message to view attachments and embeds."
)
await interaction.response.send_message(embed=i, view=DeleteBookmark())
@discord.ui.button(
label="", custom_id="customize", style=discord.ButtonStyle.secondary, emoji="π¨"
)
async def customizer(self, button, interaction):
await interaction.response.send_modal(ColourModal())
class About(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
SiteButton = discord.ui.Button(
label="Website",
style=discord.ButtonStyle.url,
url="https://archiver.asterisk.lol",
)
self.add_item(SiteButton)
CodeButton = discord.ui.Button(
label="Source Code",
style=discord.ButtonStyle.url,
url="https://github.com/Ast3risk-ops/archiver",
)
self.add_item(CodeButton)
@bot.slash_command(
# This command can be used by guild members, but also by users anywhere if they install it
integration_types={
discord.IntegrationType.guild_install,
discord.IntegrationType.user_install,
},
name="help",
description="How to use the bot",
)
async def help(ctx):
context_img = discord.File("context.png", filename="context.png")
embed = discord.Embed(
title="Using Archiver",
description="To use Archiver, simply right click or hold down on a message and go to **Apps > Archive Message**.",
color=discord.Colour.from_rgb(255, 255, 255),
)
embed.set_image(url="attachment://context.png")
await ctx.respond(embed=embed, file=context_img, ephemeral=True)
@bot.slash_command(
# This command can be used by guild members, but also by users anywhere if they install it
integration_types={
discord.IntegrationType.guild_install,
discord.IntegrationType.user_install,
},
name="about",
description="Links and stuff",
)
async def about(ctx):
embed = discord.Embed(
title="About",
description=f"[**Archiver**]({website}) is a bot to archive Discord messages, developed by [**Asterisk**](https://asterisk.lol).",
color=discord.Colour.from_rgb(255, 255, 255),
)
await ctx.respond(embed=embed, view=About(), ephemeral=True)
@bot.message_command(
# This command can be used by guild members, but also by users anywhere if they install it
integration_types={
discord.IntegrationType.guild_install,
discord.IntegrationType.user_install,
},
name="Archive Message",
)
async def bookmark_tag(ctx, message: discord.Message):
modal = TagSet(title="Message Tag(s)")
await ctx.send_modal(modal)
await modal.wait() # Wait for the modal to be submitted before archiving
reactionlist = [] # Empty list of reactions to use later
for i in message.reactions:
count = i.count # Number of times reacted
formatted_emoji = str(i.emoji)
reactionlist.append(f"{count}x {formatted_emoji} ")
global embed
global oneimage
if message.content:
embed = discord.Embed(
title=f"ποΈ Archived Message On {discord.utils.format_dt(dt.now(), 'f')} ({discord.utils.format_dt(dt.now(), 'R')})",
description=f"-------\n\n{message.content}\n\n--------",
color=discord.Colour.random(),
)
else:
embed = discord.Embed(
title=f"ποΈ Archived Message On {discord.utils.format_dt(dt.now(), 'f')} ({discord.utils.format_dt(dt.now(), 'R')})",
color=discord.Colour.random(),
)
if message.poll:
embed.description = (
f"\n**π Poll**\n-------\nβ {message.poll.question.text}\n\n"
)
answertext = []
for i in message.poll.answers:
answerf = f"{i.id}. [{i.emoji}] {i.text} \n"
answertext.append(answerf)
embed.add_field(name="", value="".join(answertext), inline=False)
embed.add_field(name="\n\n", value=", ".join(reactionlist), inline=False)
embed.add_field(
name="π€ Author",
value=f"`{message.author.name}` (<@{message.author.id}>)",
inline=True,
)
embed.add_field(name="π Link", value=f"{message.jump_url}", inline=True)
embed.add_field(name="πͺͺ ID", value=f"{message.id}", inline=True)
if message.guild:
embed.add_field(name="π° Guild", value=f"{message.guild.id}", inline=True)
else:
embed.add_field(name="π° Guild", value=f"DM", inline=True)
if message.embeds:
global numembeds
numembeds = len(message.embeds) # Number of embeds
embed.add_field(name="π² Embeds", value=f"{numembeds}", inline=True)
if message.attachments:
global numfiles
numfiles = len(message.attachments)
if numfiles == 1:
for i in message.attachments:
if i.content_type and i.content_type.startswith("image/"):
global oneimage
oneimage = 1
path = f"./{i.filename}"
await i.save(path)
img = discord.File(i.filename, filename=i.filename)
embed.set_image(url=f"attachment://{i.filename}")
os.remove(path)
embed.add_field(name="πΈ Attachments", value=f"{numfiles}", inline=True)
embed.add_field(
name="π
Send Date",
value=f"{discord.utils.format_dt(message.created_at, 'F')}",
inline=True,
)
if modal.children[0].value:
embed.add_field(name="π Tags", value=f"{modal.children[0].value}", inline=True)
embed.set_thumbnail(url=ezcord.utils.avatar(f"{message.author.id}"))
if oneimage == 1:
embed.add_field(name=f"\n\n", value="", inline=True)
try:
if oneimage != 1:
await ctx.user.send(embed=embed, view=DeleteBookmark())
else:
await ctx.user.send(embed=embed, file=img, view=DeleteBookmark())
except discord.Forbidden:
await ctx.respond(
"βΉοΈ I can't DM you! Please enable DMs for this server and try again.",
ephemeral=True,
)
except discord.HTTPException:
await ctx.respond(
"βΉοΈ I can't DM you! (Unknown HTTP exception, please contact my developer if the issue persists)",
ephemeral=True,
)
else:
if oneimage != 1:
for i in message.attachments:
path = f"./{i.filename}"
await i.save(path)
await ctx.user.send(file=discord.File(path))
os.remove(path)
if message.stickers:
stickers = []
for i in message.stickers:
format = f"[{i.name}]({i.url})"
stickers.append(format)
await ctx.user.send(" ".join(stickers))
if message.embeds:
for i in message.embeds:
await ctx.user.send(embed=i)
if __name__ == "__main__":
bot.run(str(os.getenv("TOKEN"))) # run the bot with the token