tools.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:Harmonbot 作者: Harmon758 项目源码 文件源码
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?
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号