Advertisement
Guest User

Untitled

a guest
Jan 30th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.34 KB | None | 0 0
  1. import socket, string
  2. import time
  3. # Set all the variables necessary to connect to Twitch IRC
  4. HOST = b"irc.chat.twitch.tv"
  5. NICK = b"..."
  6. PASS = b"..."  #тут oauth токен
  7. PORT = 6667
  8. channel = b'...'
  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(b"PASS " + PASS + b"\r\n")
  16. s.send(b"NICK " + NICK + b"\r\n")
  17. s.send(b'JOIN #' + channel + b' \r\n')
  18.  
  19. # Method for sending a message
  20. def Send_message(message):
  21.     print(message)
  22.     s.send(b'PRIVMSG #' + channel + b' :' + message.encode('utf-8') + b'\r\n')
  23.  
  24. while True:
  25.     if MODT == False:
  26.         readbuffer = readbuffer + s.recv(1024).decode('utf-8')
  27.         temp = readbuffer.split("\n")
  28.         readbuffer = temp.pop()
  29.         #print(temp)
  30.         for line in temp:
  31.            
  32.             print(line)
  33.             # Checks whether the message is PING because its a method of Twitch to check if you're afk
  34.             if (line[0] == "PING"):
  35.                 s.send(b'PONG ' + line[1].encode('utf-8') + b'\r\n')
  36.             else:
  37.                 # Splits the given string so we can work with it better
  38.                 parts = line.split(":")
  39.                 if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]:
  40.                     try:
  41.                         # Sets the message variable to the actual message sent
  42.                         message = parts[2][:len(parts[2]) - 1]
  43.                     except:
  44.                         message = ""
  45.                     # Sets the username variable to the actual username
  46.                     usernamesplit = parts[1].split("!")
  47.                     username = usernamesplit[0]
  48.      
  49.                     # Only works after twitch is done announcing stuff (MODT = Message of the day)
  50.                     if MODT:
  51.                         print (username + ": " + message)
  52.                         # You can add all your plain commands here
  53.                         if message.startswith('!sosihui'):
  54.                             Send_message('uuh blya uuh sam sosi!!!!')
  55.                     for l in parts:
  56.                         if "End of /NAMES list" in l:
  57.                             MODT = True
  58.     else:
  59.         Send_message(z)
  60.         time.sleep(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement