removing debug information showing in console.
This commit is contained in:
parent
277cc27d03
commit
f07fcd6af1
@ -15,7 +15,7 @@ def send_discord_message(message, username="Auto Garden Bot"):
|
|||||||
url = secrets.get('discord_webhook_url')
|
url = secrets.get('discord_webhook_url')
|
||||||
try:
|
try:
|
||||||
if not url:
|
if not url:
|
||||||
print("DEBUG: no webhook URL in secrets")
|
print("Error: no webhook URL in secrets")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
url = url.strip().strip('\'"')
|
url = url.strip().strip('\'"')
|
||||||
@ -27,31 +27,15 @@ def send_discord_message(message, username="Auto Garden Bot"):
|
|||||||
|
|
||||||
headers = {"Content-Type": "application/json; charset=utf-8"}
|
headers = {"Content-Type": "application/json; charset=utf-8"}
|
||||||
|
|
||||||
# DEBUG
|
|
||||||
print("DEBUG: webhook url repr:", repr(url))
|
|
||||||
print("DEBUG: body (bytes):", body_bytes)
|
|
||||||
print("DEBUG: headers:", headers)
|
|
||||||
|
|
||||||
resp = requests.post(url, data=body_bytes, headers=headers)
|
resp = requests.post(url, data=body_bytes, headers=headers)
|
||||||
|
|
||||||
status = getattr(resp, "status", getattr(resp, "status_code", None))
|
status = getattr(resp, "status", getattr(resp, "status_code", None))
|
||||||
text = ""
|
|
||||||
try:
|
|
||||||
text = resp.text
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
text = resp.content
|
|
||||||
except:
|
|
||||||
text = "<no body>"
|
|
||||||
|
|
||||||
print("DEBUG: resp status:", status)
|
|
||||||
print("DEBUG: resp body:", text)
|
|
||||||
|
|
||||||
if status and 200 <= status < 300:
|
if status and 200 <= status < 300:
|
||||||
print("Discord message sent")
|
print("Discord message sent")
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print("Discord webhook HTTP", status, "body:", text)
|
print(f"Discord webhook failed with status {status}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user