lounge.py 文件源码

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

项目:LunaBot 作者: miraai 项目源码 文件源码
def coliru(self, ctx, *, code : CodeBlock):
        """Compiles code via Coliru.

        You have to pass in a codeblock with the language syntax
        either set to one of these:

        - cpp
        - python
        - py
        - haskell

        Anything else isn't supported. The C++ compiler uses g++ -std=c++14.

        Please don't spam this for Stacked's sake.
        """
        payload = {
            'cmd': code.command,
            'src': code.source
        }

        data = json.dumps(payload)

        async with aiohttp.post('http://coliru.stacked-crooked.com/compile', data=data) as resp:
            if resp.status != 200:
                await self.bot.say('Coliru did not respond in time.')
                return
            output = await resp.text()

            if len(output) < 1992:
                fmt = '```\n{}\n```'.format(output)
                await self.bot.say(fmt)
                return

            # output is too big so post it in gist
            gist = {
                'description': 'The response for {0.author}\'s compilation.'.format(ctx.message),
                'public': True,
                'files': {
                    'output': {
                        'content': output
                    },
                    'original': {
                        'content': code.source
                    }
                }
            }

            async with aiohttp.post('https://api.github.com/gists', data=json.dumps(gist)) as gh:
                if gh.status != 201:
                    await self.bot.say('Could not create gist.')
                else:
                    js = await gh.json()
                    await self.bot.say('Output too big. The content is in: {0[html_url]}'.format(js))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号