faucet/gift.py

54 lines
1.2 KiB
Python
Raw Normal View History

2023-11-07 23:04:54 +11:00
import os
import dotenv
import json
dotenv.load_dotenv()
loaded = False
gifts = []
2023-11-07 23:24:09 +11:00
2023-11-07 23:04:54 +11:00
def gift(name,email,referer, ip):
global loaded
global gifts
2023-11-07 23:11:08 +11:00
print("Name: " + name,flush=True)
print("Email: " + email,flush=True)
print("Referer: " + referer,flush=True)
print("IP: " + ip,flush=True)
2023-11-07 23:04:54 +11:00
path = '/data/gifts.json'
if os.getenv('local') == 'true':
path = './gifts.json'
# If the file doesn't exist, create it
if not os.path.isfile(path):
with open(path, 'w') as f:
f.write('[]')
# Load the file
if not loaded:
with open(path, 'r') as f:
gifts = json.load(f)
loaded = True
# Check if the user has already submitted
2023-11-07 23:24:09 +11:00
if ip != os.getenv('admin_ip'):
for gift in gifts:
if gift['email'] == email:
return "You have already submitted a gift request"
if gift['ip'] == ip:
return "You have already submitted a gift request"
2023-11-07 23:04:54 +11:00
# Add the user to the list
gifts.append({
'name': name,
'email': email,
'referer': referer,
'ip': ip
})
# Save the file
with open(path, 'w') as f:
json.dump(gifts, f)
2023-11-07 23:11:08 +11:00
2023-11-07 23:04:54 +11:00
return True