async def prefix(self, ctx, prefix: str): try: dbInsert.prefix(ctx.guild.id, prefix) await ctx.message.add_reaction("✅") except Exception as e: logger.errorRun("prefix.py prefix - error changing prefix") logger.normRun(e) await ctx.message.add_reaction("❌")
async def loadCog(self, ctx, extension): try: self.bot.load_extension(f'cogs.main.{extension}') logger.normRun(f'Successfully loaded cog: {extension}') state = dbQuery.cogEnabled(extension) dbInsert.cogs(extension, state, True) await ctx.message.add_reaction("✅") except Exception as e: logger.errorRun(f'Failed to load cog: {extension}') logger.errorRun(f'{e}') await ctx.message.add_reaction("❌")
async def enableCmd(self, ctx, *, cmd): allCmd = [] for command in set(ctx.bot.walk_commands()): allCmd.append(str(command)) try: if str(cmd) in allCmd: dbInsert.commands(ctx.guild.id, cmd, True) logger.normRun(f"Successfully enabled command: {cmd}") await ctx.message.add_reaction("✅") else: logger.warnRun(f"Command doesn't exist: {cmd}") await ctx.message.add_reaction("❌") except Exception as e: logger.errorRun(f"Failed to enable command: {cmd}") logger.normRun(e) await ctx.message.add_reaction("❌")
def isAllowed(ctx): try: guildID = ctx.guild.id name = ctx.command.qualified_name author = ctx.message.author.id value = commandCheck(guildID, name) and ignoreCheck(guildID, author) # ups the command usage counter if command checks all pass if value: dbInsert.commandCount(guildID, name) return value except Exception as e: logger.errorRun("commandchecks.py isAllowed - command check failure") logger.errorRun(e) return False
def commit(query, values, data=False): try: cnx = connect() cursor = cnx.cursor() cursor.execute(query, values) if data: returnData = cursor.fetchall() cnx.commit() cnx.close() return returnData else: cnx.commit() cnx.close() except Exception as e: logger.errorRun("dbConnect.py SQLcommit - error committing query") logger.errorRun(e)
async def disableCog(self, ctx, extension): flag = False try: self.bot.load_extension(f'cogs.main.{extension}') self.bot.unload_extension(f'cogs.main.{extension}') flag = True except: try: self.bot.unload_extension(f'cogs.main.{extension}') self.bot.load_extension(f'cogs.main.{extension}') flag = True except: pass if flag: try: state = dbQuery.cogLoaded(extension) dbInsert.cogs(extension, False, state) logger.normRun(f'Successfully disabled cog: {extension}') await ctx.message.add_reaction("✅") except Exception as e: logger.errorRun(f'Failed to disable cog: {extension}') logger.errorRun(f'{e}') await ctx.message.add_reaction("❌") else: logger.errorRun(f'Failed to disable cog: {extension}') await ctx.message.add_reaction("❌")
def connect(): try: conf = config.readINI('mainConfig.ini') cnx = mysql.connect(host=conf['mySQL']['host'], database=conf['mySQL']['dbname'], user=conf['mySQL']['user'], password=conf['mySQL']['password']) return cnx except mysql.Error as e: if e.errno == errorcode.ER_ACCESS_DENIED_ERROR: logger.errorRun( "dbConnect.py SQLconnect - Something is wrong with the username or password" ) logger.normRun(e) elif e.errno == errorcode.ER_BAD_DB_ERROR: logger.errorRun( "dbConnect.py SQLconnect - Database does not exist") logger.normRun(e) else: logger.errorRun("dbConnect.py SQLconnect - error") logger.normRun(e) return False