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:xxxxxxxxxxxxxxxxxxxxxxxx" -- Twitch oauth token (http://twitchapps.com/tmi/)
- local term = require("term")
- local fs = require("filesystem")
- local net = require("internet")
- print("Starting...")
- function getAuth()
- print("No auth file found! Please visit http://twitchapps.com/tmi/.")
- print("Once you've logged in, please input the entire string you received (including the beginning 'oauth:')")
- local oauth = term.read()
- net.request("https://api.twitch.tv/kraken/user", nil, { Authorization = "OAuth " .. oauth:sub(7) })
- end
- print("Which channel should be joined?")
- local serverchan = term.read()
- if serverchan:sub(1,1) ~= "#" then
- serverchan = "#" .. serverchan
- end
- 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 con = net.open(serverhost, serverport)
- local serialization = require("serialization")
- local keyboard = require("keyboard")
- local keys = keyboard.keys
- local component = require("component")
- local gpu = component.getPrimary("gpu")
- local keyPressed
- print("Testing connection...")
- function getKeyPress()
- local _, _, _, keycode = event.pull(1/20, "key_down")
- return keys[keycode]
- end
- 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(true) do
- local id, _, _, _ = event.pull(0.2, "interrupted")
- if id == "interrupted" then
- break
- end
- 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]
- msg = linesplit
- msg[0], msg[1] = nil, nil
- print(msgfrom .. ": " .. linesplit[2])
- elseif linesplit[1] == "NOTICE" or linesplit[1] == "NOTICE " then
- if linesplit[2] == "Login authentication failed" then
- print("Invalid login information. Exiting.")
- end
- end
- end
- else
- print("Connection failed.")
- end
- print("Goodbye!")
- os.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement