-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
382 lines (305 loc) Β· 11.3 KB
/
main.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
import datetime
import os
import random
import statistics
import sys
import time
from constants import TOKEN
from discord.ext import commands
from discord import app_commands, ui
import discord
from utils import *
from api import *
start_time = None
latencies = []
# command to show the code to use the api based on the user selected language
class spooBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix="$", intents=discord.Intents.all(), help_command=None
)
self.synced = False
async def on_ready(self):
await load()
global start_time
start_time = datetime.datetime.now(datetime.UTC)
await self.wait_until_ready()
if not self.synced:
await self.tree.sync()
await bot.change_presence(
activity=discord.CustomActivity(
name="Custom Status",
state=f"Shorten your URLs, not your possibilities.",
)
)
self.synced = True
try:
file = r"assets\\s.gif"
with open(file, "rb") as avatar:
await self.user.edit(avatar=avatar.read())
print("Applied Animated Avatar")
except Exception as e:
print(e, file=sys.stdout)
pass
print(f"Logged in as {self.user.name} (ID: {self.user.id})")
print(f"Connected to {len(self.guilds)} guilds")
bot = spooBot()
async def load():
for f in os.listdir("cogs"):
if f.endswith(".py"):
await bot.load_extension(f"cogs.{f[:-3]}")
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if bot.user in message.mentions:
if message.type is not discord.MessageType.reply:
embed = discord.Embed(
description="Hello, I am the SpooBot. I am a URL shortener bot that makes your URLs spoo-tacular! π\nType </help:1202746904203759646> to see the list of commands I can do for you!",
color=discord.Color.og_blurple(),
)
await message.reply(embed=embed)
await bot.process_commands(message)
@bot.event
async def on_member_join(member):
channel = bot.get_channel(1192388005206433894)
embed = discord.Embed(
title="Welcome to the spoo.me Support Server!",
description=f"Hey {member.mention}! Welcome to the support server for spoo.me, the best URL shortener out there! We hope you enjoy your stay here!",
color=discord.Color.blurple(),
url="https://spoo.me",
)
embed.set_image(url=random.choice(welcome_gifs))
try:
embed.set_thumbnail(url=member.avatar.url)
except:
embed.set_thumbnail(url=member.default_avatar.url)
await channel.send(embed=embed)
@bot.command()
@commands.is_owner()
async def sync(ctx):
await bot.tree.sync()
synced = await bot.tree.sync()
if len(synced) > 0:
await ctx.send(f"Successfully Synced {len(synced)} Commands βοΈ")
else:
await ctx.send("No Slash Commands to Sync :/")
@bot.event
async def on_command_completion(ctx):
end = time.perf_counter()
start = ctx.start
latency = (end - start) * 1000
latencies.append(latency)
if len(latencies) > 10:
latencies.pop(0)
@bot.before_invoke
async def before_invoke(ctx):
start = time.perf_counter()
ctx.start = start
@bot.command()
async def ping(ctx):
try:
embed = discord.Embed(title="Pong!", color=discord.Color.green())
message = await ctx.send(embed=embed)
end = time.perf_counter()
latency = (end - ctx.start) * 1000
embed.add_field(
name="Latency", value=f"{bot.latency * 1000:.2f} ms", inline=False
)
embed.add_field(name="Message Latency", value=f"{latency:.2f} ms", inline=False)
# Calculate the average ping of the bot in the last 10 minutes
if latencies:
average_ping = statistics.mean(latencies)
embed.add_field(
name="Average Ping", value=f"{average_ping:.2f} ms", inline=False
)
global start_time
current_time = datetime.datetime.now(datetime.UTC)
delta = current_time - start_time
hours, remainder = divmod(int(delta.total_seconds()), 3600)
minutes, seconds = divmod(remainder, 60)
embed.add_field(
name="Uptime",
value=f"{hours} hours {minutes} minutes {seconds} seconds",
inline=False,
)
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.avatar.url,
)
embed.set_thumbnail(
url="https://uploads.poxipage.com/7q5iw7dwl5jc3zdjaergjhpat27tws8bkr9fgy45_938843265627717703-webp"
)
await message.edit(embed=embed)
except Exception as e:
print(e, file=sys.stdout)
@bot.hybrid_command(
name="help",
description="View the various commands of this bot π"
)
async def help(ctx):
user = bot.get_user(1202738385194717205)
profilePicture = user.avatar.url
embed = discord.Embed(
title="SpooBot Commands",
description="Here is the list of the available commands:",
color=discord.Color.blurple(),
timestamp=ctx.message.created_at,
)
embed.set_thumbnail(url=profilePicture)
for i in commands_.keys():
embed.add_field(name=i, value=commands_[i], inline=False)
try:
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.avatar.url,
)
except:
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.default_avatar.url,
)
await ctx.send(embed=embed)
@bot.hybrid_command(
name="invite",
description="Get the invite link for the bot π",
)
async def invite(ctx):
embed = discord.Embed(
title="Invite SpooBot to your server!",
description="Click [here](https://discord.com/api/oauth2/authorize?client_id=1202738385194717205&permissions=9242837113920&scope=bot) to invite SpooBot to your server!",
color=discord.Color.orange(),
timestamp=ctx.message.created_at,
)
try:
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.avatar.url,
)
except:
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.default_avatar.url,
)
await ctx.send(embed=embed)
@bot.hybrid_command(
name="bot-stats",
description="View the stats of the bot π",
)
async def stats(ctx):
global start_time
current_time = datetime.datetime.now(datetime.UTC)
delta = current_time - start_time
hours, remainder = divmod(int(delta.total_seconds()), 3600)
minutes, seconds = divmod(remainder, 60)
embed = discord.Embed(
title="SpooBot Stats",
description="Here are the stats of the bot:",
color=discord.Color.og_blurple(),
timestamp=ctx.message.created_at,
)
embed.add_field(name="Servers", value=f"```{len(bot.guilds)}```", inline=True)
embed.add_field(name="Users", value=f"```{len(bot.users)}```", inline=True)
embed.add_field(
name="Uptime",
value=f"```{hours} hours {minutes} minutes {seconds} seconds```",
inline=False,
)
embed.add_field(name="Command Prefix", value=f"``` $ ```", inline=True)
embed.add_field(name="Total Commands", value=f"```{len(commands_)}```", inline=True)
try:
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.avatar.url,
)
except:
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.default_avatar.url,
)
await ctx.send(embed=embed)
@bot.hybrid_command(
name="support",
description="Join the Support Server of the bot π οΈ",
)
async def support(ctx):
embed = discord.Embed(
title="Join the SpooBot Support Server!",
description="Click https://spoo.me/discord to join the support server for SpooBot!",
color=discord.Color.gold(),
timestamp=ctx.message.created_at,
)
embed.set_thumbnail(
url="https://cdn.discordapp.com/icons/1192388005206433892/461edd6dd7b92f24a94505fe3a660f91.webp?size=1024&format=webp&width=0&height=320"
)
try:
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.avatar.url,
)
except:
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.default_avatar.url,
)
await ctx.send(embed=embed)
@bot.hybrid_command(
name="about",
description="View information about the bot π€",
)
async def about(ctx):
embed = discord.Embed(
title="About SpooBot π",
description="```SpooBot is a URL shortener bot that makes your URLs spoo-tacular! π It is a bot that saves you time and hassle by shortening URLs for you, so you can focus on more important things! π\nBut wait, there's more! SpooBot also lets you view all your URL statistics from this bot, so you can track how many clicks, views, and visits your URLs get! π\nSpooBot is the ultimate URL shortener bot that you need in your life! π```",
color=discord.Color.greyple(),
url="https://spoo.me",
timestamp=ctx.message.created_at,
)
embed.add_field(
name="What service does SpooBot use? π",
value="```SpooBot uses the spoo.me URL shortening service to shorten URLs. spoo.me is a fast, reliable, and secure URL shortening service that allows you to shorten URLs with ease. π```",
inline=False,
)
embed.add_field(
name="Where can I find the source code? π»",
value="```You can find the source code for SpooBot on GitHub. π```",
inline=False,
)
embed.add_field(
name="Who made SpooBot? π₯",
value="```SpooBot was made by the devs of spoo.me. π```",
inline=False,
)
user = bot.get_user(1202738385194717205)
embed.set_thumbnail(url=user.avatar.url)
try:
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.avatar.url,
)
except:
embed.set_footer(
text="Information requested by: {}".format(ctx.author.name),
icon_url=ctx.author.default_avatar.url,
)
view = discord.ui.View()
view.add_item(
discord.ui.Button(
label="View Source Code",
url="https://github.com/spoo-me/spoo-bot",
style=discord.ButtonStyle.link,
emoji="<:git:1203429172903542835>",
)
)
view.add_item(
discord.ui.Button(
label="View Website",
url="https://spoo.me",
style=discord.ButtonStyle.link,
emoji="<:spoo:1203429402071797760>",
)
)
await ctx.send(embed=embed, view=view)
if __name__ == "__main__":
keep_alive()
bot.run(token=TOKEN)