Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- #-------------------------------------------------------------------------------#
- Debug = True # This is here for your protection. When debug is True, whispers
- # will be printed to the console rather than sent to the Twitch servers. Read
- # through the code and comments and run in debug mode until you understand how
- # everything works. Once you understand the script, go ahead and change Debug to
- # False. When Debug is false, whispers will actually be sent through the IRC
- # channel and to Twitch. I do not condone spamming or anything of the sort, this
- # script is for educational purposes and is to be used at your own risk. I am not
- # responsible for anything that happens due to the use of this script, therefore
- # I highly recommend running this on a throwaway Twitch account.
- #-------------------------------------------------------------------------------#
- #------Import Modules------#
- import requests
- import time
- import re
- import socket
- import tkinter
- #--------------------------#
- #------------------------------------------Start Settings and Variables-----------------------------------------------#
- username = input("CSGO_Shuffle: ") # Twitch username
- oauth = input("oauth:5b6zy4ep707d933wkf6c5fv8k6swtj: ") # Twitch oauth code - use http://www.twitchapps.com/tmi/ to find
- oauthstripped = oauth.replace('oauth:','') # Strip oauth code down (for use later in group chat API)
- channel = input("KittyPlaysGames: ") # Twitch channel to pull viewer list from
- message = input("Hey: ") # Message to whisper
- viewers = [] # Empty array to hold viewers
- ip = "" # Default value for server IP
- port = 0 # Default value for server port
- ircchan = "irc.twitch.tv" # Default value for IRC channel
- con = socket.socket() # Intiate con
- #------------------------------------------End Settings and Variables-------------------------------------------------#
- #---------------------------------------------Start IRC Functions-----------------------------------------------------#
- def send_message(chan, msg): # Send messages to channel
- con.send(bytes('PRIVMSG %s :%s\r\n' % (chan, msg), 'UTF-8'))
- def send_nick(nick): # Set nick, used for logging in
- con.send(bytes('NICK %s\r\n' % nick, 'UTF-8'))
- def send_pass(password): # Set pass, used for logging in
- con.send(bytes('PASS %s\r\n' % password, 'UTF-8'))
- def join_channel(chan): # Join IRC channel
- con.send(bytes('JOIN %s\r\n' % chan, 'UTF-8'))
- def part_channel(chan): # Leave IRC channel
- con.send(bytes('PART %s\r\n' % chan, 'UTF-8'))
- #----------------------------------------------End IRC Functions------------------------------------------------------#
- #---------------------------------------------Start Bot Functions-----------------------------------------------------#
- def get_group(): # Function to get group chat IRC channel and server
- global ip
- global port
- global ircchan
- r = requests.get("https://chatdepot.twitch.tv/room_memberships?oauth_token=" + oauthstripped) # Load group chat API
- if r.json()["memberships"]: # If content in memberships exists (checking to see if you have a group chat created)
- ircchan = "#" + r.json()["memberships"][0]["room"]["irc_channel"] # Gets and sets IRC channel
- print("\nGrabbed IRC Channel: " + ircchan) # Prints channel grabbed
- fullip = r.json()["memberships"][0]["room"]["servers"][0] # Gets and sets IRC server
- ip,port = re.split(":", fullip) # Splits IRC server into two variables "ip" and "port"
- print("Grabbed Server: " + ip) # Print IRC server IP
- print("Grabbed Port: " + port + "\n") # Print IRC server port
- port = int(port) # Converts port to integer for use in line 73
- else: # If user does not have a group chat, do this
- 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
- print("Checking every 5 seconds...\n") # Tell user we will check every 5 seconds for a group chat
- time.sleep(5) # Wait 5 seconds
- get_group() # Run through get_group function again
- def get_viewers(): # Function to get all viewers in a channel
- r = requests.get("http://tmi.twitch.tv/group/user/" + channel + "/chatters") # Load API
- viewers.extend(r.json()["chatters"]["viewers"]) # Find all viewers and put them in the viewers array
- print("Grabbed " + str(len(viewers)) + " Viewers\n") # Print # Viewers Grabbed
- def run_bot():
- get_group() # Run get_group to grab IRC channel, server, and port from Twitch group chat API
- get_viewers() # Run get_viewers to grab all viewers in a certain channel
- con.connect((ip, port)) # Connect to IP:PORT
- send_pass(oauth) # Send oauth to server as password
- send_nick(username) # Send nickname to server as username
- join_channel(ircchan) # Join the IRC channe;
- print("Connecting to IRC...\n") # Print connecting to IRC
- print("Sending Whispers...") # Print sending whispers
- count = 0 # Count is equal to 0, we will use this to count the number of whispers sent
- for viewer in viewers: # Loop through array of viewers with each item as viewer
- 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.
- chatmessage = "/w " + viewer + " " + message # Set chatmessage to what we want to send to the IRC channel
- if Debug: # If in debug mode, print message instead of sending it
- print(chatmessage) # Print chat message
- else: # If not debugging, send message to IRC channel
- send_message(ircchan, chatmessage) # Send the message to the IRC channel
- 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
- print("Done, " + count + " whispers sent.") # Alert user that we are finished, also print number of whispers sent.
- part_channel(ircchan) # Leave IRC Channel
- #----------------------------------------------End Bot Functions------------------------------------------------------#
- run_bot() # Run the main function 'run_bot'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement