From 93d763e7d4205c9c55a8c182fbcfed2f6f339a07 Mon Sep 17 00:00:00 2001 From: Specoolazius Date: Thu, 31 Mar 2022 15:29:13 +0200 Subject: [PATCH] developer cog with permission granter --- bot/botclient.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/bot/botclient.py b/bot/botclient.py index 688286d..c3ef41f 100644 --- a/bot/botclient.py +++ b/bot/botclient.py @@ -99,6 +99,9 @@ class BotClient(discord.Bot, ABC): # default presence activity=discord.Game('Beep Boop! Loading...'), status=discord.Status.idle, + + # debug + debug_guilds=self.config.debug_guilds, ) self.mc_server = JavaServer( @@ -253,8 +256,41 @@ class Presence(object): class Developer(discord.Cog): """< discord.Cog > + Some developer tools for managing the bot. """ + def __init__(self, bot: BotClient): + self.bot = bot + + async def __permission_granter(self, *path: str) -> int: + process = await asyncio.create_subprocess_shell( + cmd=f'sudo chmod +x {os.path.join(os.getcwd(), *path)}', + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE, + ) + stdout, stderr = await process.communicate() + + self.bot.logger.info(f'Finished bot update with exit code {process.returncode}') + if process.returncode: + self.bot.logger.error(f'stderr:\n{stderr.decode()}') + + else: + self.bot.logger.info(f'stdout:\n{stdout.decode()}') + + return process.returncode + + __dev_group = SlashCommandGroup(name='dev', description='Developer settings') + + @__dev_group.command(name='update') + async def __update_bot(self, ctx: discord.ApplicationContext): + response = await ctx.respond('starting update...') + + if await self.__permission_granter('scripts', 'update.sh') == 0: + print('okay') + + else: + await ctx.respond('Failed to update. Check the log files for further information') + class Status(discord.Cog): """< discord.Cog >