async def jsk_shell(self, ctx: commands.Context, *, argument: codeblock_converter): """ Executes statements in the system shell. This uses the system shell as defined in $SHELL, or `/bin/bash` otherwise. Execution can be cancelled by closing the paginator. """ async with ReplResponseReactor(ctx.message): with self.submit(ctx): with ShellReader(argument.content) as reader: prefix = "```" + reader.highlight paginator = WrappedPaginator(prefix=prefix, max_size=1975) paginator.add_line(f"{reader.ps1} {argument.content}\n") interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author) self.bot.loop.create_task(interface.send_to(ctx)) async for line in reader: if interface.closed: return await interface.add_line(line) await interface.add_line( f"\n[status] Return code {reader.close_code}")
async def git(self, ctx: commands.Context, pull_push, *, commit_msg=None): """ Executes git statements in the system shell. This uses the system shell as defined in $SHELL, or `/bin/bash` otherwise. Execution can be cancelled by closing the paginator. """ if pull_push == "push": shellcmd = f'sudo git add .&&sudo git commit -m "{commit_msg}"&&sudo git push' if pull_push == "pull": shellcmd = 'sudo git pull' if pull_push not in ['pull', 'push']: return await ctx.send("Invalid option given") async with ReplResponseReactor(ctx.message): paginator = WrappedPaginator(prefix="```sh", max_size=1985) paginator.add_line(f"$ git {pull_push}\n") interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author) self.bot.loop.create_task(interface.send_to(ctx)) if commit_msg is None: commit_msg = "File changes" with ShellReader(shellcmd) as reader: async for line in reader: if interface.closed: return await interface.add_line(line)
async def git(self, ctx, pull_push, *, message=None): """ Executes git statements in the system shell. This uses the system shell as defined in $SHELL, or `/bin/bash` otherwise. Execution can be cancelled by closing the paginator. """ message = message if message is not None else "Updated files." if pull_push == "push": shellcmd = f'sudo git add .&&sudo git commit -m "{message}"&&sudo git push' elif pull_push == "pull": shellcmd = 'sudo git pull' else: return await ctx.send("Invalid option given") async with ReplResponseReactor(ctx.message): paginator = WrappedPaginator(prefix="```sh", max_size=1985) paginator.add_line(f"$ git {pull_push}\n") interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author) self.bot.loop.create_task(interface.send_to(ctx)) with ShellReader(shellcmd) as reader: async for line in reader: if interface.closed: return await interface.add_line(line)
async def speedtest(self, ctx): async with ReplResponseReactor(ctx.message): with ShellReader("speedtest-cli") as reader: prefix = "```" + reader.highlight paginator = WrappedPaginator(prefix=prefix, max_size=1975) paginator.add_line(f"{reader.ps1} 'speedtest-cli'\n") interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author) self.bot.loop.create_task(interface.send_to(ctx)) async for line in reader: if interface.closed: return await interface.add_line(line) await interface.add_line( f"\n[status] Return code {reader.close_code}")