-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
393 lines (351 loc) · 14 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
383
384
385
386
387
388
389
390
391
392
393
# don't skid // yux#3039
import shutil
import discord
from discord.ext import commands
from dislash import *
import json
import os
import time
bot = commands.Bot(command_prefix="!")
inter_client = InteractionClient(bot)
bottoken = ""
botname = ""
botprefix = ""
botbase = """import discord
from discord.ext import commands
from dislash import *
import json
config = json.load(open('./config.json'))
bot = commands.Bot(command_prefix=config['prefix'])
inter_client = InteractionClient(bot)
## BOT CODE / START
## BOT CODE / END
bot.run(config['token'])
"""
async def managebotui(ctx, msg):
global bottoken, botname, botprefix
def check(inter):
return inter.message.id == msg.id
rib = ActionRow(
Button(
style=ButtonStyle.blurple,
label="Bot Informations",
custom_id="botinfo"
),
Button(
style=ButtonStyle.blurple,
label="Token",
custom_id="token"
),
Button(
style=ButtonStyle.blurple,
label="New Command",
custom_id="addcommand"
),
Button(
style=ButtonStyle.blurple,
label="New Event",
custom_id="addevent"
)
)
await msg.edit(embed=discord.Embed(title=f"MANAGER", description=f"`You can now manage your bot !`"), components=[rib])
inter = await ctx.wait_for_button_click(check)
button_text = inter.clicked_button.custom_id
if button_text == "token":
embed=discord.Embed(title="Your BOT Token:", description=f"`{bottoken}`")
await msg.edit(embed=embed, components=[Button(style=ButtonStyle.blurple,label="Change",custom_id="changetkn")])
inter = await ctx.wait_for_button_click(check)
button_text = inter.clicked_button.custom_id
if button_text == 'changetkn':
await msg.edit(embed=discord.Embed(title="Your BOT Token:", description="`please send the new token in the chat`"), components=[])
bottoken = await bot.wait_for("message")
await bottoken.delete()
bottoken = bottoken.content
embed=discord.Embed(title="Your BOT Token Is Now:", description=f"`{bottoken}`")
await msg.edit(embed=embed, components=[Button(style=ButtonStyle.blurple,label="Change",custom_id="changetkn")])
await managebotui(ctx, msg)
if button_text == "addcommand":
await msg.edit(embed=discord.Embed(title="MYB | New Command", description=f"`Please send the command without prefix in the chat:`"), components=[])
command = await bot.wait_for("message")
await command.delete()
await msg.edit(
embed=None,
components=[
SelectMenu(
custom_id="selected",
placeholder="Action",
max_values=1,
options=[
SelectOption("Send A Message", "send_msg"),
SelectOption("Send A Private Message", "send_pmsg")
]
)
]
)
def check(inter):
return inter.author == ctx.author
inter = await msg.wait_for_dropdown(check)
customid = [option.value for option in inter.select_menu.selected_options]
print(customid)
if customid[0] == "send_msg":
await msg.edit(embed=discord.Embed(title="MYB | New Command", description=f"`Please send the message you want to send in the chat:`"), components=[])
msg1 = await bot.wait_for("message")
addbotcode(f'''
@bot.command()
async def {command.content}(ctx):
await ctx.send("""{msg1.content}""")
''')
await managebotui(ctx, msg)
elif customid[0] == "send_pmsg":
await msg.edit(embed=discord.Embed(title="MYB | New Command", description=f"`Please send the message you want to send in the chat:`"), components=[])
msg1 = await bot.wait_for("message")
addbotcode(f'''
@bot.command()
async def {command.content}(ctx):
await ctx.author.send("""{msg1.content}""")
''')
await managebotui(ctx, msg)
await msg.edit(embed=discord.Embed(title="MYB | Command Succesfully Created", description=f"`{botprefix.content}{command.content} >> Has been created !`"), components=[])
if button_text == "addevent":
await msg.edit(
embed=None,
components=[
SelectMenu(
custom_id="selected",
placeholder="Action",
max_values=1,
options=[
SelectOption("On Message", "on_message"),
SelectOption("On Ready", "on_ready")
]
)
]
)
def check(inter):
return inter.author == ctx.author
inter = await msg.wait_for_dropdown(check)
customid = [option.value for option in inter.select_menu.selected_options]
if customid[0] == 'on_message':
await msg.edit(
embed=None,
components=[
SelectMenu(
custom_id="selected",
placeholder="Action",
max_values=1,
options=[
SelectOption("Send A Message", "send_msg"),
SelectOption("Send A Private Message", "send_pmsg")
]
)
]
)
def check(inter):
return inter.author == ctx.author
inter = await msg.wait_for_dropdown(check)
customid = [option.value for option in inter.select_menu.selected_options]
if customid[0] == "send_msg":
await msg.edit(embed=discord.Embed(title="MYB | New Command", description=f"`Please send the message you want to send in the chat:`"), components=[])
msg1 = await bot.wait_for("message")
addbotcode(f'''
@bot.event
async def on_message(message):
await message.channel.send("""{msg1.content}""")
''')
await managebotui(ctx, msg)
elif customid[0] == "send_pmsg":
await msg.edit(embed=discord.Embed(title="MYB | New Command", description=f"`Please send the message you want to send in the chat:`"), components=[])
msg1 = await bot.wait_for("message")
addbotcode(f'''
@bot.event
async def on_message(message):
await message.author.send("""{msg1.content}""")
''')
await managebotui(ctx, msg)
if customid[0] == 'on_ready':
await managebotui(ctx, msg)
def loadbot(botname):
global bottoken
foldername = str(botname).replace(' ', '')
configdata = json.load(open(f'./Bots/{foldername}/config.json'))
bottoken = configdata['token']
botname = configdata['name']
def addbotcode(code):
foldername = str(botname.content).replace(' ', '')
with open(f'./Bots/{foldername}/main.py', 'r') as f:
data = f.readlines()
data[12] = f'\n\n\n{code}\n\n\n'
with open(f'./Bots/{foldername}/main.py', 'w') as f:
f.writelines(data)
def getbotscount():
list = os.listdir('./Bots/')
number_files = len(list)
return number_files
def getbots():
list = os.listdir('./Bots/')
return list
def setupbotmainfile(token, name, prefix):
try:
foldername = name.replace(' ', '')
os.mkdir(os.path.join("./Bots/", foldername))
with open(f'./Bots/{foldername}/config.json', 'w') as f:
f.write('''
{
"token": "'''+token+'''",
"name": "'''+name+'''",
"prefix": "'''+prefix+'''"
}
''')
with open(f'./Bots/{foldername}/main.py', 'w') as f:
f.write(botbase)
except Exception as e:
print(e)
async def mainmenu(ctx, msg):
global bottoken, botname, bot
# Make a row of buttons
basebuttons = ActionRow(
Button(
style=ButtonStyle.green,
label="New Bot",
custom_id="create"
),
Button(
style=ButtonStyle.blurple,
label="My Bots",
custom_id="bots"
),
Button(
style=ButtonStyle.green,
label="Load A Bot",
custom_id="load"
),
Button(
style=ButtonStyle.red,
label="Delete A Bot",
custom_id="delete"
)
)
okbtn = ActionRow(
Button(
style=ButtonStyle.green,
label="Ok",
custom_id="ok"
)
)
await msg.edit(
embed=discord.Embed(title=f"MYB | {getbotscount()} Bots Loaded", description="`Please select a choice:`", ),
components=[basebuttons]
)
# Wait for someone to click on them
def check(inter):
return inter.message.id == msg.id
inter = await ctx.wait_for_button_click(check)
button_text = inter.clicked_button.custom_id
if button_text == "delete":
await msg.edit(embed=discord.Embed(title="MYB | Delete A Bot", description="`please send the name of your bot you want to delete!`"), components=[])
db = await bot.wait_for("message")
await db.delete()
try:
shutil.rmtree(f'./Bots/{db.content}/')
await msg.edit(embed=discord.Embed(title="MYB | Delete A Bot", description="`The bot has been deleted !`"), components=[])
time.sleep(2)
await mainmenu(ctx, msg)
except Exception as e:
await msg.edit(embed=discord.Embed(title="MYB | Delete A Bot", description="`Failed to delete the bot !`"), components=[])
print(e)
time.sleep(2)
await mainmenu(ctx, msg)
if button_text == "load":
await msg.edit(embed=discord.Embed(title="MYB | Load A Bot", description="`please send the name of your bot you want to load!`"), components=[])
bottoload = await bot.wait_for("message")
await bottoload.delete()
try:
loadbot(bottoload.content)
await msg.edit(embed=discord.Embed(title="MYB | Load A Bot", description=f"`{bottoload.content} Has been loaded !`"), components=[])
except Exception as e:
await msg.edit(embed=discord.Embed(title="MYB | Load A Bot", description=f"`Failed to load bot : {bottoload.content}`"), components=[okbtn])
print(e)
def check(inter):
return inter.message.id == msg.id
inter = await ctx.wait_for_button_click(check)
button_text = inter.clicked_button.custom_id
await mainmenu(ctx, msg)
time.sleep(1)
await managebotui(ctx, msg)
if button_text == "create":
await msg.edit(embed=discord.Embed(title="MYB | Bot Setup (1/4)", description="`please send the BOT TOKEN in the chat`"), components=[])
bottoken1 = await bot.wait_for("message")
await bottoken1.delete()
await msg.edit(embed=discord.Embed(title="MYB | Bot Setup (2/4)", description="`please send the BOT NAME in the chat`"), components=[])
botname1 = await bot.wait_for("message")
await botname1.delete()
await msg.edit(embed=discord.Embed(title="MYB | Bot Setup (3/4)", description="`please send the BOT PREFIX in the chat`"), components=[])
botprefix1 = await bot.wait_for("message")
await botprefix1.delete()
await msg.edit(embed=discord.Embed(title="MYB | Setting Up Your Bot... (4/4)", description="`please wait ...`"), components=[])
setupbotmainfile(bottoken1.content, botname1.content, botprefix1.content)
loadbot(botname1.content)
time.sleep(2)
await managebotui(ctx, msg)
elif button_text == "bots":
embed=discord.Embed(title="MYB | Your Bots", description="There is your bots loaded:")
okbtn = ActionRow(
Button(
style=ButtonStyle.green,
label="Ok",
custom_id="ok"
)
)
for bot in getbots():
embed.add_field(name=f"```{bot}```", value=f"` `", inline=True)
await msg.edit(embed=embed, components=[okbtn])
def check(inter):
return inter.message.id == msg.id
inter = await ctx.wait_for_button_click(check)
button_text = inter.clicked_button.custom_id
await mainmenu(ctx, msg)
@bot.command()
async def start(ctx):
basebuttons = ActionRow(
Button(
style=ButtonStyle.green,
label="New Bot",
custom_id="create"
),
Button(
style=ButtonStyle.blurple,
label="My Bots",
custom_id="bots"
),
Button(
style=ButtonStyle.green,
label="Load A Bot",
custom_id="load"
),
Button(
style=ButtonStyle.red,
label="Delete A Bot",
custom_id="delete"
)
)
msg = await ctx.send(
embed=discord.Embed(title=f"MYB | {getbotscount()} Bots Loaded", description="`Please select a choice:`", ),
components=[basebuttons]
)
while True:
try:
await mainmenu(ctx, msg)
except:
global bottoken, botname, botprefix
bottoken = ""
botname = ""
botprefix = ""
time.sleep(5)
await msg.edit(
embed=discord.Embed(title=f"MYB | Bot Crashed", description="`this is a beta made by yux then sorry for crashs, enjoy`", ),
components=[]
)
bot.logout()
exit('bot crashed')
return
bot.run("YOUR_BOT_TOKEN")