about summary refs log tree commit diff
path: root/bot.lua
diff options
context:
space:
mode:
Diffstat (limited to 'bot.lua')
-rw-r--r--bot.lua23
1 files changed, 19 insertions, 4 deletions
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)