-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
78 lines (76 loc) · 2.31 KB
/
Copy pathmain.lua
File metadata and controls
78 lines (76 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require"irc.init"
config={}
dofile("config.lua")
json=dofile("json.lua")
--[[
--Options:
-- config.server: IRC server to connect to
-- config.port: Port on the IRC server to connect to
-- config.servername: Friendly name for the IRC server.
-- config.nickname: Nickname to use on the IRC server. Must be one word.
-- config.username: Username to use on the IRC server. Must be one word.
-- config.realname: Realname to use on the IRC server. Can be multiple words.
-- config.autorun: *RAW* commands to send to the IRC server before joining channels. If this is :::SLEEP:::(sec)::: then we will wait <sec> seconds before continuing.
-- config.channels: Channel names to join.
-- config.cmdchar: Command character to use
]]--
users={}
function split(str, pat) -- from lua-users wiki
local t = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
function sleep(sec) socket.select(nil,nil,sec) end
function debug_raw(line) print(line) end
if config.debug then irc:hook("OnLine","[CORE/DEBUG] raw debug hook",debug_raw) end
dofile("load.lua")
ircuser={}
ircuser.username=config.username
ircuser.nick=config.nickname
ircuser.realname=config.realname
irc=irc.new(ircuser)
irc:connect(config.server,config.port,config.servername)
for k,v in pairs(config.autorun) do
-- :::SLEEP:::(sec):::
if string.match(v,":::SLEEP:::(.+):::") then
socket.select(nil,nil,tonumber(string.match(v,"::SLEEP:::(.+):::")))
else
irc:send(v)
end
end
for k,v in pairs(config.channels) do
irc:join(v)
end
for i=1,50 do irc:think() end
irc:hook("OnChat","[CORE] Main command engine",commandEngine)
started=true
s,apr=pcall(function() return require"apr" end)
function SIGHUP()
_,err=pcall(function() dofile"load.lua" end)
print("SIGHUP received, reloaded.")
if err then
print("[ERROR]\t\t"..err)
end
end
if s==true then
print("Apache Portable Runtime loaded, will catch SIGHUP to reload and SIGTERM to exit.")
apr.signal("SIGHUP",SIGHUP)
--apr.signal("SIGTERM",function() os.exit() end)
end
while irc do
irc:think()
sleep(0.2)
end