Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function split(data, pat)
- local ret = {}
- for i in string.gmatch(data,pat) do
- table.insert(ret,i)
- end
- end
- local nickname = "kayo_mc"
- local channel = "#kayochuu"
- local host = "irc.chat.twitch.tv"
- local net = require("internet")
- print("Connecting to "..host.."...")
- local con, reason = net.open(host, 6667)
- --If I don't set the timeout, con:read() will return nil
- --If I do set the timeout to something like 1s, then it will timeout
- --con:setTimeout(1)
- if not con then
- io.stderr:write(reason.."\n")
- return
- end
- local line,png,linesplit,msgfrom = ""
- while(true) do
- print("Reading connection...")
- line = con:read()
- print("read connection")
- print(line)
- linesplit = split(line, "[^:]+")
- if #linesplit >= 2 and string.find(linesplit[2], "No Indent response") ~= nil then
- print("JOIN")
- con:write("USER " .. nickname .. "0 * :" .. nickname .. "\r\n")
- con:write("NICK " .. nickname .. "\r\n")
- con:write("JOIN :" .. channel .. "\r\n")
- elseif linesplit[1] == "PING" or linesplit[1] == "PING " then
- print("PING")
- png = split(line, "[^:]+")
- con:write("PONG :" .. png[#png] .. "\r\n")
- elseif string.find(linesplit[1], "[^ ]+") ~= nil then
- msgfrom = split(linesplit[1], "[^ ]+")
- msgfrom = msgfrom[3]
- else
- print("no split")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement