def graph(self, ctx, lower_limit : int, upper_limit : int, *, equation : str):
'''WIP'''
filename = "data/temp/graph.png"
try:
equation = self.string_to_equation(equation)
except SyntaxError as e:
await self.bot.embed_reply(":no_entry: Error: {}".format(e))
return
x = numpy.linspace(lower_limit, upper_limit, 250)
try:
y = numexpr.evaluate(equation)
except Exception as e:
await self.bot.reply(py_code_block.format("{}: {}".format(type(e).__name__, e)))
return
try:
matplotlib.pyplot.plot(x, y)
except ValueError as e:
await self.bot.embed_reply(":no_entry: Error: {}".format(e))
return
matplotlib.pyplot.savefig(filename)
matplotlib.pyplot.clf()
await self.bot.send_file(destination = ctx.message.channel, fp = filename, content = ctx.message.author.display_name + ':')
# TODO: Send as embed?
评论列表
文章目录