| 1234567891011121314151617181920212223242526272829 |
- import json
- import os
- import requests
- import sys
- from dotenv import load_dotenv
- from pprint import pprint
- base_url = 'https://discordapp.com/api/webhooks/'
- def broadcast(this_text):
- load_dotenv()
- webhooks_json = os.environ["DISCORD_TOKENS"]
- webhooks = json.loads(webhooks_json)
- for webhook_key in webhooks:
- webhook = webhooks[webhook_key]
- if 'sent an application' in this_text:
- this_text = ' @KnockKnock '+this_text
- this_json = {'content': this_text}
- pprint(this_json)
- url = base_url+webhook
- print(url)
- response = requests.post(url, json=this_json)
- if response.status_code in [200, 204]:
- print("Webhook executed")
- else:
- print("status code {}: {}".format(response.status_code, response.content.decode("utf-8")))
- if response.status_code == int(429):
- sys.exit(1)
|