5
1
Fork 0
mirror of https://github.com/Anvilcraft/jensmemes synced 2024-11-12 13:01:30 +01:00

added registration bot

This commit is contained in:
Jonas Leder 2020-06-26 10:25:39 +02:00
parent aaa8b17c8a
commit 5b171576f0
2 changed files with 41 additions and 0 deletions

33
Bot/bot.py Normal file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env python3
import discord
from discord.ext import commands, tasks
from config import *
import pymysql
from hashlib import md5
bot = commands.Bot(command_prefix=prefix)
@bot.event #print the username and id to the console and change the game status
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
async def register(ctx):
name = ctx.author.name
token = md5(str(ctx.author.id).encode()).hexdigest()
user = bot.get_user(ctx.author.id)
db = pymysql.connect(sqlServer,sqlUser,sqlPassword,sqlDatabase )
cursor = db.cursor()
cursor.execute("SELECT * FROM token WHERE name=%s AND token=%s", (name, token))
if(len(cursor.fetchall()) == 0):
cursor.execute("INSERT INTO token (name, token, uploadsLast24H) VALUES (%s, %s, 0)", (name, token))
db.commit()
db.close()
await user.send("Your Token for Jensmemes is " + token)
bot.run(token, bot=botAccount)#start the bot with the options in config.py

8
Bot/config-example.py Normal file
View file

@ -0,0 +1,8 @@
token = ""
botAccount = True #if you use a normal useraccount, set this to false
prefix = "!" #This you have to enter before every command (e.g. ?help)
sqlServer = ""
sqlUser = ""
sqlPassword = ""
sqlDatabase = ""