From d32a49463a20b379468e0997fe349bdb8fb80a64 Mon Sep 17 00:00:00 2001 From: "green." <41323182+greeeen-dev@users.noreply.github.com> Date: Tue, 13 Aug 2024 12:01:15 +0200 Subject: [PATCH] restore progress --- cogs/sysmgr.py | 102 ++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/cogs/sysmgr.py b/cogs/sysmgr.py index 09f7e4dd..4a143f89 100644 --- a/cogs/sysmgr.py +++ b/cogs/sysmgr.py @@ -817,68 +817,66 @@ async def reload_services(self,ctx,*,services=None): text = f'\n\n{selector.get("extension")} `{fail}`\n```{errors[index]}```' index += 1 if not len(failed) == 0: - await ctx.author.send(f'**Fail logs**\n{text}') + await ctx.author.send(f'**{selector.get("fail_logs")}**\n{text}') - @commands.command(hidden=True, description='Evaluates code.') + @commands.command(hidden=True, description=language.desc('sysmgr.eval')) @restrictions.owner() async def eval(self, ctx, *, body): - if ctx.author.id == self.bot.config['owner']: - env = { - 'ctx': ctx, - 'channel': ctx.channel, - 'author': ctx.author, - 'guild': ctx.guild, - 'message': ctx.message, - 'source': inspect.getsource, - 'session': self.bot.session, - 'bot': self.bot - } + selector = language.get_selector(ctx) + env = { + 'ctx': ctx, + 'channel': ctx.channel, + 'author': ctx.author, + 'guild': ctx.guild, + 'message': ctx.message, + 'source': inspect.getsource, + 'session': self.bot.session, + 'bot': self.bot + } - env.update(globals()) + env.update(globals()) - body = cleanup_code(body) - stdout = io.StringIO() + body = cleanup_code(body) + stdout = io.StringIO() - to_compile = f'async def func():\n{textwrap.indent(body, " ")}' + to_compile = f'async def func():\n{textwrap.indent(body, " ")}' - try: - if 'bot.token' in body or 'dotenv' in body or '.env' in body or 'environ' in body: - raise ValueError('Blocked phrase') - exec(to_compile, env) - except: - pass + try: + if 'bot.token' in body or 'dotenv' in body or '.env' in body or 'environ' in body: + raise ValueError('Blocked phrase') + exec(to_compile, env) + except: + pass - try: - func = env['func'] - except Exception as e: - await ctx.send('An error occurred while executing the code.', reference=ctx.message) - await ctx.author.send( - f'```py\n{e.__class__.__name__}: {e}\n```\nIf this is a KeyError, it is most likely a SyntaxError.') - return - token_start = base64.b64encode(bytes(str(self.bot.user.id), 'utf-8')).decode('utf-8') - try: - with redirect_stdout(stdout): - # ret = await func() to return output - await func() - except: - value = await self.bot.loop.run_in_executor(None, lambda: stdout.getvalue()) - await ctx.send('An error occurred while executing the code.', reference=ctx.message) - if token_start in value: - return await ctx.author.send('The error contained your bot\'s token, so it was not sent.') - await ctx.author.send(f'```py\n{value}{traceback.format_exc()}\n```') - else: - value = await self.bot.loop.run_in_executor(None, lambda: stdout.getvalue()) - if token_start in value: - return await ctx.send('The output contained your bot\'s token, so it was not sent.') - if value == '': - pass - else: - # here, cause is if haves value - await ctx.send('```%s```' % value) + try: + func = env['func'] + except Exception as e: + await ctx.send(selector.get('error'), reference=ctx.message) + await ctx.author.send( + f'```py\n{e.__class__.__name__}: {e}\n```\n{selector.get("syntaxerror")}') + return + token_start = base64.b64encode(bytes(str(self.bot.user.id), 'utf-8')).decode('utf-8') + try: + with redirect_stdout(stdout): + # ret = await func() to return output + await func() + except: + value = await self.bot.loop.run_in_executor(None, lambda: stdout.getvalue()) + await ctx.send(selector.get('error'), reference=ctx.message) + if token_start in value: + return await ctx.author.send(selector.get('blocked')) + await ctx.author.send(f'```py\n{value}{traceback.format_exc()}\n```') else: - await ctx.send('Only the owner can execute code.') + value = await self.bot.loop.run_in_executor(None, lambda: stdout.getvalue()) + if token_start in value: + return await ctx.send(selector.get('blocked')) + if value == '': + pass + else: + # here, cause is if haves value + await ctx.send('```%s```' % value) - @commands.command(aliases=['stop', 'poweroff', 'kill'], hidden=True, description='Gracefully shuts the bot down.') + @commands.command(aliases=['stop', 'poweroff', 'kill'], hidden=True, description=language.desc('sysmgr.shutdown')) @restrictions.owner() async def shutdown(self, ctx): selector = language.get_selector(ctx)