Moved high-five module outside of main script, added method to extend.

This commit is contained in:
Izaya 2016-01-12 03:58:29 +11:00
parent b70d0eaa20
commit 8a2f380146
5 changed files with 111 additions and 25 deletions

View File

@ -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"}
}

BIN
hooks/.highfive.lua.swp Normal file

Binary file not shown.

21
hooks/highfive.lua Normal file
View File

@ -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

View File

@ -1,8 +1,10 @@
local socket = require "socket" local socket = require "socket"
local serialization = require "serialization" local serialization = require "serialization"
local config = {} config = {}
local cmds={} cmds = {}
hooks = {}
timers = {}
function loadconfig() function loadconfig()
local f = io.open("./config.lua","rb") local f = io.open("./config.lua","rb")
@ -10,6 +12,47 @@ function loadconfig()
f:close() f:close()
print(content) print(content)
config = serialization.unserialize(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 end
function saveconfig() function saveconfig()
@ -62,21 +105,10 @@ end
leftHanging = {0,false} leftHanging = {0,false}
function parsemsg(nick,chan,message) function parsemsg(nick,chan,message)
if message:find("o/") ~= nil or message:find("\\o") ~= nil and nick ~= "Shocky" and nick ~= "yukichan" then for k,v in ipairs(hooks) do
if leftHanging[2] == false then v(nick,chan,message)
print (nick .." left hanging at "..os.time())
local typeOfHighFive="o/"
if message:find("o/") ~= nil then
typeOfHighFive = "\\o"
end end
leftHanging = {os.time(),true,chan,typeOfHighFive} if string.find(message,config.prefix) == 1 then
elseif leftHanging[2] == true then
leftHanging = {0,false}
print("No longer left hanging.")
end
end
if message:find("o/ * \\o") ~= nil and nick == "Shocky" then leftHanging = {0, false} end
if string.find(message,":") == 1 then
local command = message:sub(2) .. " " local command = message:sub(2) .. " "
if command == "" then return end if command == "" then return end
local tCommand = {} local tCommand = {}
@ -99,6 +131,8 @@ function parsemsg(nick,chan,message)
if checkAdmin(nick) then if checkAdmin(nick) then
writeln(command:sub(9)) writeln(command:sub(9))
end end
elseif tCommand[1] == "drop" then
leftHanging = {0, false}
elseif tCommand[1] == "join" then elseif tCommand[1] == "join" then
writeln("JOIN "..tCommand[2]) writeln("JOIN "..tCommand[2])
elseif tCommand[1] == "lua" then elseif tCommand[1] == "lua" then
@ -149,7 +183,7 @@ function main()
function writeln(l) connection:send(l.."\n") end function writeln(l) connection:send(l.."\n") end
function sendchan(chan,msg) writeln("PRIVMSG "..chan.." :"..msg) end function sendchan(chan,msg) writeln("PRIVMSG "..chan.." :"..msg) end
function readln() return connection:receive() end function readln() return connection:receive() end
connection:settimeout(2) connection:settimeout(1)
print("Connected!") print("Connected!")
os.sleep(1) os.sleep(1)
connection:receive() -- drop a line connection:receive() -- drop a line
@ -163,23 +197,25 @@ function main()
writeln("PONG :"..pingid) writeln("PONG :"..pingid)
print("Pinged: "..pingid) print("Pinged: "..pingid)
end end
if line ~= "" then
print(line) print(line)
end
until string.match(line or "","%+i") ~= nil until string.match(line or "","%+i") ~= nil
os.sleep(2) os.sleep(2)
print("Sent everything relevant. Joining channels.") print("Sent everything relevant. Joining channels.")
if config.autojoin then
for k,v in pairs(config.channels) do for k,v in pairs(config.channels) do
connection:send("JOIN " .. v.."\n") connection:send("JOIN " .. v.."\n")
end end
end
repeat repeat
line = connection:receive() line = connection:receive()
if line ~= nil and line ~= "timeout" then if line ~= nil and line ~= "timeout" then
print(line) print(line)
pcall(parse,line) pcall(parse,line)
end end
if os.time() > leftHanging[1]+3 and leftHanging[2] then for k,v in ipairs(timers) do
print ("Responding to a hanging high-five at "..leftHanging[1]) v(line)
sendchan(leftHanging[3],leftHanging[4] or "\\o")
leftHanging={0,false}
end end
if line == nil then line = "" end if line == nil then line = "" end
until string.find(line,"ERROR :Closing link:") ~= nil until string.find(line,"ERROR :Closing link:") ~= nil

6
timers/highfive.lua Normal file
View File

@ -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