SHOW:
|
|
- or go back to the newest paste.
| 1 | - | import socket, string |
| 1 | + | import socket, string |
| 2 | - | |
| 2 | + | |
| 3 | - | # Set all the variables necessary to connect to Twitch IRC |
| 3 | + | # Set all the variables necessary to connect to Twitch IRC |
| 4 | - | HOST = "irc.twitch.tv" |
| 4 | + | HOST = "irc.twitch.tv" |
| 5 | - | NICK = "BOTSNICKNAME" |
| 5 | + | NICK = "BOTSNICKNAME" |
| 6 | - | PORT = 6667 |
| 6 | + | PORT = 6667 |
| 7 | - | PASS = "oauth:YOUROAUTHKEYHERE" |
| 7 | + | PASS = "oauth:13370" |
| 8 | - | readbuffer = "" |
| 8 | + | readbuffer = "" |
| 9 | - | MODT = False |
| 9 | + | MODT = False |
| 10 | - | |
| 10 | + | |
| 11 | - | # Connecting to Twitch IRC by passing credentials and joining a certain channel |
| 11 | + | # Connecting to Twitch IRC by passing credentials and joining a certain channel |
| 12 | - | s = socket.socket() |
| 12 | + | s = socket.socket() |
| 13 | - | s.connect((HOST, PORT)) |
| 13 | + | s.connect((HOST, PORT)) |
| 14 | - | s.send("PASS " + PASS + "\r\n") |
| 14 | + | s.send("PASS " + PASS + "\r\n")
|
| 15 | - | s.send("NICK " + NICK + "\r\n") |
| 15 | + | s.send("NICK " + NICK + "\r\n")
|
| 16 | - | s.send("JOIN #YOURCHANNELNAME \r\n") |
| 16 | + | s.send("JOIN #Kickz \r\n")
|
| 17 | - | |
| 17 | + | |
| 18 | - | # Method for sending a message |
| 18 | + | # Method for sending a message |
| 19 | - | def Send_message(message): |
| 19 | + | def Send_message(message): |
| 20 | - | s.send("PRIVMSG #YOURCHANNELNAME :" + message + "\r\n") |
| 20 | + | s.send("PRIVMSG #YOURCHANNELNAME :" + message + "\r\n")
|
| 21 | - | |
| 21 | + | |
| 22 | - | |
| 22 | + | |
| 23 | - | while True: |
| 23 | + | while True: |
| 24 | - | readbuffer = readbuffer + s.recv(1024) |
| 24 | + | readbuffer = readbuffer + s.recv(1024) |
| 25 | - | temp = string.split(readbuffer, "\n") |
| 25 | + | temp = string.split(readbuffer, "\n") |
| 26 | - | readbuffer = temp.pop() |
| 26 | + | readbuffer = temp.pop() |
| 27 | - | |
| 27 | + | |
| 28 | - | for line in temp: |
| 28 | + | for line in temp: |
| 29 | - | # Checks whether the message is PING because its a method of Twitch to check if you're afk |
| 29 | + | # Checks whether the message is PING because its a method of Twitch to check if you're afk |
| 30 | - | if (line[0] == "PING"): |
| 30 | + | if (line[0] == "PING"): |
| 31 | - | s.send("PONG %s\r\n" % line[1]) |
| 31 | + | s.send("PONG %s\r\n" % line[1])
|
| 32 | - | else: |
| 32 | + | else: |
| 33 | - | # Splits the given string so we can work with it better |
| 33 | + | # Splits the given string so we can work with it better |
| 34 | - | parts = string.split(line, ":") |
| 34 | + | parts = string.split(line, ":") |
| 35 | - | |
| 35 | + | |
| 36 | - | if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]: |
| 36 | + | if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]: |
| 37 | - | try: |
| 37 | + | try: |
| 38 | - | # Sets the message variable to the actual message sent |
| 38 | + | # Sets the message variable to the actual message sent |
| 39 | - | message = parts[2][:len(parts[2]) - 1] |
| 39 | + | message = parts[2][:len(parts[2]) - 1] |
| 40 | - | except: |
| 40 | + | except: |
| 41 | - | message = "" |
| 41 | + | message = "" |
| 42 | - | # Sets the username variable to the actual username |
| 42 | + | # Sets the username variable to the actual username |
| 43 | - | usernamesplit = string.split(parts[1], "!") |
| 43 | + | usernamesplit = string.split(parts[1], "!") |
| 44 | - | username = usernamesplit[0] |
| 44 | + | username = usernamesplit[0] |
| 45 | - | |
| 45 | + | |
| 46 | - | # Only works after twitch is done announcing stuff (MODT = Message of the day) |
| 46 | + | # Only works after twitch is done announcing stuff (MODT = Message of the day) |
| 47 | - | if MODT: |
| 47 | + | if MODT: |
| 48 | - | print username + ": " + message |
| 48 | + | print username + ": " + message |
| 49 | - | |
| 49 | + | |
| 50 | - | # You can add all your plain commands here |
| 50 | + | # You can add all your plain commands here |
| 51 | - | if message == "Hey": |
| 51 | + | if message == "Hey": |
| 52 | - | Send_message("Welcome to my stream, " + username) |
| 52 | + | Send_message("Welcome to my stream, " + username)
|
| 53 | - | |
| 53 | + | |
| 54 | - | for l in parts: |
| 54 | + | for l in parts: |
| 55 | - | if "End of /NAMES list" in l: |
| 55 | + | if "End of /NAMES list" in l: |
| 56 | MODT = True |