Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import urllib.request
  2. import random
  3. import json
  4.  
  5. try:
  6. from tkinter import Tk, messagebox
  7. except ImportError:
  8. tk = False
  9. else:
  10. tk = True
  11. root = Tk()
  12. root.withdraw()
  13.  
  14. # Discord Markdown formatting works here!
  15. # Keep this in the same order as the WEBHOOKS below if you want -
  16. # webhook/channel-specific messages.
  17. # If you want the same message across all webhooks, just use one message.
  18. MESSAGES = [
  19. "MESSAGE1",
  20. ]
  21.  
  22. # If you have more than one message and want a random one to be sent, -
  23. # set this to True, else set it to False.
  24. randomise = False
  25.  
  26. # Right click channel > Edit Channel > Webhooks
  27. # Create webhook or edit existing, copy URL
  28.  
  29. # Add another line inside the brackets to announce to extra channels
  30. # "WEBHOOK URL",
  31. # note the trailing comma
  32. WEBHOOKS = [
  33. "WEBHOOK URL",
  34. ]
  35.  
  36. statuses = []
  37.  
  38. headers = {'Content-Type': 'application/json',
  39. 'User-Agent': "Stream Announcer"}
  40.  
  41. for ind, hook in enumerate(WEBHOOKS):
  42. if len(MESSAGES) == 1:
  43. message = MESSAGES[0]
  44. elif randomise:
  45. message = random.choice(MESSAGES)
  46. elif len(MESSAGES) == len(WEBHOOKS):
  47. message = MESSAGES[ind]
  48. else:
  49. if tk:
  50. messagebox.showerror('Error',
  51. 'Mismatching message and webhook counts.\n'
  52. 'Fix that or set `randomise` to `True`.')
  53. else:
  54. print('Mismatching message and webhook counts.\n'
  55. 'Fix that or set `randomise` to `True`.')
  56. input('Press RETURN or close the window to exit.')
  57. raise SystemExit(1)
  58. data = json.dumps({'content': message}).encode('utf-8')
  59. req = urllib.request.Request(hook, data=data, headers=headers, method='POST')
  60. with urllib.request.urlopen(req) as r:
  61. statuses.append(r.getcode())
  62.  
  63. print(('Status code: {}\n' * len(statuses)).format(*statuses))
  64. input('Press RETURN or close the window to exit.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement