From ce1077bcd965d946e2ff0cca1e8f645565554a64 Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Fri, 15 Jul 2016 10:59:06 -0500 Subject: [PATCH] Handling testing exception in the cog for now --- bot.py | 3 --- cogs/mod.py | 52 +++++++++++++++++++++++++++------------------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/bot.py b/bot.py index 47513ce..0dac2f5 100644 --- a/bot.py +++ b/bot.py @@ -3,7 +3,6 @@ import discord from discord.ext import commands from cogs.utils import config -import traceback extensions = ['cogs.interaction', 'cogs.core', @@ -64,8 +63,6 @@ async def on_command_error(error, ctx): await bot.send_message(ctx.message.channel, fmt) else: fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' - #await bot.send_message(ctx.message.channel,str(traceback.format_exc())) - traceback.print_exc(file=open("/home/phxntx5/public_html/Bonfire/bot_error","a")) await bot.send_message(ctx.message.channel, fmt.format(type(error).__name__, error)) if __name__ == '__main__': diff --git a/cogs/mod.py b/cogs/mod.py index 132aa27..40ec89c 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -92,34 +92,36 @@ class Mod: @perms.command(name="add", aliases=["setup,create"], pass_context=True) @commands.has_permissions(manage_server=True) async def add_perms(self, ctx, command: str, permissions: str): - for checks in self.bot.commands.get(command).checks: - if "isOwner" == checks.__name__: - await self.bot.say("This command cannot have custom permissions setup!") - return - - if getattr(discord.Permissions, permissions, None) is None and not permissions.lower() == "none": - await self.bot.say("{} does not appear to be a valid permission! Valid permissions are: ```{}```" - .format(permissions, "\n".join(valid_perms))) - else: - cursor = config.getCursor() - cursor.execute('use {}'.format(config.db_default)) - cursor.execute("show tables like %s", (ctx.message.server.id,)) - result = cursor.fetchone() - if result is None: - #Server's data doesn't exist yet, need to create it - sql = "create table `{}` (`command` varchar(32) not null,`perms` varchar(32) not null," - "primary key (`command`)) engine=InnoDB default charset=utf8 collate=utf8_bin" - cursor.execute(sql.format(ctx.message.server.id)) - cursor.execute("insert into {} (command, perms) values({}, {})",(ctx.message.server.id,command,perms)) + try: + for checks in self.bot.commands.get(command).checks: + if "isOwner" == checks.__name__: + await self.bot.say("This command cannot have custom permissions setup!") + return + + if getattr(discord.Permissions, permissions, None) is None and not permissions.lower() == "none": + await self.bot.say("{} does not appear to be a valid permission! Valid permissions are: ```{}```" + .format(permissions, "\n".join(valid_perms))) else: - cursor.execute("select perms from %s where command=%s",(ctx.message.server.id,command)) - if cursor.fetchone() is None: + cursor = config.getCursor() + cursor.execute('use {}'.format(config.db_default)) + cursor.execute("show tables like %s", (ctx.message.server.id,)) + result = cursor.fetchone() + if result is None: + #Server's data doesn't exist yet, need to create it + sql = "create table `{}` (`command` varchar(32) not null,`perms` varchar(32) not null," + "primary key (`command`)) engine=InnoDB default charset=utf8 collate=utf8_bin" + cursor.execute(sql.format(ctx.message.server.id)) cursor.execute("insert into {} (command, perms) values({}, {})",(ctx.message.server.id,command,perms)) else: - cursor.execute("update %s set perms=%s where command=%s",(ctx.message.server.id,perms,command)) - - config.closeConnection() - + cursor.execute("select perms from %s where command=%s",(ctx.message.server.id,command)) + if cursor.fetchone() is None: + cursor.execute("insert into {} (command, perms) values({}, {})",(ctx.message.server.id,command,perms)) + else: + cursor.execute("update %s set perms=%s where command=%s",(ctx.message.server.id,perms,command)) + + config.closeConnection() + except: + traceback.print_exc(file=open("/home/phxntx5/public_html/Bonfire/bot_error","a")) def setup(bot):