From 93f45eec122a242f8ac88994d354b724c30c888f Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 8 Nov 2023 14:31:52 +1100 Subject: [PATCH] feat: Send gift to discord webhook --- README.md | 3 ++- gift.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f127ea..a7bd771 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,5 @@ docker run -d \ | cookie | Cookie to use for nb-main | | 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) | \ No newline at end of file +| interval | Interval to send gifts (in seconds) | 86400 (24 hours) | +| discord_webhook | Discord webhook to send notifications to | None | \ No newline at end of file diff --git a/gift.py b/gift.py index b6f8db9..9f0b2b1 100644 --- a/gift.py +++ b/gift.py @@ -137,6 +137,7 @@ def gift(name,email,referer, ip): if send_name.status_code != 200: return "Error sending gift:
" + 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) +