forked from AlliedEnvy/leroy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
40 lines (33 loc) · 1.08 KB
/
main.lua
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
do
function string:split(sep)
local sep, fields = sep or ':', {}
local pattern = string.format('([^%s]+)', sep)
self:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
local IRC = require 'irc'
local redis = require 'redis'
http = require 'socket.http'
local socket = require 'socket'
db_client = redis.connect('127.0.0.1', 6379)
assert(db_client:ping(), 'Check redis host and port')
local environment = arg[1] or 'test'
config = require('config.' .. environment .. '_config')
irc_client = IRC.connect('irc.freenode.net')
irc_client:nick(config.nick)
irc_client:user('bot', '0', '*', 'baddest man in the whole damn town')
commands = require 'commands'
replies = require 'replies'
while true do
irc_client:send_dequeue()
local line, err = irc_client.socket:receive('*l')
if line then
print(line)
prefix, command, rest = IRC.tokenize_line(line)
command = command:lower()
if replies[command] then replies[command](prefix, rest) end
elseif err == 'closed' then
break
end
end
end