Advertisement
Guest User

twitch.lua

a guest
Jun 4th, 2021
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. function split(data, pat)
  2.   local ret = {}
  3.   for i in string.gmatch(data,pat) do
  4.     table.insert(ret,i)
  5.   end
  6. end
  7.  
  8. local nickname = "kayo_mc"
  9. local channel = "#kayochuu"
  10. local host = "irc.chat.twitch.tv"
  11.  
  12. local net = require("internet")
  13. print("Connecting to "..host.."...")
  14. local con, reason = net.open(host, 6667)
  15.  
  16. --If I don't set the timeout, con:read() will return nil
  17. --If I do set the timeout to something like 1s, then it will timeout
  18. --con:setTimeout(1)
  19.  
  20. if not con then
  21.   io.stderr:write(reason.."\n")
  22.   return
  23. end
  24.  
  25.  
  26. local line,png,linesplit,msgfrom = ""
  27. while(true) do
  28.   print("Reading connection...")
  29.   line = con:read()
  30.   print("read connection")
  31.   print(line)
  32.   linesplit = split(line, "[^:]+")
  33.  
  34.   if #linesplit >= 2 and string.find(linesplit[2], "No Indent response") ~= nil then
  35.     print("JOIN")
  36.     con:write("USER " .. nickname .. "0 * :" .. nickname .. "\r\n")
  37.     con:write("NICK " .. nickname .. "\r\n")
  38.     con:write("JOIN :" .. channel .. "\r\n")
  39.   elseif linesplit[1] == "PING" or linesplit[1] == "PING " then
  40.     print("PING")
  41.     png = split(line, "[^:]+")
  42.     con:write("PONG :" .. png[#png] .. "\r\n")
  43.   elseif string.find(linesplit[1], "[^ ]+") ~= nil then
  44.     msgfrom = split(linesplit[1], "[^ ]+")
  45.     msgfrom = msgfrom[3]
  46.   else
  47.     print("no split")
  48.   end
  49. end
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement