From c926a2f11e75f744c187fd116d8675a0fc090cb3 Mon Sep 17 00:00:00 2001 From: equa Date: Thu, 10 Mar 2022 20:30:59 +0000 Subject: only invoke edbot with a specific prefix --- TODO | 7 +++---- bot.lua | 23 +++++++++++++++++++---- 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) -- cgit 1.3.0-6-gf8a5