From ca311aef1ed8fbce0552b42b7135f7a134f5e960 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Jan 2016 01:35:19 +1100 Subject: [PATCH] Rewrote the parser, added timeouts --- config.lua | 1 + init.lua | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/config.lua b/config.lua index d16b76a..574af1d 100644 --- a/config.lua +++ b/config.lua @@ -23,5 +23,6 @@ autojoin=true, prefix=":", username="yuki", port=6667, +timeout=300, admins={"ShadowKatStudios","XeonSquared"} } diff --git a/init.lua b/init.lua index ad0dbb4..3664a1c 100644 --- a/init.lua +++ b/init.lua @@ -167,11 +167,22 @@ function parse(line) print("Pinged: "..pingid) elseif string.find(line,":") == 1 and string.find(line,"PRIVMSG") ~= nil and string.find(line,"005") == nil then local s = string.sub(line,2) -- I - local nick,s = string.match(s,"([^,]+)!([^,]+)") -- am - local _,s = string.match(s,"([^,]+) PRIVMSG ([^,]+)") -- a - local chan, msg = string.match(s,"([^,]+) :([^,]+)") -- terrible + local ms,me = string.find(s,"!") -- me = match end, ms = match start + local nick = string.sub(s,1,ms-1) + s=string.sub(s,me+1) + local ms,me = string.find(s," PRIVMSG ") + s=string.sub(s,me+1) + local ms,me = string.find(s," :") + local chan = string.sub(s,1,ms-1) + local msg = string.sub(s,me+1) + --[[ + -- old parser, kept for hysterical rasins + local nick,s = string.match(s,"([^,]+)!([^\n]+)") -- am + local _,s = string.match(s,"([^,]+) PRIVMSG ([^\n]+)") -- a + local chan, msg = string.match(s,"([^,]+) :([^\n]+)") -- terrible if chan == config.nick then chan = nick end - print(nick .. " " .. chan .. " " .. msg) --person + ]]-- + print(nick,chan,msg) --person parsemsg(nick,chan,msg) end end @@ -199,7 +210,8 @@ function main() local _,pingid = string.match(line,"([^,]+):([^,]+)") writeln("PONG :"..pingid) print("Pinged: "..pingid) - end + _G.lastping = os.time() + end if line ~= "" then print(line) end @@ -211,11 +223,15 @@ function main() connection:send("JOIN " .. v.."\n") end end + _G.lastping = os.time() repeat line = connection:receive() if line ~= nil and line ~= "timeout" then print(line) pcall(parse,line) + elseif line == "timeout" and os.time() > _G.lastping + config.timeout then + print("Connection to IRC timed out, aborting.") + break end for k,v in ipairs(timers) do local fail, errors = pcall(v,line)