async def dbcommitfone(sqlcommand, value = None): mydb = zz_init.getdb() if(not mydb.is_connected()): print("Verbindung zur DB verloren...wird reconnected") mydb.reconnect(attempts=3, delay=5) mydb = zz_init.getdb() mycursor = mydb.cursor() if(value): mycursor.execute(sqlcommand, value) else: mycursor.execute(sqlcommand) return mycursor.fetchone()
async def on_member_update(before, after): if (before.roles != after.roles and before.guild.id == IDguildCommunity and after.guild.id == IDguildCommunity): mydb = zz_init.getdb() mycursor = mydb.cursor() wlroleyoutube = False wlroletwitch = False for i in ArrayIDgrpsubyoutube: if await zz_functions.checkrole(after.roles, i): wlroleyoutube = True for i in ArrayIDgrpsubtwitch: if await zz_functions.checkrole(after.roles, i): wlroletwitch = True sql = "UPDATE mcnames SET isWhitelistedYoutube = %s WHERE discord_id = %s" val = (wlroleyoutube, after.id) mycursor.execute(sql, val) mydb.commit() sql = "UPDATE mcnames SET isWhitelistedTwitch = %s WHERE discord_id = %s" val = (wlroletwitch, after.id) mycursor.execute(sql, val) mydb.commit() await zz_functions.syncwhitelist() return
async def on_member_remove(member): mydb = zz_init.getdb() mycursor = mydb.cursor() sql = "DELETE FROM mcnames WHERE discord_id = " + str(member.id) mycursor.execute(sql) mydb.commit() sql = "DELETE FROM ranking WHERE discord_id = " + str(member.id) mycursor.execute(sql) mydb.commit() return
async def cmndmc(message, client, name=None): mydb = zz_init.getdb() mycursor = mydb.cursor() if not name: await message.channel.send("Bitte Minecraftname eingeben") author = message.author def check(m): return m.author == message.author mcname = await client.wait_for('message', check=check) name = mcname.content mcsite = requests.get('https://api.mojang.com/users/profiles/minecraft/' + name) if mcsite.text: mcinfo = mcsite.json() uuid = mcinfo['id'] uuid = uuid[0:8] + "-" + uuid[8:12] + "-" + uuid[12:16] + "-" + uuid[16:20] + "-" + uuid[20:32] #await message.channel.send(uuid) sql = "SELECT * FROM mcnames WHERE discord_id ='" + str(message.author.id) + "'" myresult = await dbcommit(sql) if(myresult): sql = "UPDATE mcnames SET minecraft_name = %s, uuid = %s WHERE discord_id = %s" val = (mcinfo['name'], uuid, message.author.id) await message.channel.send("Dein Minecraftname **" + name + "** wurde erfolgreich aktualisiert.") else: whitelistedyoutube = False whitelistedtwitch = True for role in message.author.roles: for youtubeid in ArrayIDgrpsubyoutube: if(role.id == youtubeid): whitelistedyoutube = True for twitchid in ArrayIDgrpsubtwitch: if(role.id == twitchid): whitelistedtwitch = True sql = "INSERT INTO mcnames (discord_id, minecraft_name, uuid, isWhitelistedYoutube, isWhitelistedTwitch) VALUES (%s, %s, %s, %s, %s)" val = (message.author.id, mcinfo['name'], uuid, whitelistedyoutube, whitelistedtwitch) await message.channel.send("Dein Minecraftname **" + name + "** wurde erfolgreich hinzugefügt.") await dbcommit(sql, val, 1) mydb.commit() await syncwhitelist() else: await message.channel.send("Der Minecraftname **" + name + "** existiert nicht.") return