Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Dillon Cain
- ; dcain
- import socket
- import threading
- SERVER = "irc.twitch.tv"
- PORT = 6667
- PASS = "oauth:fill in here"
- BOT = "TwitchBot"
- CHANNEL = "channel name here"
- OWNER = "channel name here"
- message = ""
- irc = socket.socket()
- irc.connect((SERVER, PORT))
- irc.send(( "PASS " + PASS + "\n"
- "NICK " + BOT + "\n" +
- "JOIN #" + CHANNEL + "\n").encode())
- def twitch():
- def joinchat():
- Loading = True
- while Loading:
- readbuffer_join = irc.recv(1024)
- readbuffer_join = readbuffer_join.decode()
- for line in readbuffer_join.split("\n")[0:-1]:
- print(line)
- Loading = loadingComplete(line)
- def loadingComplete(line):
- if ("End of /NAMES list" in line):
- print("Bot has joined " + CHANNEL + "'s Channel!")
- return False
- else:
- return True
- def sendMessage(irc, message):
- messageTemp = "PRIVMSG #" + CHANNEL + " :" + message
- irc.send((messageTemp + "\n").encode())
- def getUser(line):
- seperate = line.split(":", 2)
- user = seperate[1].split("!" , 1)[0]
- return user
- def getMessage(line):
- global message
- try:
- message = (line.split(":",2))[2]
- except:
- message = ""
- return message
- def Console(line):
- if "PRIVMSG" in line:
- return False
- else:
- return True
- joinchat()
- while True:
- try:
- readbuffer = irc.recv(1024).decode()
- except:
- readbuffer = ""
- for line in readbuffer.split("\r\n"):
- if line == "":
- continue
- elif "PING" in line and Console(line):
- msgg = "PONG tmi.twitch.tv\r\n".encode()
- irc.send(msgg)
- print(msgg)
- continue
- else:
- print(line)
- user = getUser(line)
- message = getMessage(line)
- print(user + " : " + message)
- if __name__ =='__main__':
- t1 = threading.Thread(target = twitch)
- t1. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement