1
0
Fork 0
mirror of synced 2024-05-19 20:12:30 +12:00

Handling testing exception in the cog for now

This commit is contained in:
Phxntxm 2016-07-15 10:59:06 -05:00
parent edaa480aef
commit ce1077bcd9
2 changed files with 27 additions and 28 deletions

3
bot.py
View file

@ -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__':

View file

@ -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):