Advertisement
Guest User

Discord Bot ESF

a guest
Mar 21st, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.12 KB | None | 0 0
  1. import discord
  2. import logging
  3. from discord.ext import commands
  4. import mysql.connector
  5. import json
  6.  
  7. if not discord.opus.is_loaded():
  8.     discord.opus.load_opus('opus')
  9.  
  10. bot_prefix = "$"
  11. bot = commands.Bot(command_prefix=bot_prefix)
  12.  
  13. logger = logging.getLogger('discord')
  14. logger.setLevel(logging.DEBUG)
  15. handler = logging.FileHandler(filename='output.log', encoding='utf-8', mode='w')
  16. handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
  17. logger.addHandler(handler)
  18.  
  19. @bot.event
  20. async def on_ready():
  21.     print("Bot Online!")
  22.     print("Name: {}".format(bot.user.name))
  23.     print("ID: {}".format(bot.user.id))
  24.     await bot.change_presence(game=discord.Game(name='games at ESF'))
  25.  
  26. @bot.event
  27. async def on_message(message):
  28.     channel = message.channel
  29.     if (str(channel.type) == "private"):
  30.         if (message.content.startswith('Danke f') == False):
  31.             await bot.send_message(channel,"Danke für Ihre Anfrage, wie werden sie so schnell wie möglich bearbeiten!")
  32.             #message an support channel weiterleiten
  33.             #await bot.send_message(IDVONSUPPORTCHANNEL, message.content)
  34.  
  35.  
  36. @bot.command(pass_context=True)
  37. async def verify(ctx, code):
  38.     channel = ctx.message.channel
  39.     code = str(code)
  40.     cnx = mysql.connector.connect(user='root', password='',
  41.                               host='localhost',
  42.                               database='discord_bot',
  43.                               use_pure=False)
  44.     cursor = cnx.cursor()
  45.  
  46.     query3 = ("SELECT is_verified FROM users WHERE userid = '"+ctx.message.author.id+"' LIMIT 1;")
  47.     cursor.execute(query3)
  48.     i=0
  49.     for (is_verified) in cursor:
  50.         i = i+1
  51.         if(is_verified[0] == 0):
  52.             query = ("SELECT is_claimed FROM codes WHERE code = '"+code+"' LIMIT 1;")
  53.  
  54.             cursor.execute(query)
  55.             k = 0
  56.             for (is_claimed) in cursor:
  57.                 k = i + 1
  58.                 if(is_claimed[0] == 0):
  59.                     print("Updating")
  60.                     query1 = ("UPDATE codes SET is_claimed=1 WHERE code = '"+code+"';")
  61.                     cursor.execute(query1)
  62.                     query4 = ("UPDATE users SET is_verified=1, verification_code='"+code+"' WHERE userid = '"+ctx.message.author.id+"';")
  63.                     cursor.execute(query4)
  64.                     cnx.commit()
  65.                     await bot.send_message(channel,"Successfully verified your account!")
  66.                 else:
  67.                     await bot.send_message(channel,"The verification code '"+code+"' was already used.")
  68.             cursor.close()
  69.  
  70.             if(k==0):
  71.                 await bot.send_message(channel, "The verification code is invalid.")
  72.         else:
  73.             await bot.send_message(channel, "User already verified.")
  74.  
  75.     if(i==0):
  76.         await bot.send_message(channel, "Creating user..")
  77.         query5 = ("INSERT INTO users(userid,username) VALUES ('"+ctx.message.author.id+"','"+ctx.message.author.name+"') ")
  78.         cursor.execute(query5)
  79.         cnx.commit()
  80.         query = ("SELECT is_claimed FROM codes WHERE code = '" + code + "' LIMIT 1;")
  81.  
  82.         cursor.execute(query)
  83.         k = 0
  84.         for (is_claimed) in cursor:
  85.             k = i + 1
  86.             if (is_claimed[0] == 0):
  87.                 print("Updating")
  88.                 query1 = ("UPDATE codes SET is_claimed=1 WHERE code = '" + code + "';")
  89.                 cursor.execute(query1)
  90.                 query4 = (
  91.                             "UPDATE users SET is_verified=1, verification_code='" + code + "' WHERE userid = '" + ctx.message.author.id + "';")
  92.                 cursor.execute(query4)
  93.                 cnx.commit()
  94.                 await bot.send_message(channel, "Successfully verified your account!")
  95.             else:
  96.                 await bot.send_message(channel, "The verification code '" + code + "' was already used.")
  97.         cursor.close()
  98.  
  99.         if (k == 0):
  100.             await bot.send_message(channel, "The verification code is invalid.")
  101.  
  102.     cnx.close()
  103.  
  104. #da gehört dann der token von discord dev rein
  105. bot.run("NDIzMTkxODEzNTIwODgzNzIy.DYmvqQ.4nO--cNMpUBTKBi79JjAELLf3Ck")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement