create line in sql if not exist on twitch / YT / MC update

This commit is contained in:
Jonas Leder 2020-07-27 16:00:16 +02:00
parent 4ed7df8003
commit 8baf366646

12
main.py
View file

@ -82,6 +82,10 @@ async def mc(ctx, minecraftUsername : str):
return
db = pymysql.connect(sqlServer,sqlUser,sqlPassword,sqlDatabase )
cursor = db.cursor()
cursor.execute("SELECT * FROM users WHERE discord=%s", (ctx.author.id))
if(len(cursor.fetchall()) == 0):
cursor.execute("INSERT INTO users (discord, mcuuid) VALUES (%s, %s)", (member.id, respone["uuid"]))
else:
cursor.execute("UPDATE users SET mcuuid=%s WHERE discord=%s", (respone["uuid"], ctx.author.id))
db.commit()
db.close()
@ -92,6 +96,10 @@ async def mc(ctx, minecraftUsername : str):
async def yt(ctx, youTubeChannelURL):
db = pymysql.connect(sqlServer,sqlUser,sqlPassword,sqlDatabase )
cursor = db.cursor()
cursor.execute("SELECT * FROM users WHERE discord=%s", (ctx.author.id))
if(len(cursor.fetchall()) == 0):
cursor.execute("INSERT INTO users (discord, ytchannel) VALUES (%s, %s)", (member.id, youTubeChannelURL))
else:
cursor.execute("UPDATE users SET ytchannel=%s WHERE discord=%s", (youTubeChannelURL, ctx.author.id))
db.commit()
db.close()
@ -102,6 +110,10 @@ async def yt(ctx, youTubeChannelURL):
async def twitch(ctx, twitchChannelURL):
db = pymysql.connect(sqlServer,sqlUser,sqlPassword,sqlDatabase )
cursor = db.cursor()
cursor.execute("SELECT * FROM users WHERE discord=%s", (ctx.author.id))
if(len(cursor.fetchall()) == 0):
cursor.execute("INSERT INTO users (discord, twchannel) VALUES (%s, %s)", (member.id, twitchChannelURL))
else:
cursor.execute("UPDATE users SET twchannel=%s WHERE discord=%s", (twitchChannelURL, ctx.author.id))
db.commit()
db.close()