Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 KB | None | 0 0
  1. # bot.py
  2. import socket
  3. import re
  4. import time
  5. import string
  6.  
  7. HOST = "irc.twitch.tv"              # the Twitch IRC server
  8. PORT = 6667                         # always use port 6667!
  9. NICK = "t_oo"            # your Twitch username, lowercase
  10. PASS = "oauth:ks8p4gtpdtaqot88zfew5hw59c81rx" # your Twitch OAuth token
  11. CHAN = "ishugi"                   # the channel you want to join
  12.  
  13.  
  14. s = socket.socket()
  15. s.connect((HOST, PORT))
  16. s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
  17. s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
  18. s.send("JOIN {}\r\n".format(CHAN).encode("utf-8"))
  19.  
  20. def initial(s):
  21.     readbuffer = ""
  22.     Loading = True
  23.     while Loading:
  24.         readbuffer = readbuffer + (s.recv(1024)).decode("utf-8")
  25.         temp = readbuffer.splitlines()
  26.         readbuffer = temp.pop()
  27.         for line in temp:
  28.             print(line)
  29.             Loading = loadingComplete(line)
  30.     ##sendMessage(s, "Connection successful. VoHiYo")
  31.     print("connected")
  32.  
  33. def loadingComplete(line):
  34.     if(">" in line):
  35.         return False
  36.     else:
  37.         return True
  38.        
  39. def sendMessage(s, message):
  40.     messageTemp = "PRIVMSG #" + CHAN + " :" + message
  41.     s.send((messageTemp + "\r\n").encode("utf-8"))
  42.     print("Sent: " + messageTemp)
  43.    
  44. def getMessage(line):
  45.     print("getMessage")
  46.     separate = line.split(":", 2)
  47.     message = separate[2]
  48.     return message
  49.    
  50. def getUser(line):
  51.     print("getUser")
  52.     separate = line.split(":", 2)
  53.     user = separate[1].split("!", 1)[0]
  54.     return user
  55.    
  56. initial(s)
  57.        
  58. readbuffer = ""
  59. while True:
  60.     readbuffer = readbuffer + (s.recv(1024).decode("utf-8"))
  61.     temp = readbuffer.splitlines()
  62.     print(temp)
  63.     readbuffer = temp.pop()
  64.     print(readbuffer)
  65.     for line in temp:
  66.         print(line)
  67.         if "PING :tmi.twitch.tv" in line:
  68.             s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
  69.             print("PONG")      
  70.         user = getUser(line)
  71.         message = getMessage(line)
  72.         print (user + " typed :" + message)
  73.         if "hello justin" in message:
  74.             s.send("Hey there fam")
  75.             break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement