This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
120 lines (97 loc) · 3.47 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
import discord, os, textwrap, io, traceback
from contextlib import redirect_stdout
from core.files import Data
from core import checks
from discord.ext import commands
config = Data("config").yaml_read()
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=config["prefix"], case_insensitive=True, help_command=None, intents=intents)
@bot.event
async def on_ready():
print("Bot is ready!")
@checks.manager()
@bot.command(aliases=["e"])
async def eval(ctx, *, body: str):
raw = False
"""Evaluates a code"""
env = {
'bot': bot,
'ctx': ctx,
'channel': ctx.message.channel,
'author': ctx.message.author,
'guild': ctx.message.guild,
'message': ctx.message,
}
env.update(globals())
stdout = io.StringIO()
to_compile = f'async def func():\n{textwrap.indent(body, " ")}'
try:
exec(to_compile, env)
except Exception as e:
return await ctx.send(f'```py\n{e.__class__.__name__}: {e}\n```')
func = env['func']
try:
with redirect_stdout(stdout):
ret = await func()
except Exception:
value = stdout.getvalue()
await ctx.send(f'```py\n{value}{traceback.format_exc()}\n```')
else:
value = stdout.getvalue()
try:
await ctx.message.add_reaction('\u2705')
except:
pass
if ret is None:
if value:
if raw:
await ctx.send(f"{value}")
else:
await ctx.send(f'```py\n{value}\n```')
else:
pass
@checks.manager()
@bot.command(hidden=True)
async def load(ctx, *, module):
try:
bot.load_extension(f"cogs.{module}")
except commands.ExtensionError as e:
await ctx.send(f'{e.__class__.__name__}: {e}')
else:
embed=discord.Embed(title=f"Loaded {str(module).capitalize()}", description=f"Successfully loaded cogs.{str(module).lower()}!", color=0x2cf818)
await ctx.send(embed=embed)
@checks.manager()
@bot.command(hidden=True)
async def unload(ctx, *, module):
try:
bot.unload_extension(f"cogs.{module}")
except commands.ExtensionError as e:
await ctx.send(f'{e.__class__.__name__}: {e}')
else:
embed=discord.Embed(title=f"Unloaded {str(module).capitalize()}", description=f"Successfully unloaded cogs.{str(module).lower()}!", color=0xeb1b2c)
await ctx.send(embed=embed)
@checks.manager()
@bot.command(name="reload", hidden=True)
async def _reload(ctx, *, module):
try:
bot.reload_extension(f"cogs.{module}")
except commands.ExtensionError as e:
await ctx.send(f'{e.__class__.__name__}: {e}')
else:
embed=discord.Embed(title=f"Reloaded {str(module).capitalize()}", description=f"Successfully reloaded cogs.{str(module).lower()}!", color=0x00d4ff)
await ctx.send(embed=embed)
for file in [i for i in os.listdir("cogs") if i.endswith(".py")]:
try:
bot.load_extension(f"cogs.{file[:-3]}")
print(f"Loaded {file}")
except Exception as e:
print(f"######\nFailed to load {file}: {e}\n######")
dirs = [i for i in [x for x in os.walk("cogs")][0][1] if i.find(".") == -1]
for folder in dirs:
for file in [i for i in os.listdir(f"cogs/{folder}") if i.endswith(".py")]:
try:
bot.load_extension(f"cogs.{folder}.{file[:-3]}")
print(f"Loaded {file}")
except Exception as e:
print(f"######\nFailed to load {folder}.{file}: {e}\n######")
bot.run(config["token"])