From 1c0266a9a92b8f896027b54bcf5f7be08b0d9f7d Mon Sep 17 00:00:00 2001 From: olryts | xyZ Date: Fri, 2 Jul 2021 04:13:13 +0800 Subject: [PATCH 1/5] feature: remove first the image if exists before generating a new one to avoid sending a cache image that cause of multi account --- QRCodeBot.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/QRCodeBot.py b/QRCodeBot.py index d118afd..9a3e6ed 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 @@ -50,6 +51,11 @@ def getQRCode(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('QRCode.png'): + os.remove('QRCode.png') + # Save the image img.save('QRCode.png') return From c123ef3e3252f110554e1c3a4779c8949295e930 Mon Sep 17 00:00:00 2001 From: olryts | xyZ Date: Sat, 3 Jul 2021 20:27:53 +0800 Subject: [PATCH 2/5] fixed time not updating every qr request --- DiscordBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscordBot.py b/DiscordBot.py index c1ae431..179aa9b 100644 --- a/DiscordBot.py +++ b/DiscordBot.py @@ -3,7 +3,6 @@ from QRCodeBot import * from datetime import datetime -now = datetime.now() client = discord.Client() @client.event @@ -18,6 +17,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 From fc577e591852539550f20428c3cf7c3dc46b5fb0 Mon Sep 17 00:00:00 2001 From: olryts | xyZ Date: Sun, 18 Jul 2021 21:43:20 +0800 Subject: [PATCH 3/5] qr per discord --- QRCodeBot.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/QRCodeBot.py b/QRCodeBot.py index 9a3e6ed..3b5bb6e 100644 --- a/QRCodeBot.py +++ b/QRCodeBot.py @@ -46,16 +46,18 @@ def submitSignature(signedMessage, message, accountAddress): # Return the accessToken value return json_data['data']['createAccessTokenWithSignature']['accessToken'] -def getQRCode(accessToken): +def getQRCode(accessToken,discordID): # Function to create a QRCode from the accessToken # Make an image as a QR Code from the accessToken img = qrcode.make(accessToken) + qrImg = 'qr/QRCode-'+discordID+'.png' + #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('QRCode.png'): - os.remove('QRCode.png') + if os.path.exists(qrImg): + os.remove(qrImg) # Save the image - img.save('QRCode.png') + img.save(qrImg) return From 052b8fe47cb120a0d96a77beab9c12b8c9979f43 Mon Sep 17 00:00:00 2001 From: olryts | xyZ Date: Sun, 18 Jul 2021 21:48:00 +0800 Subject: [PATCH 4/5] adding file per discord id --- DiscordBot.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/DiscordBot.py b/DiscordBot.py index 179aa9b..ec7bae6 100644 --- a/DiscordBot.py +++ b/DiscordBot.py @@ -2,6 +2,11 @@ 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) client = discord.Client() @@ -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) From f36c794dd8406988d417602d97cf102550314a57 Mon Sep 17 00:00:00 2001 From: olryts | xyZ Date: Sun, 18 Jul 2021 21:48:53 +0800 Subject: [PATCH 5/5] updated to sending qr filename --- QRCodeBot.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/QRCodeBot.py b/QRCodeBot.py index 3b5bb6e..847b771 100644 --- a/QRCodeBot.py +++ b/QRCodeBot.py @@ -46,14 +46,12 @@ def submitSignature(signedMessage, message, accountAddress): # Return the accessToken value return json_data['data']['createAccessTokenWithSignature']['accessToken'] -def getQRCode(accessToken,discordID): +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) - qrImg = 'qr/QRCode-'+discordID+'.png' - #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)