-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·78 lines (70 loc) · 2.03 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
#!/usr/bin/env python3
import config
import discord
import re
from discord.ext import commands, tasks
from print_queue import pop_message
from cogs.languages import Languages, set_input
from cogs.problems import Problems, read_problems
from utils import search_between
from discord import Game
from discord.utils import escape_mentions, oauth_url
bot = commands.Bot(command_prefix='$')
@bot.event
async def on_ready():
print('Bot is ready.')
await bot.change_presence(activity=Game(name='with code (try $help)'))
@tasks.loop(seconds=0.05)
async def check_print_queue():
try:
data = pop_message()
except:
return
channel_id = data[0]
message = escape_mentions(data[1])
if len(message) > 2000:
await bot.get_channel(channel_id).send(
'[This message is too large.]')
return
try:
await bot.get_channel(channel_id).send(message)
except:
pass
@bot.command()
async def setinput(ctx, *, stdin):
"""Sets the input that is to be passed to code you run.
You can set multiple lines of input.
Using the command without an argument clears the input.
"""
print('Setting input:', stdin)
if '```' in stdin:
data = search_between(stdin, '```', '```')
else:
data = stdin
set_input(ctx.author.id, data)
if data:
message = 'Input set: ```\n' + data + '\n```'
await ctx.send(message)
else:
await ctx.send('Input cleared.')
@bot.command()
async def invite(ctx):
"""Sends the bot invite link."""
await ctx.send(oauth_url(bot.user.id))
@bot.command()
@commands.is_owner()
async def guilds(ctx):
"""Lists the guilds the bot is in. Only available to the bot owner."""
message = 'Guilds the bot is in:```\n'
for guild in bot.guilds:
message += guild.name + '\n'
message += '```'
await ctx.send(message)
def main():
check_print_queue.start()
read_problems()
bot.add_cog(Languages(bot))
bot.add_cog(Problems(bot))
bot.run(config.token)
if __name__ == '__main__':
main()