diff options
Diffstat (limited to 'bot.lua')
-rw-r--r-- | bot.lua | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/bot.lua b/bot.lua index 7014eda..db01ba8 100644 --- a/bot.lua +++ b/bot.lua @@ -182,7 +182,9 @@ local function handle_ed_rx(state) end end -local function irc_connect(loop, host, config) +local function irc_connect(loop, config) + local host = config.host + local state = { -- IRC output queue (message objects) queue = fifo.new(), @@ -203,8 +205,10 @@ local function irc_connect(loop, host, config) channels = {}, } - local sock = assert(socket.connect(host)) - sock:starttls() + local sock = assert(socket.connect(host.host, host.port)) + if host.tls then + sock:starttls() + end loop:wrap(function () irc_dump(state.queue, sock) end) loop:wrap(function () @@ -236,14 +240,24 @@ local function irc_connect(loop, host, config) loop:wrap(function () handle_ed_rx(state) end) fifo.put(state.queue, { command = "NICK", params = { config.nick } }) - fifo.put(state.queue, { command = "USER", params = { "ed1bot", "0", "*", ":)" } }) + -- TODO: config + fifo.put(state.queue, { + command = "USER", + params = { "ed1bot", "0", "*", ":)" }, + }) end -local main = cqueues.new() -if not arg[1] then - print("usage: edbot [CONFIG]") - os.exit(1) +do + local main = cqueues.new() + if not arg[1] then + print("usage: edbot [CONFIG]") + os.exit(1) + end + + local config = assert(dofile(arg[1])) + + main:wrap(function () + irc_connect(main, config) + end) + assert(main:loop()) end -main:wrap(function () irc_connect(main, { host = "localhost", port = 6697 }, dofile(arg[1])) end) -assert(main:loop()) -return { parse_message = parse_message } |