Advertisement
Guest User

Untitled

a guest
Feb 24th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. from __future__ import division
  2. import socket, re, time
  3.  
  4.  
  5. HOST = "irc.twitch.tv"
  6. PORT = 6667
  7. NICK = "##########"
  8. PASS = "oauth:##############################"
  9. CHAN = "##########"
  10. RATE = (20/30)
  11.  
  12. s = socket.socket()
  13. s.connect((HOST, PORT))
  14. s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
  15. s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
  16. s.send("JOIN {}\r\n".format(CHAN).encode("utf-8"))
  17. CHAT_MSG=re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
  18.  
  19. while True:
  20.     response = s.recv(1024).decode("utf-8")
  21.     if response == "PING :tmi.twitch.tv\r\n":
  22.         s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
  23.     else:
  24.         username = re.search(r"\w+", response).group(0)
  25.         message = CHAT_MSG.sub("", response)
  26.         print(username + ": " + message)
  27.        
  28.         if username == "hey":
  29.             print "Sent!"
  30.             s.send('PRIVMSG '+CHAN+' :' + "Welcome to the Stream!" + '\r\n')
  31.            
  32.     time.sleep(1 / RATE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement