aboutsummaryrefslogtreecommitdiffstats
path: root/discord
diff options
context:
space:
mode:
Diffstat (limited to 'discord')
-rw-r--r--discord/README.md10
-rwxr-xr-xdiscord/discord_alert.py48
2 files changed, 58 insertions, 0 deletions
diff --git a/discord/README.md b/discord/README.md
new file mode 100644
index 0000000..189bf7d
--- /dev/null
+++ b/discord/README.md
@@ -0,0 +1,10 @@
+Adapted from past discord alerts
+
+Example usage
+```bash
+$ echo "Test Alert!" | python discord_alert.py https://url
+```
+
+https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
+
+Be sure to keep your discord webhook private!
diff --git a/discord/discord_alert.py b/discord/discord_alert.py
new file mode 100755
index 0000000..fc9542c
--- /dev/null
+++ b/discord/discord_alert.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python3
+# Example usage
+# echo "Test Alert!" | python discord_alert.py https://url
+# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
+
+import sys
+import requests
+import argparse
+
+
+def send_update(name, msg, discord_webhook):
+ """ Send a push to discord webhook url"""
+ formatted = f"⚠️ ALERT {name}\n\n{msg}"
+ message = { 'content' : formatted }
+ sys.stderr.write("Sending request.... ")
+ r = requests.post(url=discord_webhook, data=message)
+ sys.stderr.write(f"{r.status_code}\n")
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-t", "--title", default="")
+ parser.add_argument("url")
+ args = parser.parse_args()
+
+ if not args.url:
+ sys.stderr.write("A webhook url is required\n")
+ sys.stderr.write("Usage:\n\n")
+ sys.stderr.write("python discord_alert.py [-t] <title> <url>\n")
+ sys.exit(1)
+
+ msg = ""
+ line = input()
+ while line:
+ msg += line
+ try:
+ line = input()
+ except EOFError:
+ break
+ send_update(args.title, msg, args.url)
+
+
+if __name__ == '__main__':
+ try:
+ main()
+ except KeyboardInterrupt:
+ sys.stderr.write("User stopped program\n")
+ sys.exit(0)
+