|
@@ -1,8 +1,10 @@
|
1
|
1
|
local socket = require "socket"
|
2
|
2
|
local serialization = require "serialization"
|
3
|
3
|
|
4
|
|
-local config = {}
|
5
|
|
-local cmds={}
|
|
4
|
+config = {}
|
|
5
|
+cmds = {}
|
|
6
|
+hooks = {}
|
|
7
|
+timers = {}
|
6
|
8
|
|
7
|
9
|
function loadconfig()
|
8
|
10
|
local f = io.open("./config.lua","rb")
|
|
@@ -10,6 +12,47 @@ function loadconfig()
|
10
|
12
|
f:close()
|
11
|
13
|
print(content)
|
12
|
14
|
config = serialization.unserialize(content)
|
|
15
|
+ hooks = {}
|
|
16
|
+ for k,v in pairs(config.hooks) do
|
|
17
|
+ print("Loading hook "..v)
|
|
18
|
+ local fo=io.open("./hooks/" .. v)
|
|
19
|
+ local c = fo:read("*a")
|
|
20
|
+ local s,f = pcall(load,c)
|
|
21
|
+ fo:close()
|
|
22
|
+ if s then
|
|
23
|
+ table.insert(hooks,f)
|
|
24
|
+ print("Hook "..v.." loaded")
|
|
25
|
+ else
|
|
26
|
+ print("Hook "..v.." failed to load:")
|
|
27
|
+ print(f)
|
|
28
|
+ end
|
|
29
|
+ end
|
|
30
|
+ cmds = {}
|
|
31
|
+ for k,v in pairs(config.cmds) do
|
|
32
|
+ local fo=io.open("./cmds/" .. v)
|
|
33
|
+ local s,f = pcall(load,fo:read("*a"))
|
|
34
|
+ fo:close()
|
|
35
|
+ if s then
|
|
36
|
+ table.insert(cmds,f)
|
|
37
|
+ print("Command "..v.." loaded")
|
|
38
|
+ else
|
|
39
|
+ print("Command "..v.." failed to load:")
|
|
40
|
+ print(f)
|
|
41
|
+ end
|
|
42
|
+ end
|
|
43
|
+ timers = {}
|
|
44
|
+ for k,v in pairs(config.timers) do
|
|
45
|
+ local fo=io.open("./timers/" .. v)
|
|
46
|
+ local s,f = pcall(load,fo:read("*a"))
|
|
47
|
+ fo:close()
|
|
48
|
+ if s then
|
|
49
|
+ table.insert(timers,f)
|
|
50
|
+ print("Timer "..v.." loaded")
|
|
51
|
+ else
|
|
52
|
+ print("Timer "..v.."Failed to load:")
|
|
53
|
+ print(f)
|
|
54
|
+ end
|
|
55
|
+ end
|
13
|
56
|
end
|
14
|
57
|
|
15
|
58
|
function saveconfig()
|
|
@@ -62,21 +105,10 @@ end
|
62
|
105
|
leftHanging = {0,false}
|
63
|
106
|
|
64
|
107
|
function parsemsg(nick,chan,message)
|
65
|
|
- if message:find("o/") ~= nil or message:find("\\o") ~= nil and nick ~= "Shocky" and nick ~= "yukichan" then
|
66
|
|
- if leftHanging[2] == false then
|
67
|
|
- print (nick .." left hanging at "..os.time())
|
68
|
|
- local typeOfHighFive="o/"
|
69
|
|
- if message:find("o/") ~= nil then
|
70
|
|
- typeOfHighFive = "\\o"
|
71
|
|
- end
|
72
|
|
- leftHanging = {os.time(),true,chan,typeOfHighFive}
|
73
|
|
- elseif leftHanging[2] == true then
|
74
|
|
- leftHanging = {0,false}
|
75
|
|
- print("No longer left hanging.")
|
76
|
|
- end
|
|
108
|
+ for k,v in ipairs(hooks) do
|
|
109
|
+ v(nick,chan,message)
|
77
|
110
|
end
|
78
|
|
- if message:find("o/ * \\o") ~= nil and nick == "Shocky" then leftHanging = {0, false} end
|
79
|
|
- if string.find(message,":") == 1 then
|
|
111
|
+ if string.find(message,config.prefix) == 1 then
|
80
|
112
|
local command = message:sub(2) .. " "
|
81
|
113
|
if command == "" then return end
|
82
|
114
|
local tCommand = {}
|
|
@@ -99,6 +131,8 @@ function parsemsg(nick,chan,message)
|
99
|
131
|
if checkAdmin(nick) then
|
100
|
132
|
writeln(command:sub(9))
|
101
|
133
|
end
|
|
134
|
+ elseif tCommand[1] == "drop" then
|
|
135
|
+ leftHanging = {0, false}
|
102
|
136
|
elseif tCommand[1] == "join" then
|
103
|
137
|
writeln("JOIN "..tCommand[2])
|
104
|
138
|
elseif tCommand[1] == "lua" then
|
|
@@ -149,7 +183,7 @@ function main()
|
149
|
183
|
function writeln(l) connection:send(l.."\n") end
|
150
|
184
|
function sendchan(chan,msg) writeln("PRIVMSG "..chan.." :"..msg) end
|
151
|
185
|
function readln() return connection:receive() end
|
152
|
|
- connection:settimeout(2)
|
|
186
|
+ connection:settimeout(1)
|
153
|
187
|
print("Connected!")
|
154
|
188
|
os.sleep(1)
|
155
|
189
|
connection:receive() -- drop a line
|
|
@@ -163,12 +197,16 @@ function main()
|
163
|
197
|
writeln("PONG :"..pingid)
|
164
|
198
|
print("Pinged: "..pingid)
|
165
|
199
|
end
|
166
|
|
- print(line)
|
|
200
|
+ if line ~= "" then
|
|
201
|
+ print(line)
|
|
202
|
+ end
|
167
|
203
|
until string.match(line or "","%+i") ~= nil
|
168
|
204
|
os.sleep(2)
|
169
|
205
|
print("Sent everything relevant. Joining channels.")
|
170
|
|
- for k,v in pairs(config.channels) do
|
171
|
|
- connection:send("JOIN " .. v.."\n")
|
|
206
|
+ if config.autojoin then
|
|
207
|
+ for k,v in pairs(config.channels) do
|
|
208
|
+ connection:send("JOIN " .. v.."\n")
|
|
209
|
+ end
|
172
|
210
|
end
|
173
|
211
|
repeat
|
174
|
212
|
line = connection:receive()
|
|
@@ -176,10 +214,8 @@ function main()
|
176
|
214
|
print(line)
|
177
|
215
|
pcall(parse,line)
|
178
|
216
|
end
|
179
|
|
- if os.time() > leftHanging[1]+3 and leftHanging[2] then
|
180
|
|
- print ("Responding to a hanging high-five at "..leftHanging[1])
|
181
|
|
- sendchan(leftHanging[3],leftHanging[4] or "\\o")
|
182
|
|
- leftHanging={0,false}
|
|
217
|
+ for k,v in ipairs(timers) do
|
|
218
|
+ v(line)
|
183
|
219
|
end
|
184
|
220
|
if line == nil then line = "" end
|
185
|
221
|
until string.find(line,"ERROR :Closing link:") ~= nil
|