mirror of
https://gitlab.jonasled.de/jonasled/discordbot
synced 2024-11-20 10:13:03 +01:00
commands are now also working via PM
This commit is contained in:
parent
ba7b64e77b
commit
6011802d12
1 changed files with 15 additions and 9 deletions
24
bot.py
24
bot.py
|
@ -70,19 +70,25 @@ async def on_message(message):#this will run on every message
|
|||
current_time = datetime.now().strftime("%H:%M:%S")#get the time as string
|
||||
await message.author.send("Current time: " + current_time)#send the current time to the user as DM
|
||||
return#don't execute the rest (will fail in the next step)
|
||||
if (len(allowOnServer) > 0) and message.guild.id not in allowOnServer:#check if whitelist is enabled and Server on list
|
||||
return#don't execute the rest
|
||||
try:
|
||||
if (len(allowOnServer) > 0) and message.guild.id not in allowOnServer:#check if whitelist is enabled and Server on list
|
||||
return#don't execute the rest
|
||||
except:
|
||||
pass
|
||||
|
||||
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
|
||||
return
|
||||
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
|
||||
result = res.fetchone()
|
||||
if (result == None):
|
||||
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
|
||||
else:
|
||||
messages = result[0] + messageXP
|
||||
dbcursor.execute("UPDATE MESSAGES SET textXP = ? WHERE user = ? AND server = ?", [messages, message.author.id, message.guild.id]) #update the textXP value in the Database
|
||||
try:
|
||||
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
|
||||
result = res.fetchone()
|
||||
if (result == None):
|
||||
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
|
||||
else:
|
||||
messages = result[0] + messageXP
|
||||
dbcursor.execute("UPDATE MESSAGES SET textXP = ? WHERE user = ? AND server = ?", [messages, message.author.id, message.guild.id]) #update the textXP value in the Database
|
||||
except:
|
||||
pass
|
||||
|
||||
dbconnection.commit() #write the database changes to disk
|
||||
|
||||
|
|
Loading…
Reference in a new issue