This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
229 lines (196 loc) · 6.94 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
import asyncio
from contextlib import contextmanager
import logging
import aeval
import nextcord
from nextcord.ext import commands
import configuration
from src.extensions.EXFormatExtension import format_exception
from src.extensions.DBWorkerExtension import DataBase
class DeleteMessage(nextcord.ui.View):
def __init__(self, *, message, ctx):
"""_summary_
Args:
message (_type_): _description_
ctx (_type_): _description_
"""
super().__init__(timeout=60 * 5)
self.message = message
self.ctx = ctx
@nextcord.ui.button(label="delete this message", style=nextcord.ButtonStyle.grey)
async def delete_this(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
):
"""_summary_
Args:
button (nextcord.ui.Button): _description_
interaction (nextcord.Interaction): _description_
"""
if self.ctx.author.id == interaction.user.id:
await interaction.message.delete()
@nextcord.ui.button(label="delete two messages", style=nextcord.ButtonStyle.grey)
async def delete_two(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
):
"""_summary_
Args:
button (nextcord.ui.Button): _description_
interaction (nextcord.Interaction): _description_
"""
if self.ctx.author.id == interaction.user.id:
await self.ctx.message.delete()
await interaction.message.delete()
async def on_timeout(self):
self.delete_this.disabled = True
self.delete_two.disabled = True
try:
await self.message.edit(view=self)
except BaseException:
pass
class Bot(commands.Bot):
def __init__(
self,
cogs_add_on_ready=None,
command_prefix=None,
help_command=None,
intents=None,
):
"""_summary_
Args:
cogs_add_on_ready (_type_, optional): _description_. Defaults to None.
command_prefix (_type_, optional): _description_. Defaults to None.
help_command (_type_, optional): _description_. Defaults to None.
intents (_type_, optional): _description_. Defaults to None.
"""
super().__init__(
command_prefix=command_prefix, help_command=help_command, intents=intents
)
self.DATA: dict = {"bot-started": False, "messages": {"pymsg": None}}
self.OWNERS: list[int] = [
286914074422280194,
1120793294931234958,
404512224837894155,
]
self.EVAL_OWNER: list[int] = [
286914074422280194,
1120793294931234958,
404512224837894155,
]
self.cogs_add_on_ready = cogs_add_on_ready
async def on_ready(self):
print(f"Logged in as {self.user} (ID: {self.user.id})\n------")
if not self.DATA["bot-started"]:
if self.cogs_add_on_ready:
[
self.load_extension(f"src.cogs.{cog}")
for cog in self.cogs_add_on_ready
]
application_info = await self.application_info()
self.OWNERS.append(application_info.owner.id)
self.EVAL_OWNER.append(application_info.owner.id)
self.DATA["bot-started"] = True
bot = Bot(
cogs_add_on_ready=configuration.cogs_add_on_ready,
intents=nextcord.Intents.all(),
command_prefix=">",
help_command=None,
)
@bot.command()
async def cog_load(ctx: commands.Context, cog: str):
"""_summary_
Args:
ctx (commands.Context): _description_
cog (str): _description_
"""
if ctx.author.id not in bot.OWNERS:
return
try:
bot.load_extension(f"src.cogs.{cog}")
except BaseException as ex:
message = await ctx.channel.send(f"Exception:\n```bash\n{ex}\n```")
await message.edit(view=DeleteMessage(ctx=ctx, message=message))
else:
message = await ctx.channel.send(f"```src.cogs.{cog} loaded!```")
await message.edit(view=DeleteMessage(ctx=ctx, message=message))
@bot.command()
async def cog_unload(ctx: commands.Context, cog: str):
"""_summary_
Args:
ctx (commands.Context): _description_
cog (str): _description_
"""
if ctx.author.id not in bot.OWNERS:
return
try:
bot.unload_extension(f"src.cogs.{cog}")
except BaseException as ex:
message = await ctx.channel.send(f"Exception:\n```bash\n{ex}\n```")
await message.edit(view=DeleteMessage(ctx=ctx, message=message))
else:
message = await ctx.channel.send(f"```src.cogs.{cog} unloaded!```")
await message.edit(view=DeleteMessage(ctx=ctx, message=message))
@bot.command()
async def cog_reload(ctx: commands.Context, cog: str):
"""_summary_
Args:
ctx (commands.Context): _description_
cog (str): _description_
"""
if ctx.author.id not in bot.OWNERS:
return
try:
bot.unload_extension(f"src.cogs.{cog}")
await asyncio.sleep(1)
bot.load_extension(f"src.cogs.{cog}")
except BaseException as ex:
message = await ctx.channel.send(f"Exception:\n```bash\n{ex}\n```")
await message.edit(view=DeleteMessage(ctx=ctx, message=message))
else:
message = await ctx.channel.send(f"```src.cogs.{cog} reloaded!```")
await message.edit(view=DeleteMessage(ctx=ctx, message=message))
@bot.command()
async def remove_cog(ctx: commands.Context, cog: str):
"""_summary_
Args:
ctx (commands.Context): _description_
cog (str): _description_
"""
if ctx.author.id not in bot.OWNERS:
return
try:
bot.remove_cog(name=f"{cog}")
except BaseException as ex:
message = await ctx.channel.send(f"Exception:\n```bash\n{ex}\n```")
await message.edit(view=DeleteMessage(ctx=ctx, message=message))
else:
message = await ctx.channel.send(f"```src.cogs.{cog} removed!```")
await message.edit(view=DeleteMessage(ctx=ctx, message=message))
@bot.command(name="eval")
async def eval_string(ctx, *, content):
"""_summary_
Args:
ctx (_type_): _description_
content (_type_): _description_
"""
if ctx.author.id not in bot.EVAL_OWNER:
return
standart_args = {
"nextcord": nextcord,
"commands": commands,
"bot": bot,
"ctx": ctx,
"asyncio": asyncio,
"DataBase": DataBase,
}
if "```" in content:
content = "\n".join(content.split("\n")[1:-1])
try:
await aeval.aeval(content, standart_args, {})
except Exception as ex:
result = "".join(format_exception(ex, ex, ex.__traceback__))
message = await ctx.channel.send(
f"Exception:\n```bash\n{result.replace('```', '`')}\n```"
)
await message.edit(view=DeleteMessage(ctx=ctx, message=message))
if __name__ == "__main__":
bot.run(configuration.discord_token)