diff --git a/cogs/owner.py b/cogs/owner.py index f49dd0a..a825a4d 100644 --- a/cogs/owner.py +++ b/cogs/owner.py @@ -24,10 +24,8 @@ class Owner: @commands.check(checks.isOwner) async def restart(self, ctx): """Forces the bot to restart""" - if config.saveContent('restart_server', ctx.message.channel.id): - await self.bot.say("Restarting; see you in the next life {0}!".format(ctx.message.author.mention)) - else: - await self.bot.say("I was unable to save this data") + config.saveContent('restart_server', ctx.message.channel.id): + await self.bot.say("Restarting; see you in the next life {0}!".format(ctx.message.author.mention)) python = sys.executable os.execl(python, python, *sys.argv) @@ -43,7 +41,7 @@ class Owner: with open(local_path, "wb") as f: f.write(val) await self.bot.say( - "Just saved a new doggo image! You now have {} doggo images!".format(len(glob.glob('doggo*')))) + "Just saved a new doggo image! I now have {} doggo images!".format(len(glob.glob('doggo*')))) @commands.command(pass_context=True) @commands.check(checks.isOwner) @@ -51,20 +49,16 @@ class Owner: """Executes code""" match_single = getter.findall(ctx.message.content) match_multi = multi.findall(ctx.message.content) - if not match_single and not match_multi: - return - else: - if not match_multi: - result = eval(match_single[0]) + if not match_multi: + result = eval(match_single[0]) - if inspect.isawaitable(result): - result = await result - await self.bot.say("```{0}```".format(result)) - else: - def r(v): - config.loop.create_task(self.bot.say("```{0}```".format(v))) - - exec(match_multi[0]) + if inspect.isawaitable(result): + result = await result + await self.bot.say("```{0}```".format(result)) + elif match_single: + def r(v): + config.loop.create_task(self.bot.say("```{0}```".format(v))) + exec(match_multi[0]) @commands.command(pass_context=True) @commands.check(checks.isOwner) @@ -89,9 +83,6 @@ class Owner: """Changes the bot's name""" await self.bot.edit_profile(username=newNick) await self.bot.say('Changed username to ' + newNick) - # Restart the bot after this, as profile changes are not immediate - python = sys.executable - os.execl(python, python, *sys.argv) @commands.command() @commands.check(checks.isOwner) @@ -106,44 +97,32 @@ class Owner: @commands.check(checks.isOwner) async def load(self, *, module: str): """Loads a module""" - try: - module = module.lower() - if not module.startswith("cogs"): - module = "cogs.{}".format(module) - self.bot.load_extension(module) - await self.bot.say("I have just loaded the {} module".format(module)) - except Exception as e: - fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' - await self.bot.say(fmt.format(type(e).__name__, e)) + module = module.lower() + if not module.startswith("cogs"): + module = "cogs.{}".format(module) + self.bot.load_extension(module) + await self.bot.say("I have just loaded the {} module".format(module)) @commands.command() @commands.check(checks.isOwner) async def unload(self, *, module: str): """Unloads a module""" - try: - module = module.lower() - if not module.startswith("cogs"): - module = "cogs.{}".format(module) - self.bot.unload_extension(module) - await self.bot.say("I have just unloaded the {} module".format(module)) - except Exception as e: - fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' - await self.bot.say(fmt.format(type(e).__name__, e)) + module = module.lower() + if not module.startswith("cogs"): + module = "cogs.{}".format(module) + self.bot.unload_extension(module) + await self.bot.say("I have just unloaded the {} module".format(module)) @commands.command() @commands.check(checks.isOwner) async def reload(self, *, module: str): """Reloads a module""" - try: - module = module.lower() - if not module.startswith("cogs"): - module = "cogs.{}".format(module) - self.bot.unload_extension(module) - self.bot.load_extension(module) - await self.bot.say("I have just reloaded the {} module".format(module)) - except Exception as e: - fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' - await self.bot.say(fmt.format(type(e).__name__, e)) + module = module.lower() + if not module.startswith("cogs"): + module = "cogs.{}".format(module) + self.bot.unload_extension(module) + self.bot.load_extension(module) + await self.bot.say("I have just reloaded the {} module".format(module)) def setup(bot):