about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bot.lua14
1 files changed, 12 insertions, 2 deletions
diff --git a/bot.lua b/bot.lua
index 18faea1..66e3d12 100644
--- a/bot.lua
+++ b/bot.lua
@@ -1,5 +1,6 @@
 local cqueues = require("cqueues")
 local socket = require("cqueues.socket")
+local signal = require("cqueues.signal")
 
 local fs = require("fs")
 
@@ -77,7 +78,7 @@ 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
+		if not string.match(data, "[\r\n]") and #data <= 510 then
 			socket:write(data .. "\r\n")
 		end
 	end
@@ -238,7 +239,15 @@ local function irc_connect(loop, config)
 
 			local command = (tonumber(line.command) and "_" or "") .. line.command
 			if irc_handlers[command] then
-				irc_handlers[command](state, line)
+				local ok, err = pcall(
+					irc_handlers[command],
+					state,
+					line
+				)
+
+				if not ok then
+					print(err)
+				end
 			end
 		end
 
@@ -303,6 +312,7 @@ local function validate_config(c)
 end
 
 do
+	signal.ignore(signal.SIGPIPE)
 	local main = cqueues.new()
 	if not arg[1] then
 		print("usage: edbot [CONFIG]")