コード例 #1
0
 async def sql(ctx, *, code):
     code = util.extract_codeblock(code)
     try:
         csr = bot.database.execute(code)
         out = ""
         async with csr as cursor:
             async for row in cursor:
                 out += " ".join(map(repr, row)) + "\n"
         await ctx.send(util.gen_codeblock(out))
         await bot.database.commit()
     except Exception as e:
         await ctx.send(embed=util.error_embed(
             util.gen_codeblock(traceback.format_exc())))
コード例 #2
0
 async def unlink(self,
                  ctx,
                  target_type,
                  target_id,
                  bidirectional: bool = True):
     target_id = util.extract_codeblock(target_id)
     try:
         target_id = int(target_id)
     except ValueError:
         pass
     await eventbus.remove_bridge_link(self.bot.database,
                                       ("discord", ctx.channel.id),
                                       (target_type, target_id),
                                       bidirectional)
     await ctx.send(f"Successfully deleted.")
     pass
コード例 #3
0
 async def link(self,
                ctx,
                target_type,
                target_id,
                bidirectional: bool = True):
     target_id = util.extract_codeblock(target_id)
     try:
         target_id = int(target_id)
     except ValueError:
         pass
     await eventbus.add_bridge_link(self.bot.database,
                                    ("discord", ctx.channel.id),
                                    (target_type, target_id), "manual",
                                    bidirectional)
     await ctx.send(f"Link established.")
     pass
コード例 #4
0
ファイル: debug.py プロジェクト: LyricLy/autobotrobot
    async def py(ctx, *, code):
        "Executes Python. You may supply a codeblock. Comments in the form #timeout:([0-9]+) will be used as a timeout specifier. React with :x: to stop, probably."
        timeout = 5.0
        timeout_match = re.search("#timeout:([0-9]+)", code, re.IGNORECASE)
        if timeout_match:
            timeout = int(timeout_match.group(1))
            if timeout == 0: timeout = None
        code = util.extract_codeblock(code)
        try:
            loc = {
                **locals(), "bot": bot,
                "ctx": ctx,
                "db": bot.database,
                "util": util,
                "eventbus": eventbus
            }

            def check(re, u):
                return str(re.emoji) == "❌" and u == ctx.author

            result = None

            async def run():
                nonlocal result
                result = await util.async_exec(code, loc, globals())

            halt_task = asyncio.create_task(
                bot.wait_for("reaction_add", check=check))
            exec_task = asyncio.create_task(run())
            done, pending = await asyncio.wait(
                (exec_task, halt_task),
                timeout=timeout,
                return_when=asyncio.FIRST_COMPLETED)
            for task in done:
                task.result()  # get exceptions
            for task in pending:
                task.cancel()
            if result != None:
                if isinstance(result, str):
                    await ctx.send(result[:2000])
                else:
                    await ctx.send(util.gen_codeblock(repr(result)))
        except (TimeoutError, asyncio.CancelledError):
            await ctx.send(embed=util.error_embed("Timed out."))
        except BaseException as e:
            await ctx.send(embed=util.error_embed(
                util.gen_codeblock(traceback.format_exc())))
コード例 #5
0
 async def py(ctx, *, code):
     code = util.extract_codeblock(code)
     try:
         loc = {**locals(), "bot": bot, "ctx": ctx, "db": bot.database}
         result = await asyncio.wait_for(util.async_exec(
             code, loc, globals()),
                                         timeout=5.0)
         if result != None:
             if isinstance(result, str):
                 await ctx.send(result[:1999])
             else:
                 await ctx.send(util.gen_codeblock(repr(result)))
     except TimeoutError:
         await ctx.send(embed=util.error_embed("Timed out."))
     except BaseException as e:
         await ctx.send(embed=util.error_embed(
             util.gen_codeblock(traceback.format_exc())))