summaryrefslogtreecommitdiff
path: root/plugins/degesch
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/degesch')
-rw-r--r--plugins/degesch/censor.lua21
1 files changed, 19 insertions, 2 deletions
diff --git a/plugins/degesch/censor.lua b/plugins/degesch/censor.lua
index a768aed..cb76c23 100644
--- a/plugins/degesch/censor.lua
+++ b/plugins/degesch/censor.lua
@@ -1,7 +1,7 @@
--
-- censor.lua: black out certain users' messages
--
--- Copyright (c) 2016, Přemysl Eric Janouch <p@janouch.name>
+-- Copyright (c) 2016 - 2021, Přemysl Eric Janouch <p@janouch.name>
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted.
@@ -38,6 +38,7 @@ local read_masks = function (v)
end
end
+local quote
degesch.setup_config {
masks = {
type = "string_array",
@@ -45,13 +46,29 @@ degesch.setup_config {
comment = "user masks (optionally \"/#channel\") to censor",
on_change = read_masks
},
+ quote = {
+ type = "string",
+ default = "\"\\x0301,01\"",
+ comment = "formatting prefix for censored messages",
+ on_change = function (v) quote = v end
+ },
}
+local decolor = function (text)
+ local rebuilt, last = {""}, 1
+ for start in text:gmatch ('()\x03') do
+ table.insert (rebuilt, text:sub (last, start - 1))
+ local sub = text:sub (start + 1)
+ last = start + (sub:match ('^%d%d?,%d%d?()') or sub:match ('^%d?%d?()'))
+ end
+ return table.concat (rebuilt) .. text:sub (last)
+end
+
local censor = function (line)
-- Taking a shortcut to avoid lengthy message reassembly
local start, text = line:match ("^(.- PRIVMSG .- :)(.*)$")
local ctcp, rest = text:match ("^(\x01%g+ )(.*)")
- text = ctcp and ctcp .. "\x0301,01" .. rest or "\x0301,01" .. text
+ text = ctcp and ctcp .. quote .. decolor (rest) or quote .. decolor (text)
return start .. text
end