Browse Source

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

Izaya 2 years ago
parent
commit
8a2f380146
5 changed files with 111 additions and 25 deletions
  1. 24
    1
      config.lua
  2. BIN
      hooks/.highfive.lua.swp
  3. 21
    0
      hooks/highfive.lua
  4. 60
    24
      init.lua
  5. 6
    0
      timers/highfive.lua

+ 24
- 1
config.lua View File

@@ -1 +1,24 @@
1
-{server="irc.esper.net",nick="yukichan",hostname="lain",servername="lain",realname="yuki",channels={"#SKSDev","#v","#ssss"},prefix=":",username="yuki",port=6667,admins={"ShadowKatStudios"}}
1
+{server="irc.quakenet.org",
2
+nick="yukichan",
3
+hostname="lain",
4
+servername="lain",
5
+realname="yuki",
6
+channels={
7
+ "#SKSDev",
8
+ "#v",
9
+ "#ssss"
10
+},
11
+hooks={
12
+"highfive.lua"
13
+},
14
+cmds={
15
+},
16
+timers={
17
+"highfive.lua"
18
+},
19
+autojoin=true,
20
+prefix=":",
21
+username="yuki",
22
+port=6667,
23
+admins={"ShadowKatStudios","XeonSquared"}
24
+}

BIN
hooks/.highfive.lua.swp View File


+ 21
- 0
hooks/highfive.lua View File

@@ -0,0 +1,21 @@
1
+tArgs = {...}
2
+local nick, chan, message = tArgs[1],tArgs[2],tArgs[3]
3
+print(nick,chan,message,nick == "Shocky")
4
+if message:find("o/") ~= nil or message:find("\\o") ~= nil then
5
+ if nick ~= "Shocky" then
6
+  if _G.leftHanging[2] == false then
7
+   print (nick .." left hanging at "..os.time())
8
+   local typeOfHighFive="o/"
9
+   if message:find("o/") ~= nil then
10
+    typeOfHighFive = "\\o"
11
+   end
12
+   _G.leftHanging = {os.time(),true,chan,typeOfHighFive}
13
+  elseif _G.leftHanging[2] == true then
14
+   _G.leftHanging = {0,false}
15
+   print("No longer left hanging.")
16
+  end
17
+ else
18
+  _G.leftHanging = {0,false}
19
+ end
20
+end
21
+if message:find("o/ * \\o") ~= nil then _G.leftHanging = {0, false} end

+ 60
- 24
init.lua View File

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

+ 6
- 0
timers/highfive.lua View File

@@ -0,0 +1,6 @@
1
+local os = require "os"
2
+if os.time() > _G.leftHanging[1]+3 and _G.leftHanging[2] then
3
+ print ("Responding to a hanging high-five at ".._G.leftHanging[1])
4
+ sendchan(_G.leftHanging[3],_G.leftHanging[4] or "\\o")
5
+ _G.leftHanging={0,false}
6
+end