From cf4e7fdddb42e9377d2a01ce2a0634f8a72223c5 Mon Sep 17 00:00:00 2001 From: sickprodigy Date: Mon, 3 Nov 2025 20:15:21 -0500 Subject: [PATCH] rename file and also cleanup and try again --- Scripts/discord-webhook.py | 31 ------------------------------- Scripts/discord_webhook.py | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 Scripts/discord-webhook.py create mode 100644 Scripts/discord_webhook.py diff --git a/Scripts/discord-webhook.py b/Scripts/discord-webhook.py deleted file mode 100644 index 280bc85..0000000 --- a/Scripts/discord-webhook.py +++ /dev/null @@ -1,31 +0,0 @@ -import network -import requests -# import urequests as requests #dependency faked as another dependency ig - -url = "https://discord.com/api/webhooks/1199545130378608650/UyJj0e-YuSlmVZD87zaHitXZLC55RP6LVBUv3nt9ZWr6d4AGzSGKZ-zI6V_VwA6I4qSq" #webhook url, from here: https://i.imgur.com/f9XnAew.png - -#for all params, see https://discordapp.com/developers/docs/resources/webhook#execute-webhook -data = { - "content" : "Testing", - "username" : "Captain Hook" -} - -#leave this out if you dont want an embed -#for all params, see https://discordapp.com/developers/docs/resources/channel#embed-object -# data["embeds"] = [ -# { -# "description" : "Testing for temps", -# "title" : "Tent Temp=5000c" -# } -# ] - -result = requests.post(url, json = data) - -try: - result.raise_for_status() -except requests.exceptions.HTTPError as err: - print(err) -else: - print("Payload delivered successfully, code {}.".format(result.status_code)) - -#result: https://i.imgur.com/DRqXQzA.png \ No newline at end of file diff --git a/Scripts/discord_webhook.py b/Scripts/discord_webhook.py new file mode 100644 index 0000000..df8be47 --- /dev/null +++ b/Scripts/discord_webhook.py @@ -0,0 +1,22 @@ +import urequests as requests +from secrets import secrets + +def send_discord_message(message, username="Auto Garden Bot"): + try: + data = { + "content": message, + "username": username + } + + response = requests.post(secrets['discord_webhook_url'], json=data) + response.raise_for_status() + print(f"Discord message sent successfully, code {response.status_code}") + return True + + except Exception as e: + print(f"Failed to send Discord message: {str(e)}") + return False + + finally: + if 'response' in locals(): + response.close() \ No newline at end of file