Advertisement
WriteEscape

Untitled

Dec 29th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. API = require("buttonAPI")
  2. local filesystem = require("filesystem")
  3. local component = require("component")
  4. local keyboard = require("keyboard")
  5. local event = require("event")
  6. local gpu = component.gpu
  7.  
  8.     --this is just a basic split function we'll use to split the messages
  9.     function split(data, pat)
  10.         local ret = {}
  11.         for i in string.gmatch(data,pat) do
  12.             table.insert(ret,i)
  13.         end
  14.         return ret
  15.     end
  16.     --config
  17.     local nickname = "derpcraft"
  18.     local channel = "#derpcraft-mc"
  19.      
  20.     local net = require("internet")
  21.     local con = net.open("irc.esper.net",6667) --define server / port here, this will connect to the server
  22.     if(con) then
  23.         local line,png,linesplt,msgfrom = ""
  24.         while(true) do
  25.             line = con:read() --read a line from the socket
  26.             print(line)
  27.             linesplt = split(line,"[^:]+")
  28.             if #linesplt >= 2 and string.find(linesplt[2], "No Ident response") ~= nil then
  29.                 print("JOIN")
  30.                 con:write("USER " .. nickname .. " 0 * :" .. nickname .. "\r\n") --con:write(msg) is used to send messages, con:read() will read a line
  31.                 con:write("NICK " .. nickname .. "\r\n") --for IRC, remember to append the \r\n on the end of all messages
  32.                 con:write("JOIN :" .. channel .. "\r\n")
  33.             elseif linesplt[1] == "PING" or linesplt[1] == "PING " then
  34.                 print("PING")
  35.                 png = split(line,"[^:]+")
  36.                 con:write("PONG :"..png[#png].."\r\n") --respond to pings so we don't get disconnected
  37.             elseif string.find(linesplt[1], "PRIVMSG #") ~= nil then
  38.                 msgfrom = split(linesplt[1],"[^ ]+")
  39.                 msgfrom = msgfrom[3]
  40.                 con:write("PRIVMSG "..msgfrom.." :"..linesplt[2].."\r\n")
  41.             end
  42.         end
  43.     else
  44.         print("Connection failed.")
  45.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement