diff --git a/DiscordBot.py b/DiscordBot.py index c1ae431..ec7bae6 100644 --- a/DiscordBot.py +++ b/DiscordBot.py @@ -2,8 +2,12 @@ from SecretStorage import * from QRCodeBot import * from datetime import datetime +from pathlib import Path + +#initializing qr folder +from pathlib import Path +Path("qr").mkdir(parents=True, exist_ok=True) -now = datetime.now() client = discord.Client() @client.event @@ -18,6 +22,7 @@ async def on_message(message): return # If the user writes $qr if message.content == "$qr": + now = datetime.now() current_time = now.strftime("%H:%M:%S") print('\n') # This for loop check for all the user's DiscordID in the Database @@ -25,6 +30,11 @@ async def on_message(message): print("This user received his QR Code : " + message.author.name) print("Discord ID : " + str(message.author.id)) print("Current time : ", current_time) + + #converting discordID to string + discordID = str(message.author.id) + qrImg = 'qr/QRCode-'+discordID+'.png'; + # value with discordID botPlaceHolders = ScholarsDict[str(message.author.id)] # discordID's privateKey from the database @@ -38,11 +48,11 @@ async def on_message(message): # Get an accessToken by submitting the signature to AxieInfinty accessToken = submitSignature(signedMessage, rawMessage, accountAddress) # Create a QrCode with that accessToken - QrCode = getQRCode(accessToken) + QrCode = getQRCode(accessToken,qrImg) # Send the QrCode the the user who asked for await message.author.send( "------------------------------------------------\n\n\nHello " + message.author.name + "\nHere is your new QR Code to login : ") - await message.author.send(file=discord.File('QRCode.png')) + await message.author.send(file=discord.File(qrImg)) return else: print("This user didn't receive a QR Code : " + message.author.name) diff --git a/QRCodeBot.py b/QRCodeBot.py index d118afd..847b771 100644 --- a/QRCodeBot.py +++ b/QRCodeBot.py @@ -1,6 +1,7 @@ import requests import json import qrcode +import os from web3.auto import w3 from eth_account.messages import encode_defunct @@ -45,11 +46,16 @@ def submitSignature(signedMessage, message, accountAddress): # Return the accessToken value return json_data['data']['createAccessTokenWithSignature']['accessToken'] -def getQRCode(accessToken): +def getQRCode(accessToken,qrImg): # Function to create a QRCode from the accessToken # Make an image as a QR Code from the accessToken img = qrcode.make(accessToken) + + #remove first the image if exists before generating a new one to avoid sending a cache image that cause of multi account + if os.path.exists(qrImg): + os.remove(qrImg) + # Save the image - img.save('QRCode.png') + img.save(qrImg) return