Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.56 KB | None | 0 0
  1. import sqlite3
  2. import numpy as np
  3. import re
  4. import time
  5. import datetime
  6. import asyncio
  7. import discord
  8. from discord.ext import commands
  9.  
  10. Token = "NDQ2OTU3NTE0MzUzODAzMjY0.DeW17w.zUoKvoNKBPYsOeMj4UhXWLv2D_g"
  11. client = commands.Bot(command_prefix="")
  12. client.remove_command("help")
  13. conn = sqlite3.connect("PointsBot.db")
  14. c = conn.cursor()
  15. unix = time.time()
  16. IsUpdating = False
  17. date = str(datetime.datetime.fromtimestamp(unix).strftime("%Y-%m-%d %H:%M:%S"))
  18. c.execute("CREATE TABLE IF NOT EXISTS users (date TEXT, name TEXT, score NUM, write NUM)")
  19. conn.commit()
  20.  
  21. @client.event
  22. async def on_ready():
  23.     print("Logged in")
  24.     IsUpdating = True
  25.     for server in client.servers:
  26.         for channel in server.channels:
  27.             if str(channel.type) == "text":
  28.                 async for message in client.logs_from(channel, limit=9999999):
  29.                     author = message.author
  30.                     try:
  31.                         c.execute("SELECT score FROM users WHERE name IS '"+str(author)+"'")
  32.                         for row in c.fetchone():
  33.                             c.execute("UPDATE users SET score = score+1 WHERE name is '"+str(author)+"' AND write = 0")
  34.                             conn.commit()
  35.  
  36.                     except TypeError:
  37.                         c.execute("INSERT INTO users VALUES('"+str(date)+"', '"+str(author)+"', 1, 0)")
  38.                         conn.commit()
  39.  
  40.             else:
  41.                 continue
  42.    
  43.     IsUpdating == False
  44.  
  45.     c.execute("UPDATE users SET write = 1")
  46.     conn.commit()
  47.  
  48. @client.event
  49. async def on_message(message):
  50.     author = message.author
  51.     channel = message.channel
  52.     try:
  53.         c.execute("SELECT name FROM users WHERE name IS '"+str(author)+"'")
  54.         for row in c.fetchone():
  55.             c.execute("UPDATE users SET score = score+1 WHERE name IS '"+str(author)+"'")
  56.             c.execute("UPDATE users SET write = 1 WHERE name is '"+str(author)+"'")
  57.             conn.commit()
  58.  
  59.     except TypeError:
  60.         c.execute("INSERT INTO users VALUES('"+str(date)+"', '"+str(author)+"', 1, 0)")
  61.         conn.commit()
  62.    
  63.     if message.content.startswith("!rank") and IsUpdating == False:
  64.         c.execute("SELECT name, score FROM users WHERE name IS '"+str(author)+"'")
  65.         for row in c.fetchmany():
  66.             print(str(row))
  67.            
  68.     elif message.content.startswith("!points") and IsUpdating == True:
  69.         await client.send_message("Sorry im updating")
  70.  
  71.     if message.content.startswith("!lboard") and IsUpdating == False:
  72.         c.execute("SELECT name, score FROM users ORDER BY score DESC")
  73.         for row in c.fetchmany(size=5):
  74.             await client.send_message(channel, str(row))
  75.  
  76.     elif message.content.startswith("!lboard") and IsUpdating == True:
  77.         await client.send_message(channel, "Sorry im updateding")
  78.  
  79.     if message.content.startswith("!help"):
  80.         embed = discord.Embed(
  81.         colour = discord.Color.blue()
  82.         )
  83.        
  84.         embed.set_author(name="Help")
  85.         embed.add_field(name = "!points", value = "Displays your amount of points", inline=False)
  86.         embed.add_field(name = "!lboard", value = "Shows the top five users with the highest score", inline=False)
  87.         embed.add_field(name = "!help", value = "displays this message", inline=False)
  88.  
  89.         await client.send_message(message.channel, embed=embed)
  90.  
  91. @client.event
  92. async def on_message_delete(message):
  93.     author = message.author
  94.     c.execute("UPDATE users SET score = score-1 WHERE name is '"+str(author)+"'")
  95.     conn.commit()
  96.  
  97. client.run(Token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement