Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Twitch chat display
- local serverhost = "irc.chat.twitch.tv" -- Server to connect to
- local serverport = 6667 -- Server port
- local serveruser = "username" -- Server username
- local serverpass = "oauth:xxxxxxxxxxxxxxxxxxxxxx" -- Twitch oauth token
- local serverchan = "#channel"
- print("Starting...")
- function split(data, pat)
- local ret = {}
- for i in string.gmatch(data,pat) do
- table.insert(ret,i)
- end
- return ret
- end
- print("Starting connection...")
- local event = require("event")
- local net = require("internet")
- local con = net.open(serverhost, serverport)
- print("Testing connection...")
- if(con) then
- print("Connected!")
- local line,png,linesplit,msgfrom = ""
- local running = true
- con:write("PASS " .. serverpass .. "\r\n")
- con:write("NICK " .. serveruser .. "\r\n")
- con:write("JOIN " .. serverchan .. "\r\n")
- print("Joined " .. serverchan)
- function exitProgram()
- running = false
- end
- while(running) do
- event.listen("interrupted", exitProgram)
- line = con:read()
- -- print(line)
- linesplit = split(line, "[^:]+")
- if linesplit[1] == "PING" or linesplit[1] == "PING " then
- png = split(line,"[^:]+")
- con:write("PONG :" .. png[#png] .. "\r\n")
- elseif string.find(linesplit[1], "PRIVMSG #") ~= nil then
- msgfrom = split(linesplit[1], "[^!]+")
- msgfrom = msgfrom[1]
- print(msgfrom .. ": " .. linesplit[2])
- end
- end
- else
- print("Connection failed.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement