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

Modified file to match PEP-8

This commit is contained in:
phxntxm 2016-07-07 17:10:24 -05:00
parent 2feaf487e2
commit 2a9c64f7aa

202
bot.py
View file

@ -16,39 +16,55 @@ import yaml
import playlist import playlist
from threading import Timer from threading import Timer
with open("/home/phxntx5/public_html/bot/config.yml","r") as f: with open("/home/phxntx5/public_html/bot/config.yml", "r") as f:
global_config = yaml.load(f) global_config = yaml.load(f)
botDescription = global_config.get("description") botDescription = global_config.get("description")
commandPrefix = global_config.get("command_prefix") commandPrefix = global_config.get("command_prefix")
#Custom predicates
# Custom predicates
def isOwner(): def isOwner():
def predicate(ctx): def predicate(ctx):
return ctx.message.author.id==ownerID return ctx.message.author.id == ownerID
return commands.check(predicate) return commands.check(predicate)
def isMod(): def isMod():
def predicate(ctx): def predicate(ctx):
return ctx.message.author.top_role.permissions.kick_members return ctx.message.author.top_role.permissions.kick_members
return commands.check(predicate) return commands.check(predicate)
def isAdmin(): def isAdmin():
def predicate(ctx): def predicate(ctx):
return ctx.message.author.top_role.permissions.manage_server return ctx.message.author.top_role.permissions.manage_server
return commands.check(predicate) return commands.check(predicate)
def isPM(): def isPM():
def predicate(ctx): def predicate(ctx):
return ctx.message.channel.is_private return ctx.message.channel.is_private
return commands.check(predicate) return commands.check(predicate)
def battled(): def battled():
def predicate(ctx): def predicate(ctx):
return ctx.message.author==battleP2 return ctx.message.author == battleP2
return commands.check(predicate) return commands.check(predicate)
bot = commands.Bot(command_prefix=commandPrefix,description=botDescription)
bot = commands.Bot(command_prefix=commandPrefix, description=botDescription)
music = playlist.Music(bot) music = playlist.Music(bot)
bot.add_cog(music) bot.add_cog(music)
#Turn battling off, reset users
# Turn battling off, reset users
def battlingOff(): def battlingOff():
global battleP1 global battleP1
global battleP2 global battleP2
@ -57,36 +73,40 @@ def battlingOff():
battleP1 = "" battleP1 = ""
battleP2 = "" battleP2 = ""
#Bot event overrides
# Bot event overrides
@bot.event @bot.event
async def on_ready(): async def on_ready():
#Change the status upon connection to the default status # Change the status upon connection to the default status
game = discord.Game(name=defaultStatus,type=0) game = discord.Game(name=defaultStatus, type=0)
await bot.change_status(game) await bot.change_status(game)
cursor = connection.cursor() cursor = connection.cursor()
'''success = checkSetup(cursor) '''success = checkSetup(cursor)
if success=="Error: default_db": if success=="Error: default_db":
await bot-send_message(determineId(ownerID),("The bot ran into an error while checking the database information." fmt = "The bot ran into an error while checking the database information."
"Please double check the config.yml file, make sure the database is created, and the user has access to the database"))''' await bot.send_message(determineId(ownerID),fmt)'''
cursor.execute('use {0}'.format(db_default)) cursor.execute('use {0}'.format(db_default))
cursor.execute('select channel_id from restart_server where id=1') cursor.execute('select channel_id from restart_server where id=1')
result = cursor.fetchone()['channel_id'] result = cursor.fetchone()['channel_id']
if int(result)!=0: if int(result) != 0:
await bot.send_message(determineId(result),"I have just finished restarting!") await bot.send_message(determineId(result), "I have just finished restarting!")
cursor.execute('update restart_server set channel_id=0 where id=1') cursor.execute('update restart_server set channel_id=0 where id=1')
connection.commit() connection.commit()
@bot.event @bot.event
async def on_member_join(member): async def on_member_join(member):
await bot.say("Welcome to the '{0.server.name}' server {0.mention}!".format(member)) await bot.say("Welcome to the '{0.server.name}' server {0.mention}!".format(member))
@bot.event @bot.event
async def on_member_remove(member): async def on_member_remove(member):
await bot.say("{0} has left the server, I hope it wasn't because of something I said :c".format(member)) await bot.say("{0} has left the server, I hope it wasn't because of something I said :c".format(member))
#Bot commands
# Bot commands
@bot.command() @bot.command()
async def joke(): async def joke():
try: try:
@ -97,6 +117,7 @@ async def joke():
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True) @bot.command(pass_context=True)
@isOwner() @isOwner()
async def restart(ctx): async def restart(ctx):
@ -113,6 +134,7 @@ async def restart(ctx):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True) @bot.command(pass_context=True)
@isOwner() @isOwner()
async def py(ctx): async def py(ctx):
@ -128,11 +150,13 @@ async def py(ctx):
else: else:
def r(v): def r(v):
loop.create_task(bot.say("```{0}```".format(v))) loop.create_task(bot.say("```{0}```".format(v)))
exec(match_multi[0]) exec(match_multi[0])
except Exception as e: except Exception as e:
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True) @bot.command(pass_context=True)
@isOwner() @isOwner()
async def shutdown(ctx): async def shutdown(ctx):
@ -145,6 +169,7 @@ async def shutdown(ctx):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command() @bot.command()
@isOwner() @isOwner()
async def avatar(content): async def avatar(content):
@ -156,6 +181,7 @@ async def avatar(content):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command() @bot.command()
@isOwner() @isOwner()
async def name(newNick): async def name(newNick):
@ -169,7 +195,8 @@ async def name(newNick):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True,no_pm=True)
@bot.command(pass_context=True, no_pm=True)
@isOwner() @isOwner()
async def leave(ctx): async def leave(ctx):
try: try:
@ -179,9 +206,10 @@ async def leave(ctx):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command() @bot.command()
@isMod() @isMod()
async def status(*stat : str): async def status(*stat: str):
try: try:
newStatus = ' '.join(stat) newStatus = ' '.join(stat)
game = discord.Game(name=newStatus, type=0) game = discord.Game(name=newStatus, type=0)
@ -191,9 +219,10 @@ async def status(*stat : str):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True) @bot.command(pass_context=True)
@isMod() @isMod()
async def say(ctx,*msg : str): async def say(ctx, *msg: str):
try: try:
msg = ' '.join(msg) msg = ' '.join(msg)
await bot.say(msg) await bot.say(msg)
@ -201,15 +230,16 @@ async def say(ctx,*msg : str):
except Exception as e: except Exception as e:
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command() @bot.command()
async def urban(*msg : str): async def urban(*msg: str):
try: try:
term = '+'.join(msg) term = '+'.join(msg)
url = "http://api.urbandictionary.com/v0/define?term={}".format(term) url = "http://api.urbandictionary.com/v0/define?term={}".format(term)
response = urllib.request.urlopen(url) response = urllib.request.urlopen(url)
data = json.loads(response.read().decode('utf-8')) data = json.loads(response.read().decode('utf-8'))
if len(data['list'])==0: if len(data['list']) == 0:
await bot.say("No result with that term!") await bot.say("No result with that term!")
else: else:
await bot.say(data['list'][0]['definition']) await bot.say(data['list'][0]['definition'])
@ -218,16 +248,17 @@ async def urban(*msg : str):
except Exception as e: except Exception as e:
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True) @bot.command(pass_context=True)
async def derpi(ctx,*search : str): async def derpi(ctx, *search: str):
try: try:
if len(search) > 0: if len(search) > 0:
url = 'https://derpibooru.org/search.json?q=' url = 'https://derpibooru.org/search.json?q='
query = '+'.join(search) query = '+'.join(search)
url += query url += query
if ctx.message.channel.id in nsfwChannels: if ctx.message.channel.id in nsfwChannels:
url+=",+explicit&filter_id=95938" url += ",+explicit&filter_id=95938"
# url should now be in the form of url?q=search+terms # url should now be in the form of url?q=search+terms
# Next part processes the json format, and saves the data in useful lists/dictionaries # Next part processes the json format, and saves the data in useful lists/dictionaries
response = urllib.request.urlopen(url) response = urllib.request.urlopen(url)
@ -253,6 +284,7 @@ async def derpi(ctx,*search : str):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True) @bot.command(pass_context=True)
async def roll(ctx): async def roll(ctx):
try: try:
@ -263,6 +295,7 @@ async def roll(ctx):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(no_pm=True) @bot.command(no_pm=True)
@battled() @battled()
async def accept(): async def accept():
@ -273,15 +306,16 @@ async def accept():
fmt = battleWins[random.randint(0, len(battleWins) - 1)] fmt = battleWins[random.randint(0, len(battleWins) - 1)]
if num <= 50: if num <= 50:
await bot.say(fmt.format(battleP1.mention, battleP2.mention)) await bot.say(fmt.format(battleP1.mention, battleP2.mention))
updateBattleRecords(battleP1,battleP2) updateBattleRecords(battleP1, battleP2)
elif num > 50: elif num > 50:
await bot.say(fmt.format(battleP2.mention, battleP1.mention)) await bot.say(fmt.format(battleP2.mention, battleP1.mention))
updateBattleRecords(battleP2,battleP1) updateBattleRecords(battleP2, battleP1)
battlingOff() battlingOff()
except Exception as e: except Exception as e:
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(no_pm=True) @bot.command(no_pm=True)
@battled() @battled()
async def decline(): async def decline():
@ -289,12 +323,13 @@ async def decline():
if not battling: if not battling:
return return
await bot.say("{0} has chickened out! {1} wins by default!".format(battleP2.mention, battleP1.mention)) await bot.say("{0} has chickened out! {1} wins by default!".format(battleP2.mention, battleP1.mention))
updateBattleRecords(battleP1,battleP2) updateBattleRecords(battleP1, battleP2)
battlingOff() battlingOff()
except Exception as e: except Exception as e:
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True) @bot.command(pass_context=True)
async def commands(ctx): async def commands(ctx):
try: try:
@ -302,8 +337,8 @@ async def commands(ctx):
fmt += 'Here is a list of commands that you have access to ' fmt += 'Here is a list of commands that you have access to '
fmt += '(please note that this only includes the commands that you have access to):' fmt += '(please note that this only includes the commands that you have access to):'
await bot.whisper(fmt.format(ctx.message, bot)) await bot.whisper(fmt.format(ctx.message, bot))
fmt2 = 'I have just sent you a private message, containing all the commands you have access to {0.author.mention}!' fmt2 = 'I have just sent you a PM, containing all the commands you have access to {0.author.mention}!'
ocmds = 'Commands for everyone: ```' ocmds = 'Commands for everyone: ```'
for com, act in openCommands.items(): for com, act in openCommands.items():
ocmds += commandPrefix + com + ": " + act + "\n\n" ocmds += commandPrefix + com + ": " + act + "\n\n"
@ -340,7 +375,8 @@ async def commands(ctx):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True,no_pm=True)
@bot.command(pass_context=True, no_pm=True)
async def battle(ctx): async def battle(ctx):
try: try:
global battleP1 global battleP1
@ -372,7 +408,8 @@ async def battle(ctx):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True,no_pm=True)
@bot.command(pass_context=True, no_pm=True)
async def boop(ctx): async def boop(ctx):
try: try:
if len(ctx.message.mentions) == 0: if len(ctx.message.mentions) == 0:
@ -413,8 +450,9 @@ async def boop(ctx):
cursor.execute(sql) cursor.execute(sql)
# Booper's table does not exist, need to create the table # Booper's table does not exist, need to create the table
else: else:
sql = "create table `" + str( sql = "create table `" + str(booper.id) + \
booper.id) + "` (`id` varchar(255) not null,`amount` int(11) not null,primary key (`id`)) engine=InnoDB default charset=utf8 collate=utf8_bin" "` (`id` varchar(255) not null,`amount` int(11) not null" + \
",primary key (`id`)) engine=InnoDB default charset=utf8 collate=utf8_bin"
cursor.execute(sql) cursor.execute(sql)
sql = "insert into `" + str(booper.id) + "` (id,amount) values ('" + str(boopee.id) + "',1)" sql = "insert into `" + str(booper.id) + "` (id,amount) values ('" + str(boopee.id) + "',1)"
cursor.execute(sql) cursor.execute(sql)
@ -425,7 +463,8 @@ async def boop(ctx):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True,no_pm=True)
@bot.command(pass_context=True, no_pm=True)
async def mostboops(ctx): async def mostboops(ctx):
try: try:
cursor = connection.cursor() cursor = connection.cursor()
@ -434,13 +473,15 @@ async def mostboops(ctx):
cursor.execute(sql) cursor.execute(sql)
result = cursor.fetchone() result = cursor.fetchone()
member = determineId(result.get('id')) member = determineId(result.get('id'))
await bot.say("{0} you have booped {1} the most amount of times, coming in at {2} times".format(ctx.message.author.mention,member.mention,result.get('amount'))) await bot.say("{0} you have booped {1} the most amount of times, coming in at {2} times".format(
ctx.message.author.mention, member.mention, result.get('amount')))
connection.commit() connection.commit()
except Exception as e: except Exception as e:
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
@bot.command(pass_context=True,no_pm=True)
@bot.command(pass_context=True, no_pm=True)
async def mostwins(ctx): async def mostwins(ctx):
try: try:
members = ctx.message.server.members members = ctx.message.server.members
@ -459,26 +500,26 @@ async def mostwins(ctx):
winAmt = int(record.split('-')[0]) winAmt = int(record.split('-')[0])
loseAmt = int(record.split('-')[1]) loseAmt = int(record.split('-')[1])
percentage = winAmt / ( winAmt + loseAmt ) percentage = winAmt / (winAmt + loseAmt)
position = count position = count
indexPercentage = 0 indexPercentage = 0
if count > 0: if count > 0:
indexRecord = re.search('\d+-\d+',fmt[position-1]).group(0) indexRecord = re.search('\d+-\d+', fmt[position - 1]).group(0)
indexWin = int(indexRecord.split('-')[0]) indexWin = int(indexRecord.split('-')[0])
indexLose = int(indexRecord.split('-')[1]) indexLose = int(indexRecord.split('-')[1])
indexPercentage = indexWin / (indexWin + indexLose) indexPercentage = indexWin / (indexWin + indexLose)
while position > 0 and indexPercentage < percentage: while position > 0 and indexPercentage < percentage:
position -= 1 position -= 1
indexRecord = re.search('\d+-\d+',fmt[position-1]).group(0) indexRecord = re.search('\d+-\d+', fmt[position - 1]).group(0)
indexWin = int(indexRecord.split('-')[0]) indexWin = int(indexRecord.split('-')[0])
indexLose = int(indexRecord.split('-')[1]) indexLose = int(indexRecord.split('-')[1])
indexPercentage = indexWin / (indexWin + indexLose) indexPercentage = indexWin / (indexWin + indexLose)
fmt.insert(position,"{0} has a battling record of {1}".format(member.name,record)) fmt.insert(position, "{0} has a battling record of {1}".format(member.name, record))
count+=1 count += 1
for index in range(0,len(fmt)): for index in range(0, len(fmt)):
fmt[index] = "{0}) {1}".format(index+1,fmt[index]) fmt[index] = "{0}) {1}".format(index + 1, fmt[index])
connection.commit() connection.commit()
if len(fmt) == 0: if len(fmt) == 0:
await bot.say("```No battling records found from any members in this server```") await bot.say("```No battling records found from any members in this server```")
@ -488,9 +529,10 @@ async def mostwins(ctx):
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await bot.say(fmt.format(type(e).__name__, e)) await bot.say(fmt.format(type(e).__name__, e))
def determineId(ID): def determineId(ID):
if type(ID) is int: if type(ID) is int:
ID=str(ID) ID = str(ID)
member = discord.utils.find(lambda m: m.id == ID, bot.get_all_members()) member = discord.utils.find(lambda m: m.id == ID, bot.get_all_members())
if member is not None: if member is not None:
return member return member
@ -504,40 +546,42 @@ def determineId(ID):
if channel is not None: if channel is not None:
return channel return channel
def updateBattleRecords(winner,loser):
def updateBattleRecords(winner, loser):
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute('use {0}'.format(db_default)) cursor.execute('use {0}'.format(db_default))
#Update winners records # Update winners records
sql = "select record from battle_records where id={0}".format(winner.id) sql = "select record from battle_records where id={0}".format(winner.id)
cursor.execute(sql) cursor.execute(sql)
result = cursor.fetchone() result = cursor.fetchone()
if result is not None: if result is not None:
result = result['record'].split('-') result = result['record'].split('-')
result[0] = str(int(result[0])+1) result[0] = str(int(result[0]) + 1)
sql = "update battle_records set record ='{0}' where id='{1}'".format("-".join(result),winner.id) sql = "update battle_records set record ='{0}' where id='{1}'".format("-".join(result), winner.id)
cursor.execute(sql) cursor.execute(sql)
else: else:
sql = "insert into battle_records (id,record) values ('{0}','1-0')".format(winner.id) sql = "insert into battle_records (id,record) values ('{0}','1-0')".format(winner.id)
cursor.execute(sql) cursor.execute(sql)
connection.commit() connection.commit()
#Update losers records # Update losers records
sql = "select record from battle_records where id={0}".format(loser.id) sql = "select record from battle_records where id={0}".format(loser.id)
cursor.execute(sql) cursor.execute(sql)
result = cursor.fetchone() result = cursor.fetchone()
if result is not None: if result is not None:
result = result['record'].split('-') result = result['record'].split('-')
result[1] = str(int(result[1])+1) result[1] = str(int(result[1]) + 1)
sql = "update battle_records set record ='{0}' where id='{1}'".format('-'.join(result),loser.id) sql = "update battle_records set record ='{0}' where id='{1}'".format('-'.join(result), loser.id)
cursor.execute(sql) cursor.execute(sql)
else: else:
sql = "insert into battle_records (id,record) values ('{0}','0-1')".format(loser.id) sql = "insert into battle_records (id,record) values ('{0}','0-1')".format(loser.id)
cursor.execute(sql) cursor.execute(sql)
connection.commit() connection.commit()
def checkSetup(cursor): def checkSetup(cursor):
try: try:
cursor.execute('use {}'.format(db_default)) cursor.execute('use {}'.format(db_default))
@ -547,15 +591,17 @@ def checkSetup(cursor):
try: try:
cursor.execute('describe battle_records') cursor.execute('describe battle_records')
except pymysql.ProgrammingError: except pymysql.ProgrammingError:
#battle_records does not exist, create it # battle_records does not exist, create it
sql = "create table `battle_records` (`id` varchar(32) not null,`record` varchar(32) not null,primary key (`id`)) engine=InnoDB default charset=utf8 collate=utf8_bin" sql = "create table `battle_records` (`id` varchar(32) not null,`record` varchar(32) not null," + \
"primary key (`id`)) engine=InnoDB default charset=utf8 collate=utf8_bin"
cursor.execute(sql) cursor.execute(sql)
connection.commit() connection.commit()
try: try:
cursor.execute('describe restart_server') cursor.execute('describe restart_server')
except pymysql.ProgrammingError: except pymysql.ProgrammingError:
#restart_server does not exist, create it # restart_server does not exist, create it
sql = "create table `restart_server` (`id` int(11) not null auto_increment,`channel_id` varchar(32) not null,primary key (`id`)) engine=InnoDB default charset=utf8 collate=utf8_bin;" sql = "create table `restart_server` (`id` int(11) not null auto_increment,`channel_id` varchar(32)" + \
"not null,primary key (`id`)) engine=InnoDB default charset=utf8 collate=utf8_bin;"
cursor.execute(sql) cursor.execute(sql)
connection.commit() connection.commit()
sql = "insert into restart_server (id,channel_id) values (1,'0')" sql = "insert into restart_server (id,channel_id) values (1,'0')"
@ -565,32 +611,34 @@ def checkSetup(cursor):
cursor.execute('use {}'.format(db_boops)) cursor.execute('use {}'.format(db_boops))
except pymysql.OperationalError: except pymysql.OperationalError:
return "Error: boop_db" return "Error: boop_db"
db_default = global_config.get("db_default") db_default = global_config.get("db_default")
db_boops = global_config.get("db_boops") db_boops = global_config.get("db_boops")
nsfwChannels = global_config.get("nsfw_channel") nsfwChannels = global_config.get("nsfw_channel")
connection = pymysql.connect(host=global_config.get("db_host"), user=global_config.get("db_user"), connection = pymysql.connect(host=global_config.get("db_host"), user=global_config.get("db_user"),
password=global_config.get("db_user_pass"),charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor) password=global_config.get("db_user_pass"), charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
battling=False battling = False
battleP1=None battleP1 = None
battleP2=None battleP2 = None
battleWins = global_config.get("battleWins",[]) battleWins = global_config.get("battleWins", [])
defaultStatus = global_config.get("default_status","") defaultStatus = global_config.get("default_status", "")
botToken = global_config.get("bot_token","") botToken = global_config.get("bot_token", "")
ownerID = global_config.get("owner_id","") ownerID = global_config.get("owner_id", "")
modCommands = global_config.get("modCommands",{}) modCommands = global_config.get("modCommands", {})
adminCommands = global_config.get("adminCommands",{}) adminCommands = global_config.get("adminCommands", {})
openCommands = global_config.get("openCommands",{}) openCommands = global_config.get("openCommands", {})
ownerCommands = global_config.get("ownerCommands",{}) ownerCommands = global_config.get("ownerCommands", {})
voiceCommands = global_config.get("voiceCommands",{}) voiceCommands = global_config.get("voiceCommands", {})
getter = re.compile(r'`(?!`)(.*?)`') getter = re.compile(r'`(?!`)(.*?)`')
multi = re.compile(r'```(.*?)```',re.DOTALL) multi = re.compile(r'```(.*?)```', re.DOTALL)
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
try: try:
bot.run(botToken) bot.run(botToken)
except: except:
quit() quit()