Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- import logging
- from discord.ext import commands
- import mysql.connector
- import json
- if not discord.opus.is_loaded():
- discord.opus.load_opus('opus')
- bot_prefix = "$"
- bot = commands.Bot(command_prefix=bot_prefix)
- logger = logging.getLogger('discord')
- logger.setLevel(logging.DEBUG)
- handler = logging.FileHandler(filename='output.log', encoding='utf-8', mode='w')
- handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
- logger.addHandler(handler)
- @bot.event
- async def on_ready():
- print("Bot Online!")
- print("Name: {}".format(bot.user.name))
- print("ID: {}".format(bot.user.id))
- await bot.change_presence(game=discord.Game(name='games at ESF'))
- @bot.event
- async def on_message(message):
- channel = message.channel
- if (str(channel.type) == "private"):
- if (message.content.startswith('Danke f') == False):
- await bot.send_message(channel,"Danke für Ihre Anfrage, wie werden sie so schnell wie möglich bearbeiten!")
- #message an support channel weiterleiten
- #await bot.send_message(IDVONSUPPORTCHANNEL, message.content)
- @bot.command(pass_context=True)
- async def verify(ctx, code):
- channel = ctx.message.channel
- code = str(code)
- cnx = mysql.connector.connect(user='root', password='',
- host='localhost',
- database='discord_bot',
- use_pure=False)
- cursor = cnx.cursor()
- query3 = ("SELECT is_verified FROM users WHERE userid = '"+ctx.message.author.id+"' LIMIT 1;")
- cursor.execute(query3)
- i=0
- for (is_verified) in cursor:
- i = i+1
- if(is_verified[0] == 0):
- query = ("SELECT is_claimed FROM codes WHERE code = '"+code+"' LIMIT 1;")
- cursor.execute(query)
- k = 0
- for (is_claimed) in cursor:
- k = i + 1
- if(is_claimed[0] == 0):
- print("Updating")
- query1 = ("UPDATE codes SET is_claimed=1 WHERE code = '"+code+"';")
- cursor.execute(query1)
- query4 = ("UPDATE users SET is_verified=1, verification_code='"+code+"' WHERE userid = '"+ctx.message.author.id+"';")
- cursor.execute(query4)
- cnx.commit()
- await bot.send_message(channel,"Successfully verified your account!")
- else:
- await bot.send_message(channel,"The verification code '"+code+"' was already used.")
- cursor.close()
- if(k==0):
- await bot.send_message(channel, "The verification code is invalid.")
- else:
- await bot.send_message(channel, "User already verified.")
- if(i==0):
- await bot.send_message(channel, "Creating user..")
- query5 = ("INSERT INTO users(userid,username) VALUES ('"+ctx.message.author.id+"','"+ctx.message.author.name+"') ")
- cursor.execute(query5)
- cnx.commit()
- query = ("SELECT is_claimed FROM codes WHERE code = '" + code + "' LIMIT 1;")
- cursor.execute(query)
- k = 0
- for (is_claimed) in cursor:
- k = i + 1
- if (is_claimed[0] == 0):
- print("Updating")
- query1 = ("UPDATE codes SET is_claimed=1 WHERE code = '" + code + "';")
- cursor.execute(query1)
- query4 = (
- "UPDATE users SET is_verified=1, verification_code='" + code + "' WHERE userid = '" + ctx.message.author.id + "';")
- cursor.execute(query4)
- cnx.commit()
- await bot.send_message(channel, "Successfully verified your account!")
- else:
- await bot.send_message(channel, "The verification code '" + code + "' was already used.")
- cursor.close()
- if (k == 0):
- await bot.send_message(channel, "The verification code is invalid.")
- cnx.close()
- #da gehört dann der token von discord dev rein
- bot.run("NDIzMTkxODEzNTIwODgzNzIy.DYmvqQ.4nO--cNMpUBTKBi79JjAELLf3Ck")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement