Advertisement
Guest User

Untitled

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