This repository has been archived by the owner on Aug 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
687 lines (579 loc) · 23.1 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
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
###################
#Bot Created by #RamRam#0001 on discord
#Bugfixing and optimization
#by PervyStella#5667 on discord
###################
import os
from keep_alive import keep_alive
from parser import parse, CommandSyntaxError, CommandUnexpectedEOF
import asyncio
from random import choice, randint
import requests
import actions
import db
from requests.exceptions import RequestException
import sqlite3
import tictactoe
import uno
import error_handling
from constants import Constants, YoumuEmbed
import sauces
import sys
import discord
from discord.ext import commands
from skingrabber import skingrabber
from discord_slash import SlashCommand, SlashContext
from discord_components import DiscordComponents, Button, ButtonStyle
import argparse
import pathlib
import aiosqlite
TOKEN = os.getenv('TOKEN')
if TOKEN is None:
raise ValueError("Please set your discord bot token to the TOKEN enviroment variable")
parser = argparse.ArgumentParser(description="Youmu bot, a wip Discord bot with many functionalities.")
listen_group = parser.add_mutually_exclusive_group()
listen_group.add_argument("--unix", nargs=1, type=pathlib.Path, metavar="path", help="Create a status web server listening in a unix socket")
tcp_group = listen_group.add_argument_group("--tcp")
listen_group.add_argument("--tcp", nargs=2, type=str, metavar=("address", "port"), help="Create a status web server listening in a tcp socket")
args = parser.parse_args()
levels_tbl: db.LevelsTable = None
bot_channel_tbl: db.BotChannelsTable = None
xp_channel_tbl: db.ExpChannelsTable = None
prefix_tbl: db.PrefixTable = None
async def get_prefix(bot, message):
guild_prefixes = await prefix_tbl.get_prefixes(message.guild.id)
return commands.when_mentioned_or(*guild_prefixes)(bot, message)
bot = commands.Bot(command_prefix=get_prefix, help_command=None)
slash = SlashCommand(bot, sync_commands=False) #remember to change back to true
spamlogger={}
comp=DiscordComponents(bot)
ping_messages=Constants.ping_messages
presences=Constants.presences
guild_ids=[]
presence_is_looping=False
spamlogger_is_clearing=False
last_presence=None
async def is_botchannel(ctx):
return await bot_channel_tbl.contains_channel(ctx.channel.id)
############
# on_ready and background tasks
############
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected')
if args.unix:
address = args.unix[0]
elif args.tcp:
address = tuple(args.tcp)
else:
address = None
if address is not None:
asyncio.create_task(keep_alive(address), name="status server")
print("Status server is starting")
#print([guild for guild in bot.guilds])
global guild_ids
guild_ids=[guild.id for guild in bot.guilds]
await asyncio.gather(hourly_precenses(), clear_spamlogger())
async def hourly_precenses():
global presence_is_looping
if not presence_is_looping: #prevent from looping multiple times if on_ready() is called multiple times
presence_is_looping=True
while True:
presence=choice(presences)
global last_presence
if presence==last_presence: #prevent the same status from appearing twice in a row
continue
last_presence=presence
print("changing presence...")
await bot.change_presence(activity=discord.Game(name=presence))
print("done...")
await asyncio.sleep(3600)
@bot.event
async def on_message(message):
if message.author.bot:
return
await bot.process_commands(message)
if isinstance(message.channel, discord.channel.DMChannel):
return
guild_id = message.guild.id
member_id = message.author.id
if await xp_channel_tbl.contains_channel(message.channel.id):
try:
spamlogger[member_id] += 1
except KeyError:
spamlogger[member_id] = 1
old_level, new_level = await levels_tbl.add_exp(guild_id, member_id, 2 * 1 / (spamlogger[member_id] + 1))
if old_level != new_level:
await on_level_up(message)
async def clear_spamlogger():
global spamlogger_is_clearing
global spamlogger
if not spamlogger_is_clearing:
while True:
spamlogger_is_clearing=True
spamlogger={}
await asyncio.sleep(60)
async def on_level_up(message):
stats = await levels_tbl.get_member_stats(message.guild.id, message.author.id)
embed = YoumuEmbed(title='Level Up!',description=f"{message.author.mention}, you have leveled up to level {stats.level}!", color=0x53cc74)
try:
m = await message.channel.send(embed=embed, components=[Button(style=ButtonStyle.red, label="Close", emoji=bot.get_emoji(844701344719962132)),])
except Exception:
m = await message.channel.send(embed=embed, components=[Button(style=ButtonStyle.red, label="Close", emoji='⚔️'),],)
def check(res):
return message.author == res.user and res.channel == message.channel
try:
res = await bot.wait_for("button_click", check=check, timeout=60)
if res.component.label == 'Close':
await m.delete()
except asyncio.TimeoutError:
await m.edit(components=[Button(style=ButtonStyle.red, label="Close", emoji=bot.get_emoji(844701344719962132), disabled=True),])
@bot.event
async def on_guild_channel_create(channel):
print('updating muted role channel perms...')
guild = channel.guild
role = discord.utils.get(guild.roles, name="Speaking Cut")
if not role:
print('creating role...')
role = await guild.create_role(name="Speaking Cut")
permissions = discord.Permissions()
permissions.update(send_messages = False)
await role.edit(reason = None, colour = discord.Colour.black(), permissions=permissions)
print('Changing perms')
for channel in guild.channels:
await channel.set_permissions(role, speak=False, send_messages=False, read_message_history=True, read_messages=True)
else:
await channel.set_permissions(role, speak=False, send_messages=False, read_message_history=True, read_messages=True)
print('success!')
await bot_channel_tbl.add_channel(channel.id)
await xp_channel_tbl.add_channel(channel.id)
@bot.event
async def on_guild_join(guild):
global guild_ids
guild_ids.append(guild.id)
prefix_tbl.add_prefix(guild.id, ";")
role = discord.utils.get(guild.roles, name="Speaking Cut")
if not role:
print('creating role...')
role = await guild.create_role(name="Speaking Cut")
permissions = discord.Permissions()
permissions.update(send_messages = False)
await role.edit(reason = None, colour = discord.Colour.black(), permissions=permissions)
print('Changing perms')
for channel in guild.channels:
await channel.set_permissions(role, speak=False, send_messages=False, read_message_history=True, read_messages=True)
else:
await channel.set_permissions(role, speak=False, send_messages=False, read_message_history=True, read_messages=True)
print('success!')
@bot.event
async def on_command_error(ctx, error):
await error_handling.handle_error(ctx, error)
##########
#Commands
##########
@bot.command()
@commands.check(is_botchannel)
async def ping(ctx):
await ctx.send(f'{choice(ping_messages)} ({round(bot.latency*1000, 2)}ms)')
@bot.command()
async def cut(ctx, *, args):
try:
results=parse(args)
except Exception as e:
if isinstance(e, CommandSyntaxError) or isinstance(e, CommandUnexpectedEOF):
await ctx.send(e.message)
return
else:
raise e
coroutines=[result.run(ctx) for result in results]
await asyncio.gather(*coroutines)
import hashlib
def new_rate(thing: str, upper: int)->int:
digest=hashlib.md5(thing.encode("utf8")).digest()
gen=Random(digest)
return gen.randint(0, upper)
@bot.command()
async def rate(ctx, *, thing):
h=new_rate(thing, 10)
embed=YoumuEmbed(title='Rate',description=f"I would rate *{thing}* a {h} out of 10", colour=0xcc00ff)
await ctx.send(embed=embed)
@bot.command()
@commands.check(is_botchannel)
async def percent(ctx, *, thing):
h=new_rate(str(ctx.author.id)+thing, 100)
embed=YoumuEmbed(title='Rate',description=f"{ctx.author.mention}, you are {h}% {thing}",colour=0xcc00ff)
await ctx.send(embed=embed)
@bot.command()
@commands.check(is_botchannel)
async def ttt(ctx, player: discord.Member):
if player.id==ctx.author.id:
await ctx.send("You can't challenge yourself!")
embed=YoumuEmbed(title='✉️Invitation!✉️', description=f'{player.mention}, {ctx.author.mention} has challenged you to a game of **Tic Tac Toe**. \n\nPress the button within the next minute to start the game. \n\n*Remember that if you don\'t accept, you might lose a friend~*', color=0x53cc74)
button=Button(label='Accept Tic Tac Toe Invite', style=ButtonStyle.green, emoji='☑️')
m=await ctx.send(embed=embed, components=[button])
def check(res):
return player.id == res.user.id and res.channel == ctx.channel
try:
res = await bot.wait_for("button_click", check=check, timeout=60)
if res.component.label=='Accept Tic Tac Toe Invite':
game=tictactoe.TTTGame(bot, ctx, (ctx.author, player))
await m.delete()
await game.start()
except asyncio.TimeoutError:
button=Button(label='Expired Invite :(', style=ButtonStyle.red, emoji='❎', disabled=True)
await m.edit(components=[button])
@bot.command(name='uno', aliases=['nou', 'no_u'])
@commands.check(is_botchannel)
async def one(ctx, *players: discord.Member):
if not len(players) or (len(set(players))==1 and ctx.author in players):
embed=YoumuEmbed(title='Woops!', description=f"You can't play **Uno** by yourself!", color=0xff0f1d)
await ctx.send(embed=embed)
return
game=uno.UnoGame(ctx, bot, *players)
await game.invite()
@bot.command()
@commands.check(is_botchannel)
async def inspire(ctx):
try:
url = 'http://inspirobot.me/api?generate=true'
params = {'generate': 'true'}
response = requests.get(url, params, timeout=10)
image = response.text
embed=YoumuEmbed(title='Inspiration', colour=0x53cc74)
embed.set_image(url=image)
await ctx.send(embed=embed)
except RequestException:
await ctx.send('Inspirobot is broken, there is no reason to live.')
@bot.command()
@commands.check(is_botchannel)
async def skin(ctx, username):
sg = skingrabber()
uuid = sg.get_uuid(user=username)
print(uuid)
render = f"https://visage.surgeplay.com/full/832/{uuid}"
await ctx.send(render)
@bot.command()
@commands.check(is_botchannel)
async def help(ctx):
embed=YoumuEmbed(title='Help',description=f"Check out the documentation that contains the help here:", color=0x53cc74)
await ctx.send(embed=embed, components=[Button(style=ButtonStyle.URL, label="Github", url="https://github.com/4gboframram/Youmu-bot-")])
@bot.command()
async def amogus(ctx):
await ctx.send('ඞ')
########
#Slash Commands
########
@slash.slash(name="cut", description='Cuts a variety of things', guild_ids=guild_ids)
async def _cut(ctx, *, args):
try:
results=parse(args)
except Exception as e:
if isinstance(e, CommandSyntaxError) or isinstance(e, CommandUnexpectedEOF):
await ctx.send(e.message)
return
else: raise e
def check_slash(result):
if isinstance(result, actions.Clear):
return result.run_slash(ctx)
return result.run(ctx)
coroutines=[check_slash(result) for result in results]
await asyncio.gather(*coroutines)
@slash.slash(name="help", description='Go to the github documentation for help about this bot\'s commands', guild_ids=guild_ids)
@commands.check(is_botchannel)
async def _help(ctx):
embed=YoumuEmbed(title='Help',description=f"Check out the documentation that contains the help here: https://github.com/4gboframram/Youmu-bot-", color=0x53cc74)
await ctx.send(embed=embed)
@slash.slash(name="rate", description='What would I rate [thing] out of 10?', guild_ids=guild_ids)
@commands.check(is_botchannel)
async def _rate(ctx, *, thing):
h=new_rate(thing, 10)
embed=YoumuEmbed(title='Rate',description=f"I would rate *{thing}* a {h} out of 10",colour=0xcc00ff)
await ctx.send(embed=embed)
@slash.slash(name="ping", description='Pong?', guild_ids=guild_ids)
@commands.check(is_botchannel)
async def _ping(ctx: SlashContext):
await ctx.send(f'{choice(ping_messages)} ({round(bot.latency*1000, 2)}ms)')
@slash.slash(name="inspire", description='Inspiration anyone? (Generated using Inspirobot)', guild_ids=guild_ids)
@commands.check(is_botchannel)
async def _inspire(ctx):
try:
url = 'http://inspirobot.me/api?generate=true'
params = {'generate': 'true'}
response = requests.get(url, params, timeout=10)
image = response.text
embed=YoumuEmbed(title='Inspiration', colour=0x53cc74)
embed.set_image(url=image)
await ctx.send(embed=embed)
except RequestException:
await ctx.send('Inspirobot is broken, there is no reason to live.')
##################
# Leveling Commands
#################
@bot.command()
@commands.check(is_botchannel)
async def xp(ctx):
stats = await levels_tbl.get_member_stats(ctx.guild.id, ctx.author.id)
needed = db.LevelsTable.needed_exp_to_levelup(stats.level + 1) - stats.exp
embed = YoumuEmbed(title='Xp?', description=f"{ctx.author.mention}, you are level {stats.level}, and {needed} xp from leveling up.", color=0x53cc74)
await ctx.send(embed=embed)
@bot.command()
@commands.check(is_botchannel)
async def rank(ctx):
rank = await levels_tbl.get_member_rank(ctx.guild.id, ctx.author.id)
embed = YoumuEmbed(title='Rank?', description=f"{ctx.author.mention}, you are rank {rank} in the server!", color=0x53cc74)
await ctx.send(embed=embed)
##########
# xp control commands
##########
@bot.command()
@commands.has_permissions(administrator=True)
async def addxpchannel(ctx):
if await xp_channel_tbl.add_channel(ctx.channel.id):
embed = YoumuEmbed(title=f"Xp Channel", description=f"Channel {ctx.channel.mention} is now an xp channel.", colour=0xadf0ff)
await ctx.send(embed=embed)
else:
embed = YoumuEmbed(title=f"Error", description=f"Channel {ctx.channel.mention} is already an xp channel, baka.", colour=0xff0000)
await ctx.send(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
async def removexpchannel(ctx):
if await xp_channel_tbl.remove_channel(ctx.channel.id):
embed = YoumuEmbed(title=f"Xp Channel", description=f"Channel {ctx.channel.mention} is no longer an xp channel.", colour=0xadf0ff)
await ctx.send(embed=embed)
else:
embed = YoumuEmbed(title=f"Xp Channel Error", description=f"Could not remove this channel from the list of xp channels because it is not a xp channel to begin with, baka.", colour=0xff0000)
await ctx.send(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
async def allxpchannel(ctx):
await xp_channel_tbl.add_multiple_channels(channel.id for channel in ctx.guild.text_channels)
embed = YoumuEmbed(title=f"Xp Channel", description=f"All channels are now xp channels", colour=0xadf0ff)
await ctx.send(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
async def removeallxpchannels(ctx):
await xp_channel_tbl.remove_multiple_channels(channel.id for channel in ctx.guild.text_channels)
embed = YoumuEmbed(title=f"Xp Channel", description=f"All xp channels have been removed", colour=0xadf0ff)
await ctx.send(embed=embed)
#####################
# Bot Channel Commands
#####################
@bot.command()
@commands.has_permissions(administrator=True)
async def addbotchannel(ctx):
if await bot_channel_tbl.add_channel(ctx.channel.id):
embed = YoumuEmbed(title=f"Bot Channel", description=f"Channel {ctx.channel.mention} is now a bot channel. If you had no bot channels before, then this is the only channel where this bot's commands can be used", colour=0xadf0ff)
await ctx.send(embed=embed)
else:
embed = YoumuEmbed(title=f"Error", description=f"Channel {ctx.channel.mention} is already a bot channel, baka", colour=0xff0000)
await ctx.send(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
async def removebotchannel(ctx):
if await bot_channel_tbl.remove_channel(ctx.channel.id):
embed = YoumuEmbed(title=f"Xp Channel", description=f"Channel {ctx.channel.mention} is no longer an xp channel.", colour=0xadf0ff)
await ctx.send(embed=embed)
else:
embed = YoumuEmbed(title=f"Xp Channel Error", description=f"Could not remove this channel from the list of xp channels because it is not a xp channel to begin with, baka.", colour=0xff0000)
await ctx.send(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
async def allbotchannel(ctx):
await bot_channel_tbl.add_multiple_channels(channel.id for channel in ctx.guild.text_channels)
embed = YoumuEmbed(title=f"Bot Channel", description=f"All channels are now bot channels", colour=0xadf0ff)
await ctx.send(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
async def removeallbotchannels(ctx):
await bot_channel_tbl.remove_multiple_channels(channel.id for channel in ctx.guild.text_channels)
embed = YoumuEmbed(title=f"Bot Channel", description=f"All bot channels have been removed", colour=0xadf0ff)
await ctx.send(embed=embed)
#########
# Prefix
#########
@bot.command()
async def prefixes(ctx):
prefix = await prefix_tbl.get_prefixes(ctx.guild.id)
prefix_str = '\n'.join(prefix)
print(prefix_str)
embed = YoumuEmbed(title='Prefixes', description=f'Prefixes: \n**{prefix_str}**', color=0x53cc74)
await ctx.send(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
async def addprefix(ctx, prefix):
if await prefix_tbl.add_prefix(ctx.guild.id, prefix):
embed = YoumuEmbed(title=f"Prefix Add!", description=f"Added '{prefix}' to the list of prefixes", colour=0xadf0ff)
else:
embed=YoumuEmbed(title=f"Prefix Error", description=f"That prefix is already a supported prefix!", colour=0xff0000)
await ctx.send(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
async def removeprefix(ctx, prefix):
if await prefixes_tbl.remove_prefix(ctx.guild.id, prefix):
embed = YoumuEmbed(title=f"Prefix Removed!", description=f"Removed '{prefix}' from the list of prefixes", colour=0xadf0ff)
else:
embed = YoumuEmbed(title=f"Prefix Error", description=f"Could not remove the prefix '{prefix}' because it is not a prefix to begin with, baka.", colour=0xff0000)
await ctx.send(embed=embed)
################
# Sauce
##############
@bot.command(name='gelbooru', aliases=['gb'])
@commands.check(is_botchannel)
async def gelbooru(ctx, arg=''):
await sauces.char(ctx, arg)
@bot.command(name='gelboorunf', aliases=['gbnf', 'gbnsfw'])
@commands.check(is_botchannel)
@commands.is_nsfw()
async def gelbooru_nofilter(ctx, arg=''):
await sauces.char(ctx, arg, nsfw=True)
@bot.command(name='gelboorua', aliases=['gba', 'gbanimated', 'gbanim'])
@commands.check(is_botchannel)
async def gelbooruanimated(ctx, arg=''):
await sauces.char(ctx, arg, animated=True)
@bot.command(name='gelbooruanf', aliases=['gbanf', 'gbansfw', 'gbanimatednf', 'gbanimatednsfw', 'gbanimnf', 'gbanimnsfw'])
@commands.check(is_botchannel)
@commands.is_nsfw()
async def gelbooruanimated_nofilter(ctx, arg=''):
await sauces.char(ctx, arg, nsfw=True, animated=True)
@bot.command()
@commands.check(is_botchannel)
async def youmu(ctx):
await sauces.char(ctx, 'konpaku_youmu')
@bot.command(name='youmunf')
@commands.check(is_botchannel)
@commands.is_nsfw()
async def youmu_nofilter(ctx):
await sauces.char(ctx, 'konpaku_youmu', nsfw=True)
@bot.command(aliases=['yuyu'])
@commands.check(is_botchannel)
async def yuyuko(ctx):
await sauces.char(ctx, 'saigyouji_yuyuko')
@bot.command(name='yuyukonf', aliases=['yuyunf'])
@commands.check(is_botchannel)
@commands.is_nsfw()
async def yuyu_nofilter(ctx):
await sauces.char(ctx, 'saigyouji_yuyuko', nsfw=True)
@bot.command(aliases=['flan'])
@commands.check(is_botchannel)
async def flandre(ctx):
await sauces.char(ctx, 'flandre_scarlet')
@bot.command(name='flandrenf', aliases=['flannf'])
@commands.check(is_botchannel)
@commands.is_nsfw()
async def flandre_nofilter(ctx):
await sauces.char(ctx, 'flandre_scarlet', nsfw=True)
@bot.command(aliases=['remi'])
@commands.check(is_botchannel)
async def remilia(ctx):
await sauces.char(ctx, 'remilia_scarlet')
@bot.command(name='remilianf', aliases=['reminf'])
@commands.check(is_botchannel)
@commands.is_nsfw()
async def remilia_nofilter(ctx):
await sauces.char(ctx, 'remilia_scarlet', nsfw=True)
@bot.command()
@commands.check(is_botchannel)
async def marisa(ctx):
score_rng=randint(0,5)
await sauces.char(ctx, f'kirisame_marisa+score:>={score_rng}')
@bot.command(name='marisanf')
@commands.check(is_botchannel)
@commands.is_nsfw()
async def marisa_nofilter(ctx):
score_rng=randint(0,5)
await sauces.char(ctx, f'kirisame_marisa+score:>={score_rng}', nsfw=True)
@bot.command(name='reimu', aliases=['miko'])
@commands.check(is_botchannel)
async def reimu(ctx):
score_rng=randint(0,5)
await sauces.char(ctx, f'Hakurei_Reimu+score:>={score_rng}')
@bot.command(name='reimunf', aliases=['mikonf'])
@commands.check(is_botchannel)
@commands.is_nsfw()
async def reimu_nofilter(ctx):
score_rng=randint(0,5)
await sauces.char(ctx, f'Hakurei_Reimu+score:>={score_rng}', nsfw=True)
@bot.command(name='sakuya')
@commands.check(is_botchannel)
async def sakuya(ctx):
score_rng=randint(0,5)
await sauces.char(ctx, f'izayoi_sakuya+-id:5237460+score:>={score_rng}')
@bot.command(name='sakuyanf')
@commands.check(is_botchannel)
@commands.is_nsfw()
async def sakuya_nofilter(ctx):
score_rng=randint(0,5)
await sauces.char(ctx, f'izayoi_sakuya+-id:5237460+score:>={score_rng}', nsfw=True)
@bot.command(aliases=['patchy'])
@commands.check(is_botchannel)
async def patchouli(ctx):
await sauces.char(ctx, 'patchouli_knowledge')
@bot.command(name='patchoulinf', aliases=['patchynf'])
@commands.check(is_botchannel)
@commands.is_nsfw()
async def patchouli_nofilter(ctx):
await sauces.char(ctx, 'patchouli_knowledge', nsfw=True)
@bot.command(aliases=['baka', 'thestrongest'])
@commands.check(is_botchannel)
async def cirno(ctx):
await sauces.char(ctx, 'cirno')
@bot.command(name='cirnonf', aliases=['bakanf', 'thestrongestnf'])
@commands.check(is_botchannel)
@commands.is_nsfw()
async def cirno_nofilter(ctx):
await sauces.char(ctx, 'cirno', nsfw=True)
@bot.command()
@commands.check(is_botchannel)
async def satori(ctx):
await sauces.char(ctx, 'komeiji_satori')
@bot.command(name='satorinf',)
@commands.check(is_botchannel)
@commands.is_nsfw()
async def cirno_nofilter(ctx):
await sauces.char(ctx, 'komeiji_satori', nsfw=True)
@bot.command(name='char')
@commands.check(is_botchannel)
async def char(ctx, *, tag):
await sauces.char(ctx, tag)
@bot.command(name='charnf')
@commands.check(is_botchannel)
@commands.is_nsfw()
async def char_nofilter(ctx, tag):
await sauces.char(ctx, tag, nsfw=True)
########
#Owner utils. Should not be abused. I just needed it for something
#######
@bot.command()
@commands.is_owner()
async def owner(ctx, guild_id: int, *, message):
guild = bot.get_guild(guild_id)
"""owner=guild.owner
print(owner)
await ctx.author.send(str(owner))"""
channel = guild.text_channels[1]
print(channel)
await channel.send(message)
print('message sent')
print(await channel.invites())
print("got invites")
invite=await channel.create_invite()
print(invite.url)
await ctx.author.send(invite.url)
async def setup():
global levels_tbl, bot_channel_tbl, xp_channel_tbl, prefix_tbl
if not os.path.isdir("data/"):
os.mkdir("data/")
if not os.path.exists("data/youmu.db"):
print("Database doesnt exists, creating")
conn = await aiosqlite.connect("data/youmu.db")
schema = open("youmudb_schema.sql").read()
await conn.executescript(schema)
else:
conn = await aiosqlite.connect("data/youmu.db")
levels_tbl = db.LevelsTable(conn)
bot_channel_tbl = db.BotChannelsTable(conn)
xp_channel_tbl = db.ExpChannelsTable(conn)
prefix_tbl = db.PrefixTable(conn)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(setup())
bot.run(TOKEN)