aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--plugins/degesch/censor.lua21
2 files changed, 22 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index cbc1807..444d4fc 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@
* degesch: added support for IRCv3 chghost
+ * censor.lua: now stripping colours from censored messages;
+ their attributes are also configurable rather than always black on black
+
1.1.0 (2020-10-31) "What Do You Mean By 'This Isn't Germany'?"
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