diff options
author | equa <equaa@protonmail.com> | 2022-03-13 15:48:52 +0000 |
---|---|---|
committer | equa <equaa@protonmail.com> | 2022-03-13 15:48:52 +0000 |
commit | 199b82b6767dcbe0a3e5cd770402d87e1be04f31 (patch) | |
tree | a70e36d19e005ae74e65ad49c16dfba486d73764 /bot.lua | |
parent | 24808397734a69ca0b8d41a32969939a9451496e (diff) |
fix host configuration
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 } |