diff options
author | equa <equaa@protonmail.com> | 2022-03-10 20:30:59 +0000 |
---|---|---|
committer | equa <equaa@protonmail.com> | 2022-03-10 20:30:59 +0000 |
commit | c926a2f11e75f744c187fd116d8675a0fc090cb3 (patch) | |
tree | accb342b4a71e93e97732bb3fed568f462d0762d /bot.lua | |
parent | 0890ddb40f59170f1c672f7ed10b89566fe97c93 (diff) |
only invoke edbot with a specific prefix
Diffstat (limited to 'bot.lua')
-rw-r--r-- | bot.lua | 23 |
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) |