From 8a2f3801468634f98f4490c443d51da46d389391 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Tue, 12 Jan 2016 03:58:29 +1100 Subject: [PATCH] Moved high-five module outside of main script, added method to extend. --- config.lua | 25 +++++++++++- hooks/.highfive.lua.swp | Bin 0 -> 12288 bytes hooks/highfive.lua | 21 ++++++++++ init.lua | 84 ++++++++++++++++++++++++++++------------ timers/highfive.lua | 6 +++ 5 files changed, 111 insertions(+), 25 deletions(-) create mode 100644 hooks/.highfive.lua.swp create mode 100644 hooks/highfive.lua create mode 100644 timers/highfive.lua diff --git a/config.lua b/config.lua index 3ce8572..1048dc8 100644 --- a/config.lua +++ b/config.lua @@ -1 +1,24 @@ -{server="irc.esper.net",nick="yukichan",hostname="lain",servername="lain",realname="yuki",channels={"#SKSDev","#v","#ssss"},prefix=":",username="yuki",port=6667,admins={"ShadowKatStudios"}} +{server="irc.quakenet.org", +nick="yukichan", +hostname="lain", +servername="lain", +realname="yuki", +channels={ + "#SKSDev", + "#v", + "#ssss" +}, +hooks={ +"highfive.lua" +}, +cmds={ +}, +timers={ +"highfive.lua" +}, +autojoin=true, +prefix=":", +username="yuki", +port=6667, +admins={"ShadowKatStudios","XeonSquared"} +} diff --git a/hooks/.highfive.lua.swp b/hooks/.highfive.lua.swp new file mode 100644 index 0000000000000000000000000000000000000000..5c67f3d2a463ccc460945729712109e0dba0dd15 GIT binary patch literal 12288 zcmeI2F>ljA6vtl~m?%X>Yz&XNfC(@GCUBw&6vG90 zP8FW2s=QG33kUk@k~=2A1egF5U;<2l2`~XBzyz286JP>N;6Egw`T*b006bo##nb=) zv+w^OO8_58FG=@F>!fAUx3d5rNv}ySNK?{H(nZoQit&Z?ne>VDp7f6NmgM3a5;rEm z1egF5U;<2l2`~XBzyz4Ui6memq~D&-a~13Bk+J=T$Xa+AcXl$-#QhMhNwG+@#YeYg zs-t2<+1S_^Lwwc_Fj8r*r>JcoocsXiT1zK6=mEgWh{KVwMMK=pFwJbNN9a-@9ldrr zq-c`!&}cp!RZw5tcBhMBh{b5E{o3b8$#PkkJ>6&q&KS4@-$5}M>U+@!9r(UQ2fnB7 zL0=d3^(m@fI7ZGfhhUwZGo@Ki5y@KokXZW&9s@S4=?zdyQKNvWKq2Ly)jB5ss@OxW zN+yqwNAFNPNV48wBFdRVmz#|a?1sNK0+jE}#V(muyC?A32>UEs6Uv&s6FuHpY@%1( Z7{&SaYBwkco!MZm3;vGVU{cB{{00q+1bqMi literal 0 HcmV?d00001 diff --git a/hooks/highfive.lua b/hooks/highfive.lua new file mode 100644 index 0000000..2b356fc --- /dev/null +++ b/hooks/highfive.lua @@ -0,0 +1,21 @@ +tArgs = {...} +local nick, chan, message = tArgs[1],tArgs[2],tArgs[3] +print(nick,chan,message,nick == "Shocky") +if message:find("o/") ~= nil or message:find("\\o") ~= nil then + if nick ~= "Shocky" then + if _G.leftHanging[2] == false then + print (nick .." left hanging at "..os.time()) + local typeOfHighFive="o/" + if message:find("o/") ~= nil then + typeOfHighFive = "\\o" + end + _G.leftHanging = {os.time(),true,chan,typeOfHighFive} + elseif _G.leftHanging[2] == true then + _G.leftHanging = {0,false} + print("No longer left hanging.") + end + else + _G.leftHanging = {0,false} + end +end +if message:find("o/ * \\o") ~= nil then _G.leftHanging = {0, false} end diff --git a/init.lua b/init.lua index e24fbdb..5ebeaba 100644 --- a/init.lua +++ b/init.lua @@ -1,8 +1,10 @@ local socket = require "socket" local serialization = require "serialization" -local config = {} -local cmds={} +config = {} +cmds = {} +hooks = {} +timers = {} function loadconfig() local f = io.open("./config.lua","rb") @@ -10,6 +12,47 @@ function loadconfig() f:close() print(content) config = serialization.unserialize(content) + hooks = {} + for k,v in pairs(config.hooks) do + print("Loading hook "..v) + local fo=io.open("./hooks/" .. v) + local c = fo:read("*a") + local s,f = pcall(load,c) + fo:close() + if s then + table.insert(hooks,f) + print("Hook "..v.." loaded") + else + print("Hook "..v.." failed to load:") + print(f) + end + end + cmds = {} + for k,v in pairs(config.cmds) do + local fo=io.open("./cmds/" .. v) + local s,f = pcall(load,fo:read("*a")) + fo:close() + if s then + table.insert(cmds,f) + print("Command "..v.." loaded") + else + print("Command "..v.." failed to load:") + print(f) + end + end + timers = {} + for k,v in pairs(config.timers) do + local fo=io.open("./timers/" .. v) + local s,f = pcall(load,fo:read("*a")) + fo:close() + if s then + table.insert(timers,f) + print("Timer "..v.." loaded") + else + print("Timer "..v.."Failed to load:") + print(f) + end + end end function saveconfig() @@ -62,21 +105,10 @@ end leftHanging = {0,false} function parsemsg(nick,chan,message) - if message:find("o/") ~= nil or message:find("\\o") ~= nil and nick ~= "Shocky" and nick ~= "yukichan" then - if leftHanging[2] == false then - print (nick .." left hanging at "..os.time()) - local typeOfHighFive="o/" - if message:find("o/") ~= nil then - typeOfHighFive = "\\o" - end - leftHanging = {os.time(),true,chan,typeOfHighFive} - elseif leftHanging[2] == true then - leftHanging = {0,false} - print("No longer left hanging.") - end + for k,v in ipairs(hooks) do + v(nick,chan,message) end - if message:find("o/ * \\o") ~= nil and nick == "Shocky" then leftHanging = {0, false} end - if string.find(message,":") == 1 then + if string.find(message,config.prefix) == 1 then local command = message:sub(2) .. " " if command == "" then return end local tCommand = {} @@ -99,6 +131,8 @@ function parsemsg(nick,chan,message) if checkAdmin(nick) then writeln(command:sub(9)) end + elseif tCommand[1] == "drop" then + leftHanging = {0, false} elseif tCommand[1] == "join" then writeln("JOIN "..tCommand[2]) elseif tCommand[1] == "lua" then @@ -149,7 +183,7 @@ function main() function writeln(l) connection:send(l.."\n") end function sendchan(chan,msg) writeln("PRIVMSG "..chan.." :"..msg) end function readln() return connection:receive() end - connection:settimeout(2) + connection:settimeout(1) print("Connected!") os.sleep(1) connection:receive() -- drop a line @@ -163,12 +197,16 @@ function main() writeln("PONG :"..pingid) print("Pinged: "..pingid) end - print(line) + if line ~= "" then + print(line) + end until string.match(line or "","%+i") ~= nil os.sleep(2) print("Sent everything relevant. Joining channels.") - for k,v in pairs(config.channels) do - connection:send("JOIN " .. v.."\n") + if config.autojoin then + for k,v in pairs(config.channels) do + connection:send("JOIN " .. v.."\n") + end end repeat line = connection:receive() @@ -176,10 +214,8 @@ function main() print(line) pcall(parse,line) end - if os.time() > leftHanging[1]+3 and leftHanging[2] then - print ("Responding to a hanging high-five at "..leftHanging[1]) - sendchan(leftHanging[3],leftHanging[4] or "\\o") - leftHanging={0,false} + for k,v in ipairs(timers) do + v(line) end if line == nil then line = "" end until string.find(line,"ERROR :Closing link:") ~= nil diff --git a/timers/highfive.lua b/timers/highfive.lua new file mode 100644 index 0000000..458d6f2 --- /dev/null +++ b/timers/highfive.lua @@ -0,0 +1,6 @@ +local os = require "os" +if os.time() > _G.leftHanging[1]+3 and _G.leftHanging[2] then + print ("Responding to a hanging high-five at ".._G.leftHanging[1]) + sendchan(_G.leftHanging[3],_G.leftHanging[4] or "\\o") + _G.leftHanging={0,false} +end