Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. #-------------------------------------------------------------------------------#
  4. Debug = True # This is here for your protection. When debug is True, whispers
  5. # will be printed to the console rather than sent to the Twitch servers. Read
  6. # through the code and comments and run in debug mode until you understand how
  7. # everything works. Once you understand the script, go ahead and change Debug to
  8. # False. When Debug is false, whispers will actually be sent through the IRC
  9. # channel and to Twitch. I do not condone spamming or anything of the sort, this
  10. # script is for educational purposes and is to be used at your own risk. I am not
  11. # responsible for anything that happens due to the use of this script, therefore
  12. # I highly recommend running this on a throwaway Twitch account.
  13. #-------------------------------------------------------------------------------#
  14.  
  15. #------Import Modules------#
  16. import requests
  17. import time
  18. import re
  19. import socket
  20. import tkinter
  21. #--------------------------#
  22.  
  23. #------------------------------------------Start Settings and Variables-----------------------------------------------#
  24. username = input("CSGO_Shuffle: ") # Twitch username
  25. oauth = input("oauth:5b6zy4ep707d933wkf6c5fv8k6swtj: ") # Twitch oauth code - use http://www.twitchapps.com/tmi/ to find
  26. oauthstripped = oauth.replace('oauth:','') # Strip oauth code down (for use later in group chat API)
  27. channel = input("KittyPlaysGames: ") # Twitch channel to pull viewer list from
  28. message = input("Hey: ") # Message to whisper
  29. viewers = [] # Empty array to hold viewers
  30. ip = "" # Default value for server IP
  31. port = 0 # Default value for server port
  32. ircchan = "irc.twitch.tv" # Default value for IRC channel
  33. con = socket.socket() # Intiate con
  34. #------------------------------------------End Settings and Variables-------------------------------------------------#
  35.  
  36. #---------------------------------------------Start IRC Functions-----------------------------------------------------#
  37. def send_message(chan, msg): # Send messages to channel
  38. con.send(bytes('PRIVMSG %s :%s\r\n' % (chan, msg), 'UTF-8'))
  39.  
  40.  
  41. def send_nick(nick): # Set nick, used for logging in
  42. con.send(bytes('NICK %s\r\n' % nick, 'UTF-8'))
  43.  
  44.  
  45. def send_pass(password): # Set pass, used for logging in
  46. con.send(bytes('PASS %s\r\n' % password, 'UTF-8'))
  47.  
  48.  
  49. def join_channel(chan): # Join IRC channel
  50. con.send(bytes('JOIN %s\r\n' % chan, 'UTF-8'))
  51.  
  52.  
  53. def part_channel(chan): # Leave IRC channel
  54. con.send(bytes('PART %s\r\n' % chan, 'UTF-8'))
  55. #----------------------------------------------End IRC Functions------------------------------------------------------#
  56.  
  57. #---------------------------------------------Start Bot Functions-----------------------------------------------------#
  58. def get_group(): # Function to get group chat IRC channel and server
  59. global ip
  60. global port
  61. global ircchan
  62. r = requests.get("https://chatdepot.twitch.tv/room_memberships?oauth_token=" + oauthstripped) # Load group chat API
  63. if r.json()["memberships"]: # If content in memberships exists (checking to see if you have a group chat created)
  64. ircchan = "#" + r.json()["memberships"][0]["room"]["irc_channel"] # Gets and sets IRC channel
  65. print("\nGrabbed IRC Channel: " + ircchan) # Prints channel grabbed
  66. fullip = r.json()["memberships"][0]["room"]["servers"][0] # Gets and sets IRC server
  67. ip,port = re.split(":", fullip) # Splits IRC server into two variables "ip" and "port"
  68. print("Grabbed Server: " + ip) # Print IRC server IP
  69. print("Grabbed Port: " + port + "\n") # Print IRC server port
  70. port = int(port) # Converts port to integer for use in line 73
  71. else: # If user does not have a group chat, do this
  72. print("This bot must use a group chat IRC server in order to run using the whisper command. Please create a group chat so we can grab the IRC server. For instructions on creating a group chat, go here: http://imgur.com/a/Z2gul\n") # Alerts the user that they must create a group chat to continue, instructions given
  73. print("Checking every 5 seconds...\n") # Tell user we will check every 5 seconds for a group chat
  74. time.sleep(5) # Wait 5 seconds
  75. get_group() # Run through get_group function again
  76.  
  77. def get_viewers(): # Function to get all viewers in a channel
  78. r = requests.get("http://tmi.twitch.tv/group/user/" + channel + "/chatters") # Load API
  79. viewers.extend(r.json()["chatters"]["viewers"]) # Find all viewers and put them in the viewers array
  80. print("Grabbed " + str(len(viewers)) + " Viewers\n") # Print # Viewers Grabbed
  81.  
  82. def run_bot():
  83. get_group() # Run get_group to grab IRC channel, server, and port from Twitch group chat API
  84. get_viewers() # Run get_viewers to grab all viewers in a certain channel
  85. con.connect((ip, port)) # Connect to IP:PORT
  86. send_pass(oauth) # Send oauth to server as password
  87. send_nick(username) # Send nickname to server as username
  88. join_channel(ircchan) # Join the IRC channe;
  89. print("Connecting to IRC...\n") # Print connecting to IRC
  90. print("Sending Whispers...") # Print sending whispers
  91. count = 0 # Count is equal to 0, we will use this to count the number of whispers sent
  92. for viewer in viewers: # Loop through array of viewers with each item as viewer
  93. time.sleep(0.5) # Amount of time to wait before each whisper - WARNING! Setting this under 0.5 (half a second) may result in chat flood which will lead to a ban or timeout.
  94. chatmessage = "/w " + viewer + " " + message # Set chatmessage to what we want to send to the IRC channel
  95. if Debug: # If in debug mode, print message instead of sending it
  96. print(chatmessage) # Print chat message
  97. else: # If not debugging, send message to IRC channel
  98. send_message(ircchan, chatmessage) # Send the message to the IRC channel
  99. count = count + 1 # Increase count by 1, this happens for ever message we send. We use this to tally up the total number of whispers sent
  100. print("Done, " + count + " whispers sent.") # Alert user that we are finished, also print number of whispers sent.
  101. part_channel(ircchan) # Leave IRC Channel
  102. #----------------------------------------------End Bot Functions------------------------------------------------------#
  103. run_bot() # Run the main function 'run_bot'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement