about summary refs log tree commit diff
path: root/bot.lua
diff options
context:
space:
mode:
authorequa <equaa@protonmail.com>2022-03-08 22:04:55 +0000
committerequa <equaa@protonmail.com>2022-03-08 22:12:23 +0000
commit55e859929479050e2a3b71a614a388f3b6c2a197 (patch)
tree95ebc1638c229dd8409ba56054a8f48b2fa4f533 /bot.lua
parent224e8f43c50a513bae78af2152c12c0a5f9564f9 (diff)
basic editor watcher, soon to be several editors
Diffstat (limited to 'bot.lua')
-rw-r--r--bot.lua39
1 files changed, 30 insertions, 9 deletions
diff --git a/bot.lua b/bot.lua
index f957fd3..ac0a10c 100644
--- a/bot.lua
+++ b/bot.lua
@@ -8,6 +8,7 @@ local dkjson = require("dkjson")
 local fs = require("fs")
 
 local fifo = require("fifo")
+local mom = require("mom")
 
 function irc_dump(fifo, socket)
 	for data in fifo:iter() do
@@ -128,6 +129,7 @@ function irc_connect(loop, host, config)
 	local state = {
 		queue = fifo.new(),
 		nick = config.nick or "ed1bot",
+		command = config.command,
 	}
 
 	-- populate channels
@@ -169,19 +171,38 @@ function irc_connect(loop, host, config)
 		end
 	end)
 
-	state.to_ed, state.from_ed = fifo.new(), fifo.new()
-	handle_ed(loop, state.to_ed, state.from_ed, { "red" })
+	-- state.to_ed, state.from_ed = fifo.new(), fifo.new()
+	-- handle_ed(loop, state.to_ed, state.from_ed, { "red" })
+	state.mom = mom.new(loop)
+	state.to_ed, state.from_ed = select(2, state.mom:create(state.command))
 
 	loop:wrap(function()
 		while true do
 			local line = fifo.get(state.from_ed)
-			fifo.put(state.queue, {
-				command = "PRIVMSG",
-				params = {
-					state.channel,
-					line
-				}
-			})
+			if type(line) == "string" then
+				fifo.put(state.queue, {
+					command = "PRIVMSG",
+					params = {
+						state.channel,
+						line
+					}
+				})
+			else -- TODO other possible types
+				fifo.put(state.queue, {
+					command = "PART",
+					params = {
+						state.channel
+					},
+				})
+				-- be annoying
+				cqueues.poll(10.0)
+				fifo.put(state.queue, {
+					command = "JOIN",
+					params = {
+						state.channel
+					},
+				})
+			end
 		end
 	end)