Moved high-five module outside of main script, added method to extend.
This commit is contained in:
parent
b70d0eaa20
commit
8a2f380146
25
config.lua
25
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"}
|
||||
}
|
||||
|
BIN
hooks/.highfive.lua.swp
Normal file
BIN
hooks/.highfive.lua.swp
Normal file
Binary file not shown.
21
hooks/highfive.lua
Normal file
21
hooks/highfive.lua
Normal 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
|
78
init.lua
78
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"
|
||||
for k,v in ipairs(hooks) do
|
||||
v(nick,chan,message)
|
||||
end
|
||||
leftHanging = {os.time(),true,chan,typeOfHighFive}
|
||||
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
|
||||
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,23 +197,25 @@ function main()
|
||||
writeln("PONG :"..pingid)
|
||||
print("Pinged: "..pingid)
|
||||
end
|
||||
if line ~= "" then
|
||||
print(line)
|
||||
end
|
||||
until string.match(line or "","%+i") ~= nil
|
||||
os.sleep(2)
|
||||
print("Sent everything relevant. Joining channels.")
|
||||
if config.autojoin then
|
||||
for k,v in pairs(config.channels) do
|
||||
connection:send("JOIN " .. v.."\n")
|
||||
end
|
||||
end
|
||||
repeat
|
||||
line = connection:receive()
|
||||
if line ~= nil and line ~= "timeout" then
|
||||
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
|
||||
|
6
timers/highfive.lua
Normal file
6
timers/highfive.lua
Normal 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
|
Loading…
Reference in New Issue
Block a user