Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions DiscordBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,13 +22,19 @@ 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
if str(message.author.id) in ScholarsDict:
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
Expand All @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions QRCodeBot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
import json
import qrcode
import os
from web3.auto import w3
from eth_account.messages import encode_defunct

Expand Down Expand Up @@ -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