async def sql(ctx, *, sql: str): if common.isDiscordBotOwner(ctx.message.author.id): try: database.cursor.execute( sql ) #dont ever do this anywhere else VERY bad and will f**k your day up except Exception as e: await discord.bot.say("```{}```".format(e)) return dbres = database.cursor.fetchall() if len(dbres) is 0: await discord.bot.say("```DB returned zero results.```") return columns = [] columns.append(list( dbres[0].keys())) #this gets the header for tabulate for res in dbres: columns.append(list( res.values())) #this builds the rows of the results #tabulate this into a string https://pypi.python.org/pypi/tabulate postdb = tabulate(columns, headers="firstrow") #check the length if len(postdb) >= 1990: await discord.bot.say( "```DB returned a result that is {} characters over the Discord limit```" .format(1990 - len(dbres))) return await discord.bot.say("```{0}```".format(postdb))
async def run(ctx, *, msg: str): if common.isDiscordBotOwner(ctx.message.author.id): emd = discord.embeds.Embed(color=0xE79015) try: evalData = eval(msg.replace('`', '')) except Exception as e: evalData = e emd.add_field(name="Result", value=evalData) await discord.bot.say(embed=emd)
async def sql(ctx, *, sql: str): if common.isDiscordBotOwner(ctx.message.author.id): try: database.cursor.execute( sql ) #dont ever do this anywhere else VERY bad and will f**k your day up except Exception as e: await discord.bot.say("```{}```".format(e)) return dbres = database.cursor.fetchall() if len(dbres) is 0: await discord.bot.say("```DB returned zero results.```") return # format to human readable format table_result = common.dbtable_to_strtable(dbres) if table_result: await discord.bot.say("```{0}```".format(table_result)) else: await discord.bot.say( "```DB returned a result that is {} characters over the Discord limit```" .format(1990 - len(dbres)))
async def isowner(ctx): if common.isDiscordBotOwner(ctx.message.author.id): await discord.bot.say("I live to please {0.message.author.mention} every way possible ( ͡° ͜ʖ ͡°)".format(ctx))