-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
42 lines (27 loc) · 866 Bytes
/
bot.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
#!/usr/bin/env python3
import os
from os import path
import matplotlib
matplotlib.use('Agg')
import sympy as syp
from discord.ext.commands import Bot
bot = Bot(command_prefix='p$')
TOKEN = os.environ.get('TOKEN')
if not path.exists('.log'): os.mkdir('.log')
log_dir = path.abspath('.log')
@bot.event
async def on_ready():
me = f'{bot.user.name}#{bot.user.discriminator} <@{bot.user.id}>'
print(f'Logged in as {me}')
print('Bot ready!')
@bot.command(aliases=['test'])
async def hello(*args):
return await bot.say('Hello world!')
@bot.command(pass_context=True)
async def plot(ctx, *, exp):
exp = syp.sympify(exp)
img_path = path.join(log_dir, 'figure.png')
img = syp.plot(exp, show=False)
img.save(img_path)
return await bot.upload(img_path)
bot.run(TOKEN) if TOKEN else print('TOKEN environment variable not set!')