From 5b171576f0f7df693ad2aa60db26b43ed6c4699d Mon Sep 17 00:00:00 2001 From: Jonas Leder Date: Fri, 26 Jun 2020 10:25:39 +0200 Subject: [PATCH] added registration bot --- Bot/bot.py | 33 +++++++++++++++++++++++++++++++++ Bot/config-example.py | 8 ++++++++ 2 files changed, 41 insertions(+) create mode 100644 Bot/bot.py create mode 100644 Bot/config-example.py diff --git a/Bot/bot.py b/Bot/bot.py new file mode 100644 index 0000000..cda0d98 --- /dev/null +++ b/Bot/bot.py @@ -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 \ No newline at end of file diff --git a/Bot/config-example.py b/Bot/config-example.py new file mode 100644 index 0000000..06ebc2f --- /dev/null +++ b/Bot/config-example.py @@ -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 = "" \ No newline at end of file