diff options
Diffstat (limited to 'bot.lua')
-rw-r--r-- | bot.lua | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/bot.lua b/bot.lua index 63d977f..92927aa 100644 --- a/bot.lua +++ b/bot.lua @@ -1,24 +1,12 @@ local cqueues = require("cqueues") local socket = require("cqueues.socket") -local condition = require("cqueues.condition") -local std = require("posix.unistd") -local stdio = require("posix.stdio") local fs = require("fs") local fifo = require("fifo") local mom = require("mom") -function irc_dump(fifo, socket) - for data in fifo:iter() do - data = emit_message(data) - if not string.match(data, "[\r\n]") and #string <= 510 then - socket:write(data .. "\r\n") - end - end -end - -function parse_message(data) +local function parse_message(data) if string.match(data, "[\0\r\n]") then return nil, "illegal character" end local pos = 1 @@ -47,7 +35,7 @@ function parse_message(data) return { params = params, command = command, prefix = prefix } end -function emit_message(message) +local function emit_message(message) local out = {} if message.prefix then table.insert(out, message.prefix) @@ -74,7 +62,7 @@ end local irc_handlers = {} -function source_to_nick(source) +local function source_to_nick(source) return string.match(source, "[^!@]*") end @@ -84,6 +72,15 @@ do -- test source_to_nick assert(source_to_nick("man@host") == "man") end +local function irc_dump(fifo, socket) + for data in fifo:iter() do + data = emit_message(data) + if not string.match(data, "[\r\n]") and #string <= 510 then + socket:write(data .. "\r\n") + end + end +end + function irc_handlers.PING(state, line) fifo.put(state.queue, { command = "PONG", params = line.params }) end @@ -137,7 +134,7 @@ function irc_handlers.PRIVMSG(state, line) ) end -function handle_ed_rx(state) +local function handle_ed_rx(state) for line in state.rx_queue:iter() do if line[2] == "line" then state.queue:put({ @@ -170,7 +167,7 @@ function handle_ed_rx(state) end end -function irc_connect(loop, host, config) +local function irc_connect(loop, host, config) local state = { -- IRC output queue (message objects) queue = fifo.new(), |