censor.lua: strip colours, configurable formatting
Colour parsing code taken from prime.lua, and modified to strip.
This commit is contained in:
parent
6f62b9c0c7
commit
c5f49ab1e6
3
NEWS
3
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'?"
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user