fix: Discord api
All checks were successful
Build Docker / Build Image (push) Successful in 19s

This commit is contained in:
Nathan Woodburn 2023-12-12 15:13:34 +11:00
parent e60ae30668
commit 2b744a7cf8
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

17
main.py
View File

@ -177,12 +177,21 @@ def update_address():
if 'address' not in r.json():
print("Error: " + r.text,flush=True)
# Send alert via discord
webhook = os.getenv('webhook')
if webhook != None:
url = os.getenv('discord_webhook')
if url == None:
return "No webhook set"
payload = {
"content": "Error: " + r.text
"content": "NB cookie has expired\n@everyone"
}
r = requests.post(webhook, data=json.dumps(payload), headers=headers)
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)
return
address = r.json()['address']