view.py 972 B

123456789101112131415161718192021222324252627282930
  1. import json
  2. import os
  3. import requests
  4. import sys
  5. from dotenv import load_dotenv
  6. from pprint import pprint
  7. base_url = 'https://discordapp.com/api/webhooks/'
  8. def broadcast(this_text):
  9. load_dotenv()
  10. webhooks_json = os.environ["DISCORD_TOKENS"]
  11. webhooks = json.loads(webhooks_json)
  12. for webhook_key in webhooks:
  13. webhook = webhooks[webhook_key]
  14. if 'sent an application' in this_text:
  15. this_text += ' <@&647609243586920449>'
  16. this_json = {'content': this_text}
  17. pprint(this_json)
  18. url = base_url+webhook
  19. print(url)
  20. # response = requests.post(url, json=this_json)
  21. response = requests.post(url, data=this_json)
  22. if response.status_code in [200, 204]:
  23. print("Webhook executed")
  24. else:
  25. print("status code {}: {}".format(response.status_code, response.content.decode("utf-8")))
  26. if response.status_code == int(429):
  27. sys.exit(1)