Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # bot.py
- import socket
- import re
- import time
- import string
- HOST = "irc.twitch.tv" # the Twitch IRC server
- PORT = 6667 # always use port 6667!
- NICK = "t_oo" # your Twitch username, lowercase
- PASS = "oauth:ks8p4gtpdtaqot88zfew5hw59c81rx" # your Twitch OAuth token
- CHAN = "ishugi" # the channel you want to join
- s = socket.socket()
- s.connect((HOST, PORT))
- s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
- s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
- s.send("JOIN {}\r\n".format(CHAN).encode("utf-8"))
- def initial(s):
- readbuffer = ""
- Loading = True
- while Loading:
- readbuffer = readbuffer + (s.recv(1024)).decode("utf-8")
- temp = readbuffer.splitlines()
- readbuffer = temp.pop()
- for line in temp:
- print(line)
- Loading = loadingComplete(line)
- ##sendMessage(s, "Connection successful. VoHiYo")
- print("connected")
- def loadingComplete(line):
- if(">" in line):
- return False
- else:
- return True
- def sendMessage(s, message):
- messageTemp = "PRIVMSG #" + CHAN + " :" + message
- s.send((messageTemp + "\r\n").encode("utf-8"))
- print("Sent: " + messageTemp)
- def getMessage(line):
- print("getMessage")
- separate = line.split(":", 2)
- message = separate[2]
- return message
- def getUser(line):
- print("getUser")
- separate = line.split(":", 2)
- user = separate[1].split("!", 1)[0]
- return user
- initial(s)
- readbuffer = ""
- while True:
- readbuffer = readbuffer + (s.recv(1024).decode("utf-8"))
- temp = readbuffer.splitlines()
- print(temp)
- readbuffer = temp.pop()
- print(readbuffer)
- for line in temp:
- print(line)
- if "PING :tmi.twitch.tv" in line:
- s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
- print("PONG")
- user = getUser(line)
- message = getMessage(line)
- print (user + " typed :" + message)
- if "hello justin" in message:
- s.send("Hey there fam")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement