Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions scripts/say.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sys
import os
import http.client
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
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] ) )