-
Notifications
You must be signed in to change notification settings - Fork 0
/
slaveBot.py
572 lines (475 loc) · 22 KB
/
slaveBot.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
#imports
from typing import List
import discord
from discord.ext import commands
import random
import requests
import time
import asyncio
from waifuUtils import *
from anilistTest import *
from nhscript import *
from databaseUtils import *
description = "Bot written for gambling games, weebs and administration."
presence_name = "with [REDACTED]." #defines presence playing with X
token = API_KEY_HERE #enter your bot API key here.
intents = discord.Intents.default()
bot = commands.Bot(command_prefix='*', description=description, intents=intents)
#bot.remove_command('help')
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
await bot.change_presence(activity=discord.Game(name=presence_name))
"""
@bot.command(description="Returns help.")
async def help(ctx):
embedVar = discord.Embed(title="Command list.").set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
for command in bot.commands:
embedVar.add_field(name=command)
await ctx.send(embedVar)
#todo:improve the help command
"""
@bot.command(description="Returns latency.")
async def ping(ctx):
await ctx.send(f"🏓 Pong ~. Latency is {round(bot.latency*1000)}ms.")
@bot.command(description="Generates a random number between 0 and given number.")
async def rand(ctx, n: float):
r_n = random.randrange(0, round(abs(n)))
print(ctx.author.mention)
embedVar = discord.Embed(title="Random number!", description=f"{r_n}", color=0x00ff00).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
await ctx.send(embed=embedVar)
@bot.command(description="Generates random waifu image.")
async def waifu(ctx):
waifu_url = get_waifu()
print("Waifu Image URL:"+waifu_url)
embedVar = discord.Embed(
title="Waifu!", color=0x00ffcc).set_image(url=waifu_url).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
await ctx.send(embed=embedVar)
@bot.command(description="Generates random Nekomimi. *Nyaa ~*")
async def neko(ctx):
neko_url = get_neko()
print(neko_url)
embedVar = discord.Embed(
title="Nekos!", description="Nyaa ~", color=0xccff00).set_image(url=neko_url).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
await ctx.send(embed=embedVar)
@bot.command(description="Gets NSFW waifu image.")
async def xwaifu(ctx):
if not ctx.channel.is_nsfw():
await ctx.send("❌ This command can only be run in an NSFW channel.")
return
xwaifu_url = get_xwaifu()
print(xwaifu_url)
embedVar = discord.Embed(
title="NSFW Waifu!", color=0x00aacc).set_image(url=xwaifu_url).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
await ctx.send(embed=embedVar)
@bot.command(description="Generates waifu images!")
async def images(ctx):
waifus = get_waifus()["files"]
waifuList = []
n = 1
page_no = 1
embedVar = discord.Embed(
title="Waifus!", color=0xfac105).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
msgId = await ctx.send(embed=embedVar)
await msgId.add_reaction('⏮')
await msgId.add_reaction('🟥')
await msgId.add_reaction('⏭')
await msgId.add_reaction('💾')
for x in waifus:
print(x)
waifuList.append(x)
n += 1
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ['⏮', '⏭', '🟥', '💾']
while True:
try:
reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await msgId.delete()
break
else:
if (reaction.emoji == '⏭' and page_no <= n):
page_no += 1
embedVar.set_image(url=waifuList[page_no])
await msgId.edit(embed=embedVar)
elif(reaction.emoji == '⏮' and page_no >= 1):
page_no -= 1
embedVar.set_image(url=waifuList[page_no])
await msgId.edit(embed=embedVar)
elif(reaction.emoji == '💾'):
await ctx.send(embed=embedVar)
elif(reaction.emoji == '🟥'):
await msgId.delete()
return
await reaction.remove(ctx.author)
print(page_no)
@bot.command(description="Generate NSFW Waifu images.")
async def ximages(ctx):
if not ctx.channel.is_nsfw():
await ctx.send("❌ This command can only be run in an NSFW channel.")
return
waifus = get_xwaifus()["files"]
waifuList = []
n = 1
page_no = 1
embedVar = discord.Embed(
title="NSFW Waifus!", color=0xfac105).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
msgId = await ctx.send(embed=embedVar)
await msgId.add_reaction('⏮')
await msgId.add_reaction('🟥')
await msgId.add_reaction('⏭')
await msgId.add_reaction('💾')
for x in waifus:
waifuList.append(x)
print(x)
n += 1
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ['⏮', '⏭', '🟥', '💾']
while True:
try:
reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await msgId.delete()
break
else:
if (reaction.emoji == '⏭' and page_no <= n):
page_no += 1
embedVar.set_image(url=waifuList[page_no])
await msgId.edit(embed=embedVar)
elif(reaction.emoji == '⏮' and page_no >= 1):
page_no -= 1
embedVar.set_image(url=waifuList[page_no])
await msgId.edit(embed=embedVar)
elif(reaction.emoji == '💾'):
await ctx.send(embed=embedVar)
elif(reaction.emoji == '🟥'):
await msgId.delete()
return
await reaction.remove(ctx.author)
print(page_no)
@bot.command(description="Finds information about given waifu.")
async def find(ctx, waifu_name: str):
print(waifu_name)
waifu_info = searchWaifus(waifu_name)
waifu_names = []
waifu_image = []
waifu_url = []
waifu_anime = []
for waifu in waifu_info:
waifu_names.append(waifu["name"]["full"])
waifu_image.append(waifu["image"]["large"])
waifu_url.append(waifu["siteUrl"])
waifu_ani = waifu["media"]["nodes"]
for anime in waifu_ani:
waifu_anime.append(anime["title"]["userPreferred"])
break
page_no = 0
embedVar = discord.Embed(title="Waifu search!",
color=0xffabc7).set_image(url=waifu_image[page_no]).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
embedVar.add_field(
name="Name: ", value=waifu_names[page_no], inline=False)
embedVar.add_field(name="Anime name:", value=waifu_anime[page_no])
embedVar.add_field(name="AniList URL:",
value=waifu_url[page_no], inline=False)
msgId = await ctx.send(embed=embedVar)
await msgId.add_reaction('⏮')
await msgId.add_reaction('🟥')
await msgId.add_reaction('⏭')
await msgId.add_reaction('💾')
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ['⏮', '⏭', '🟥', '💾']
while True:
try:
reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await msgId.delete()
break
else:
if (reaction.emoji == '⏭' and page_no <= len(waifu_name)-1):
page_no += 1
elif(reaction.emoji == '⏮' and page_no >= 0):
page_no -= 1
elif(reaction.emoji == '💾'):
await ctx.send(embed=embedVar)
elif(reaction.emoji == '🟥'):
await msgId.delete()
return
try:
embedVar = discord.Embed(title="Waifu search!",
color=0xffabc7).set_image(url=waifu_image[page_no]).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
embedVar.add_field(
name="Name: ", value=waifu_names[page_no], inline=False)
embedVar.add_field(name="Anime name:",
value=waifu_anime[page_no])
embedVar.add_field(name="AniList URL:",
value=waifu_url[page_no], inline=False)
except:
await reaction.remove(ctx.author)
continue
await msgId.edit(embed=embedVar)
await reaction.remove(ctx.author)
print(page_no)
@bot.command(description="Gets image from Danbooru for given tag.")
async def danbooru(ctx, tag: str):
if not ctx.channel.is_nsfw():
await ctx.send("❌ This command can only be run in an NSFW channel.")
return
print(tag)
page_no = 0
# getting posts for given tag
posts = get_from_danbooru_by_tag(tag)
images = []
for x in posts:
try:
images.append(x["large_file_url"])
except:
continue
# got the images. Now what? Embeds!
try:
embedVar = discord.Embed(title="Danbooru results!", description="Page "+str(
page_no+1)+" of "+str(len(images)), color=0xffabc7).set_image(url=images[page_no]).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
except:
embedVar = discord.Embed(title="Danbooru results!", description="Page "+str(
page_no+1)+" of "+str(len(images)), color=0xffabc7).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
msgId = await ctx.send(embed=embedVar)
await msgId.add_reaction('⏮')
await msgId.add_reaction('🟥')
await msgId.add_reaction('⏭')
await msgId.add_reaction('💾')
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ['⏮', '⏭', '🟥', '💾']
while True:
try:
reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await msgId.delete()
break
else:
if (reaction.emoji == '⏭' and page_no <= len(images)-1):
page_no += 1
elif(reaction.emoji == '⏮' and page_no >= 0):
page_no -= 1
elif(reaction.emoji == '🟥'):
await msgId.delete()
return
elif(reaction.emoji == '💾'):
await ctx.send(embed=embedVar)
try:
try:
embedVar = discord.Embed(title="Danbooru results!", description="Page "+str(
page_no+1)+" of "+str(len(images)), color=0xffabc7).set_image(url=images[page_no]).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
except:
embedVar = discord.Embed(title="Danbooru results!", description="Page "+str(
page_no+1)+" of "+str(len(images)), color=0xffabc7).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
except:
await reaction.remove(ctx.author)
continue
await msgId.edit(embed=embedVar)
await reaction.remove(ctx.author)
print(page_no)
@bot.command(description="Gets Hentai tags for digits.")
async def digits(ctx, digit: str):
if not ctx.channel.is_nsfw():
await ctx.send("❌ This command can only be run in an NSFW channel.")
return
if digit.isnumeric():
try:
insert_hentai(str(digit))
except:
print("Insertion failed. ID was:"+digit)
for x in {'nhentai', '9hentai', 'nyahentai'}:
embedVar = discord.Embed(title=x, description=print_info(digit, x)).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
await ctx.send(embed=embedVar)
@bot.command(description="Gets sauce for image URL.")
async def sauce(ctx, url : str):
result = get_sauce(url)
try:
embedVar = discord.Embed(title="Sauce found!", description=f"Given image URL:[Link]({url})", color=0xAB53FF).set_author(name=ctx.author, icon_url=ctx.author.avatar_url).set_thumbnail(url=result.thumbnail)
embedVar.add_field(name="Title:", value=f"{result.title}", inline=True)
embedVar.add_field(name="Author:", value=f"{result.author}", inline=True)
embedVar.add_field(name="Similarity:", value=f"{result.similarity}%", inline=False)
embedVar.add_field(name="Results:", value=f"[Link]({result.urls[0]})", inline=False)
embedVar.set_footer(text="Image search provided by SauceNao.")
except:
await ctx.send("❌ Not found. Try on IQDB.")
return
await ctx.send(embed=embedVar)
@bot.group(description="Waifu Roulette Commands Group.")
async def w(ctx):
if ctx.invoked_subcommand is None:
await ctx.send("❌ That is not a valid waifu roulette command!")
@w.command(name="roll")
async def _roll(ctx):
user_id = ctx.author.id
roll_limit = 10
n = 0
if(is_waifu_roll_in_progress(user_id)):
await ctx.channel.send(f"❌ **{ctx.author.display_name}**, you already have a waifu roulette session in progress.")
return
else:
waifu_roll_in_progress(user_id, True)
if(is_rate_limited(user_id)):
await ctx.channel.send(f"❌**{ctx.author.display_name}**, you are rolling too much. Try again in {get_time_left(user_id)} seconds.")
waifu_roll_in_progress(user_id, False)
return
else:
set_roll_rate_limit(user_id)
try:
waifu_info = generate_random_waifu()
except:
await ctx.send(f"❗ {ctx.author.display_name}, we seem to be experiencing issues. Try again after some time. Admin has been notified.")
waifu_roll_in_progress(user_id, False)
return
embedVar = discord.Embed(title="Waifu roll!", description="Use 🎲 to roll, 💘 to claim.").set_author(
name=ctx.author, icon_url=ctx.author.avatar_url).set_image(url=ctx.author.avatar_url)
msgId = await ctx.send(embed=embedVar)
await msgId.add_reaction('🎲')
await msgId.add_reaction('💘')
await msgId.add_reaction('🟥')
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ['🎲', '💘', '🟥']
while True:
embedVar = discord.Embed(title="Waifu roll!", description="Use 🎲 to roll, 💘 to claim.").set_author(
name=ctx.author, icon_url=ctx.author.avatar_url).set_image(url=ctx.author.avatar_url)
try:
reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await msgId.delete()
waifu_roll_in_progress(user_id, False)
return
else:
embedVar = discord.Embed(title="Waifu roll!", description="Use 🎲 to roll, 💘 to claim.").set_author(
name=ctx.author, icon_url=ctx.author.avatar_url).set_image(url=ctx.author.avatar_url)
if (reaction.emoji == '🎲'):
if (n>roll_limit):
await ctx.send(f"❌**{ctx.author.display_name}**, {roll_limit} rolls per turn only.")
await reaction.remove(ctx.author)
continue
waifu_info = generate_random_waifu()
n += 1
try:
embedVar.set_image(url=waifu_info["image"]["large"]).add_field(
name=waifu_info["name"]["full"], value=waifu_info["media"]["nodes"][0]["title"]["userPreferred"])
except:
await msgId.delete()
await ctx.send(f"{ctx.author.mention}, sincere apologies, we seem to have encountered an error. Admin notified.")
waifu_roll_in_progress(user_id, False)
elif (reaction.emoji == '💘'):
await msgId.delete()
waifu_roll_in_progress(user_id, False)
await ctx.send("💘 **"+ctx.author.display_name+"** claimed **"+waifu_info["name"]["full"]+"**.")
try:
claim_waifu(user_id, waifu_info["id"])
insert_waifu_data_into_db(waifu_info["id"], waifu_info["name"]["full"], waifu_info["image"]
["large"], waifu_info["media"]["nodes"][0]["title"]["userPreferred"])
except:
await ctx.send("Something went wrong, your request has been saved and will be processed soon.")
return
elif (reaction.emoji == '🟥'):
await msgId.delete()
waifu_roll_in_progress(user_id, False)
return
try:
await msgId.edit(embed=embedVar)
except:
await reaction.remove(ctx.author)
continue
await reaction.remove(ctx.author)
@w.command(name="list")
async def _list(ctx):
user_id = ctx.author.id
waifu_ids = get_waifu_list_for_user(user_id)
if len(waifu_ids) == 0:
await ctx.send(f"❌You seem to not have claimed any waifus. Use ``{bot.command_prefix}w roll`` to claim a waifu and try again.")
return
page_no = 0
embedVar = discord.Embed(title=get_waifu_data_from_db(waifu_ids[page_no]["anilist_id"])["name"], description=get_waifu_data_from_db(waifu_ids[page_no]["anilist_id"])["anime_name"]).set_author(
icon_url=ctx.author.avatar_url, name=ctx.author).set_image(url=get_waifu_data_from_db(waifu_ids[page_no]["anilist_id"])["image_url"]).set_footer(text=f"{bot.command_prefix}roulette roll to claim.")
msgId = await ctx.send(embed=embedVar)
await msgId.add_reaction('⏮')
await msgId.add_reaction('🟥')
await msgId.add_reaction('⏭')
await msgId.add_reaction('💔')
await msgId.add_reaction('💾')
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ['⏮', '⏭', '🟥', '💾', '💔']
while True:
embedVar = discord.Embed(title=get_waifu_data_from_db(waifu_ids[page_no]["anilist_id"])["name"], description=get_waifu_data_from_db(waifu_ids[page_no]["anilist_id"])["anime_name"]).set_author(
icon_url=ctx.author.avatar_url, name=ctx.author).set_image(url=get_waifu_data_from_db(waifu_ids[page_no]["anilist_id"])["image_url"]).set_footer(text=f"{bot.command_prefix}roulette roll to claim.")
try:
reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await msgId.delete()
return
else:
if(reaction.emoji == '⏮' and page_no>=0):
page_no -= 1
elif (reaction.emoji == '⏭' and page_no<=len(waifu_ids)-1):
page_no+= 1
elif(reaction.emoji == '🟥'):
await msgId.delete()
return
if (page_no<0):
page_no = 0
elif (page_no>len(waifu_ids)-1):
page_no = len(waifu_ids)-1
embedVar = discord.Embed(title=get_waifu_data_from_db(waifu_ids[page_no]["anilist_id"])["name"], description=get_waifu_data_from_db(waifu_ids[page_no]["anilist_id"])["anime_name"]).set_author(
icon_url=ctx.author.avatar_url, name=ctx.author).set_image(url=get_waifu_data_from_db(waifu_ids[page_no]["anilist_id"])["image_url"]).set_footer(text=f"{bot.command_prefix}roulette roll to claim.")
if(reaction.emoji == '💾'):
await ctx.send(embed=embedVar)
await reaction.remove(ctx.author)
continue
if (reaction.emoji == '💔'):
try:
remove_waifu(ctx.author.id, waifu_ids[page_no]["anilist_id"])
except:
await ctx.send("An error occurred. Please try again.")
await msgId.delete()
waifu_name = get_waifu_data_from_db(waifu_ids[page_no]["anilist_id"])["name"]
await ctx.send(f"<@!{ctx.author.id}> dumped **{waifu_name}**.")
await msgId.delete()
return
await msgId.edit(embed=embedVar)
await reaction.remove(ctx.author)
@commands.is_owner()
@bot.group(description="Admin commands.")
async def admin(ctx):
if ctx.invoked_subcommand is None:
await ctx.send("❌ Baka Admin! Go learn the commands first!")
@admin.command(name="info")
async def _info(ctx):
await ctx.send(f"Admin senpai is **{ctx.author.display_name}**.")
@admin.command(name="restartroulette")
async def _restart(ctx):
msgId = await ctx.send(f"{ctx.author.mention} Resetting...")
try:
reset_user_roll_stats()
await msgId.edit(content="Reset.")
except:
await msgId.edit(content="Resetting DB failed.")
@admin.command(name="addwaifu")
async def _addwaifu(ctx, user_id : int, waifu_id : int):
try:
print(user_id)
claim_waifu(user_id, waifu_id)
waifu_data = get_waifu_info_for_id(waifu_id)
print(waifu_data["name"]["full"])
insert_waifu_data_into_db(waifu_id, waifu_data["name"]["full"], waifu_data["image"]["large"], waifu_data["media"]["nodes"][0]["title"]["userPreferred"])
except:
await ctx.send(f"{ctx.author.mention} Failed to add waifu. Check logs.")
return
waifu_name = waifu_data["name"]["full"]
await ctx.send(f"{ctx.author.mention}, **{waifu_name}** has been added to <@!{user_id}>\'s harem.")
@admin.command(name="removewaifu")
async def _removewaifu(ctx, user_id : int, waifu_id : int):
try:
print(user_id)
remove_waifu(user_id, waifu_id)
except:
await ctx.send(f"{ctx.author.mention}, removing waifu with id {waifu_id} from <@!{user_id}> failed.")
return
await ctx.send(f"{ctx.author.mention}, removing waifu with id {waifu_id} from <@!{user_id}> was successful.")
bot.run(token)