-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
78 lines (64 loc) · 2.45 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
from utils.message import error_embed, success_embed, cooldown_embed, info_embed
from utils.update import update_repo
from utils.secrets import CLIENT_TOKEN, ADMINS
from utils.config import INTENTS
from discord.ext import commands
import discord
import traceback
import asyncio
bot = commands.Bot(command_prefix="!", intents=INTENTS)
cogs = [
"ping",
"version",
"stats",
"translation",
"xdd",
"update_watcher"
]
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")
for cog in cogs:
await bot.load_extension(f"cogs.{cog}")
print(f"- Loaded {cog}")
@bot.event
async def on_command_error(ctx, error: commands.CommandError):
if isinstance(error, commands.CommandNotFound):
await ctx.send(embed=error_embed("The specified command was not found."))
elif isinstance(error, commands.CommandOnCooldown):
await cooldown_embed(ctx, error)
else:
await ctx.send(embed=error_embed(f"The command ran into an error.\n```{error}```"))
@bot.command("update")
async def update_repo_command(ctx: commands.Context, repo: str):
author = ctx.author
if author.id not in ADMINS:
await ctx.send(embed=error_embed("You do not have permission to run this command."))
return
message = await ctx.send(embed=info_embed(f"Updating {repo}", "This may take a while."))
await update_repo(repo)
await message.edit(embed=success_embed(f"{repo} has been updated to the newest version on github."))
@bot.command("reload")
async def reload(ctx: commands.Context, *target_cogs):
author = ctx.author
if author.id not in ADMINS:
await ctx.send(embed=error_embed("You do not have permission to run this command."))
return
i = 0
embeds = []
message = None
for cog in cogs if not target_cogs else target_cogs:
embeds.append(info_embed("Reloading", f"Reloading `{cog}` ({i + 1}/{len(cogs)})"))
i += 1
message = await ctx.send(embeds=embeds)
i = 0
for cog in cogs if not target_cogs else target_cogs:
try:
await bot.reload_extension(f"cogs.{cog}")
embeds[i] = success_embed(f"Reloaded `{cog}` ({i + 1}/{len(cogs)})")
await message.edit(embeds=embeds)
except Exception as e:
embeds[i] = error_embed(f"Failed to reload `{cog}` ({i + 1}/{len(cogs)})\n```{e}```")
await message.edit(embeds=embeds)
i += 1
bot.run(CLIENT_TOKEN)