about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--TODO7
-rw-r--r--bot.lua23
2 files changed, 22 insertions, 8 deletions
diff --git a/TODO b/TODO
index 267fedc..3ebad64 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,5 @@
-make ed restart itself
-- i think we probably want some sort of "process manager" thread which
-- handles all of the interrupts
-make it support multiple instances per channel
+have the shell cd for us (we can do this by running sh -c, but making it cd would be better)
+support joining irc channels with keys
+===
 signify what kind of commands we need (we can use b as a prefix?)
 find a name (bed? multihEaD? googlEDocs?)
diff --git a/bot.lua b/bot.lua
index 92927aa..7014eda 100644
--- a/bot.lua
+++ b/bot.lua
@@ -123,15 +123,30 @@ function irc_handlers.JOIN(state, line)
 end
 
 function irc_handlers.PRIVMSG(state, line)
+	-- TODO validate params existing, etc
+	local ch = line.params[1]
 	-- fifo.put(state.to_ed, line.params[2])
-	if not state.channels[line.params[1]] then
+	if not state.channels[ch] then
 		-- TODO
 		return
 	end
 
-	state.channels[line.params[1]].tx_queue:put(
-		line.params[2]
-	)
+	local full_line = line.params[2]
+	local line
+	for _, prefix in ipairs(state.channels[ch].invoke) do
+		prefix = string.gsub(prefix, "%%n", state.nick)
+		prefix = string.gsub(prefix, "%%%", "%")
+		-- TODO parens and stuff maybe
+
+		local pat = "^" .. prefix .. "(.*)"
+		line = string.match(full_line, pat)
+
+		if line then break end
+	end
+
+	if not line then return end
+
+	state.channels[ch].tx_queue:put(line)
 end
 
 local function handle_ed_rx(state)