From c762c4d26276048be8ae078b9551c673c727c1db Mon Sep 17 00:00:00 2001 From: Roman Peters Date: Thu, 28 Mar 2019 21:34:56 +0100 Subject: [PATCH 1/2] Add webhook-send-message-script --- scripts/say.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 scripts/say.py diff --git a/scripts/say.py b/scripts/say.py new file mode 100644 index 0000000..cc15894 --- /dev/null +++ b/scripts/say.py @@ -0,0 +1,30 @@ +import sys +import os +import http.client +import dotenv +dotenv.load_dotenv(".env") + +def send( message ): + + # your webhook URL + webhookurl = os.environ["WEBHOOK"] + + # compile the form data (BOUNDARY can be anything) + formdata = "------:::BOUNDARY:::\r\nContent-Disposition: form-data; name=\"content\"\r\n\r\n" + message + "\r\n------:::BOUNDARY:::--" + + # get the connection and make the request + connection = http.client.HTTPSConnection("discordapp.com") + connection.request("POST", webhookurl, formdata, { + 'content-type': "multipart/form-data; boundary=----:::BOUNDARY:::", + 'cache-control': "no-cache", + }) + + # get the response + response = connection.getresponse() + result = response.read() + + # return back to the calling function with the result + return result.decode("utf-8") + +# send the messsage and print the response +print( send( sys.argv[1] ) ) From e7636b43b010a85bc49597ff285cbcd554c2c366 Mon Sep 17 00:00:00 2001 From: Roman Peters Date: Thu, 25 Apr 2019 18:18:22 +0200 Subject: [PATCH 2/2] Check number of arguments --- scripts/say.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/say.py b/scripts/say.py index cc15894..5f4da21 100644 --- a/scripts/say.py +++ b/scripts/say.py @@ -4,6 +4,11 @@ import dotenv dotenv.load_dotenv(".env") +if not len(sys.argv) == 2: + print(f"This script requires exactly 1 commandline argument, but got {len(sys.argv) - 1}") + sys.exit() + + def send( message ): # your webhook URL