about summary refs log tree commit diff
diff options
context:
space:
mode:
authorequa <equaa@protonmail.com>2022-08-27 04:25:16 +0000
committerequa <equaa@protonmail.com>2022-08-27 04:25:16 +0000
commit6fec1265c14124ceda8d45a736fdd0132f84ad9f (patch)
treef2196f896a07845459bc46219a2518759d268c91
parent26f2ef59ef6353ee1afe33947ce5265d5d2389e5 (diff)
fix SIGPIPE and silly typo with overlong line protection
-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]")