summaryrefslogtreecommitdiff
path: root/plugins/degesch/censor.lua
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-06-02 23:33:39 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-06-03 00:12:22 +0200
commitc5f49ab1e66578335fec162a1dec079080a25dfa (patch)
tree16b916e7af980dcd9b5d6dcddb566de2742cc0b8 /plugins/degesch/censor.lua
parent6f62b9c0c722dbad9f6c3ec969f1375fdcbe5dd2 (diff)
downloadxK-c5f49ab1e66578335fec162a1dec079080a25dfa.tar.gz
xK-c5f49ab1e66578335fec162a1dec079080a25dfa.tar.xz
xK-c5f49ab1e66578335fec162a1dec079080a25dfa.zip
censor.lua: strip colours, configurable formatting
Colour parsing code taken from prime.lua, and modified to strip.
Diffstat (limited to 'plugins/degesch/censor.lua')
-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