From 727ad2204d875f5788149877b65a1ab1cb932c51 Mon Sep 17 00:00:00 2001 From: Izaya Date: Wed, 3 May 2017 21:58:59 +1000 Subject: [PATCH] Added a really terrible IRC client. --- modules/applications/ircclient.lua | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 modules/applications/ircclient.lua diff --git a/modules/applications/ircclient.lua b/modules/applications/ircclient.lua new file mode 100644 index 0000000..81054f3 --- /dev/null +++ b/modules/applications/ircclient.lua @@ -0,0 +1,46 @@ +function irc(h,p,n) -- host, port, nick + s("IRC client:"..tostring(h), function() print(pcall(function() + local ip,h,p = component.proxy(component.list("internet")()),h,p + local c=ip.connect(h,p) + print("Nick: "..n) + print("Connected: "..tostring(c.finishConnect())) + if c.finishConnect() then + local ct=computer.uptime() + print("Connected successfully.") + local function wl(s) + print("-->| "..tostring(s).."\n") + c.write(tostring(s).."\n") + end + _G.wil = wl + function _G.sc(u,s) wl("PRIVMSG "..tostring(u).." :"..tostring(s)) end + local function prs(line) + h,m = string.match(line,":?(.-):(.+)") tH = {} + for w in h:gmatch("%S+") do tH[#tH+1] = w end + if tH[1] == "PING" then + wl("PONG :"..m) + elseif tH[2] == "PRIVMSG" then + local n,r,h = tH[1]:match("(.+)!(.+)@(.+)") + print(n..":"..m.."\n") + else + print("|<-- "..line.."\n") + end + end + wl("NICK "..n) + wl("USER "..n.." "..n.." "..n.." "..n) + while c.finishConnect() do + coroutine.yield() + local d=c.read() + if type(d) == "string" then + if d ~= "" and d ~= "\n" then + for line in d:gmatch("[^\r\n]+") do + pcall(prs,line) + end + end + end + end + else + print("Failed to connect:") + print(c.finishConnect()) + end + end)) end) +end