feat: Send gift to discord webhook
All checks were successful
Build Docker / Build Image (push) Successful in 20s

This commit is contained in:
Nathan Woodburn 2023-11-08 14:31:52 +11:00
parent 7bb07dbb9e
commit 93f45eec12
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 21 additions and 1 deletions

View File

@ -22,3 +22,4 @@ docker run -d \
| max_price | Maximum price to pay for a domain (in HNS) | 5 |
| max_gifts_per_interval | Maximum number of gifts to send per interval | 24 |
| interval | Interval to send gifts (in seconds) | 86400 (24 hours) |
| discord_webhook | Discord webhook to send notifications to | None |

19
gift.py
View File

@ -137,6 +137,7 @@ def gift(name,email,referer, ip):
if send_name.status_code != 200:
return "Error sending gift:<br>" + send_name.text
discord(domain,email,ip,referer)
return True
@ -149,3 +150,21 @@ def balance():
hns_balance = user_info['hns_balance']
hns_balance = int(hns_balance)/1000000
return hns_balance
def discord(domain, email,ip,referer):
url = os.getenv('discord_webhook')
if url == None:
return "No webhook set"
payload = {
"content": "New gift request: " + domain + "\nSent to " + email + "\nIP: " + ip + "\nReferer: " + referer
}
response = requests.post(url, data=json.dumps(payload), headers={'Content-Type': 'application/json'})
# Check if the message was sent successfully
if response.status_code == 204:
print("Message sent successfully!")
else:
print(f"Failed to send message. Status code: {response.status_code}")
print(response.text)