asyncdefon_message(message):#this will run on every message
print(str(message.author)+" sent: "+str(message.content)+", latency: "+str(bot.latency)+" ms, Bot: "+str(message.author.bot))#print some information about the message to the console
if(message.author.bot)or(message.author.id==bot.user.id):#check if the bot has written the message, if yes stop parsing it
res=dbcursor.execute("SELECT textXP FROM MESSAGES WHERE user=? AND server = ?",[message.author.id,message.guild.id])#try to get the current textXP of the user
dbcursor.execute("INSERT INTO MESSAGES VALUES (?, ?, ?, 0, 0)",[message.author.id,message.guild.id,messageXP])#if Bot can't find the user in the Database create a new entry
dbcursor.execute("UPDATE MESSAGES SET textXP = ? WHERE user = ? AND server = ?",[messages,message.author.id,message.guild.id])#update the textXP value in the Database
res=dbcursor.execute("SELECT reactionXP FROM MESSAGES WHERE user=? AND server = ?",[message.user_id,message.guild_id])#try to get the reactionXP from the database
dbcursor.execute("INSERT INTO MESSAGES VALUES (?, ?, 0, ?, 0)",[message.user_id,message.guild_id,reactionXP])#if bot can't find the database entry for the user create a new one
dbcursor.execute("UPDATE MESSAGES SET reactionXP = ? WHERE user = ? AND server = ?",[messages,message.user_id,message.guild_id])#update the reactionXP with the new values
calls=dbcursor.execute("SELECT calls FROM poll WHERE pollID = ? AND reaction = ?",[message.message_id,str(message.emoji)]).fetchone()[0]# if yes update the database and add 1 vote
dbcursor.execute("UPDATE poll SET calls = ? WHERE pollID = ? AND reaction = ?",[calls+1,message.message_id,str(message.emoji)])
calls=dbcursor.execute("SELECT calls FROM poll WHERE pollID = ? AND reaction = ?",[message.message_id,str(message.emoji)]).fetchone()[0]#if yes update the database and remove 1 vote
dbcursor.execute("UPDATE poll SET calls = ? WHERE pollID = ? AND reaction = ?",[calls-1,message.message_id,str(message.emoji)])
result=dbcursor.execute("SELECT vcXP FROM MESSAGES WHERE user=? AND server = ?",[member.id,member.guild.id]).fetchone()[0]#update the user database and set the new Voice XP
dbcursor.execute("UPDATE MESSAGES SET vcXP = ? WHERE user = ? AND server = ?",[result+round(xp),member.id,member.guild.id])
dbconnection.commit()#write the changes to the database
result=dbcursor.execute("SELECT vcXP FROM MESSAGES WHERE user=? AND server = ?",[member.id,member.guild.id]).fetchone()[0]#update the user Table and set the new voiceXP
dbcursor.execute("UPDATE MESSAGES SET vcXP = ? WHERE user = ? AND server = ?",[result+round(xp),member.id,member.guild.id])
xp=dbcursor.execute("SELECT textXP, reactionXP, vcXP FROM MESSAGES WHERE user=? AND server = ?",[user.id,ctx.message.guild.id]).fetchone()#get the xp of the user from database
unsorted=dbcursor.execute("SELECT user, textXP, reactionXP, vcXP FROM MESSAGES WHERE server = ?",[ctx.message.guild.id]).fetchall()#get all users from the database (for the ranking)
unsorted=dbcursor.execute("SELECT user, textXP, reactionXP, vcXP FROM MESSAGES WHERE server = ?",[ctx.message.guild.id]).fetchall()#get all users from the database (for the ranking)
badges=[":first_place: ",":second_place: ",":third_place: ",":four: ",":five: ",":six: ",":seven: ",":eight: ",":nine: ",":keycap_ten: "]#the emoji in front of the username
message=""#in this variable we will prepare in the next step the response
forentriesinreversed(ranking):#loop through every user in reverse order to get the best first and andd his statistics to message
asyncdefping(ctx):#prints the ping and the time the bot needed to process this command
now=datetime.utcnow()#get the current time
delta=round((now.microsecond-ctx.message.created_at.microsecond)/1000)#substract the time the message was created from the current time 8in microsecconds), convert this to millisecconds and round
embed=discord.Embed(title=":ping_pong: | Pong!",description="```prolog\nLatency:: "+str(round(bot.latency*1000))+"ms\nResponse :: "+str(delta)+"ms```")#make the response, we format it as code and select prolog as language for nice cloloring
@bot.command(pass_context=True,brief="starts a poll",description="starts a poll, please give as first argument the question (for sentences please use \") and then the posibilities (leave empty for yes or no)")
asyncdefresult(ctx,id):#this function prints the result of a poll
poll_message=polls[str(id)]#get the poll message from the variable
embed=poll_message.embeds[0]#get the embed (the content)
delpolls[str(id)]#delte the poll from the poll message array
unformatted_options=[x.strip()forxinpoll_message.embeds[0].description.split('\n')]#split the poll options (split every line and remove all leading and trailing spaces)
opt_dict={}
foroptionsinunformatted_options:#for every option: split on the space between emoji and text and put it in a dict, with the emoji as key and the emoji + the text as value
embed2=discord.Embed(title="",description="You can find the result of the poll in the original message [here]("+poll_message.jump_url+").")#This message will be printed to the end of the chat with a link to the original (where the results are)
awaitctx.message.channel.send(embed=embed2)#print the result message from one line up