From c5f49ab1e66578335fec162a1dec079080a25dfa Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Wed, 2 Jun 2021 23:33:39 +0200 Subject: censor.lua: strip colours, configurable formatting Colour parsing code taken from prime.lua, and modified to strip. --- plugins/degesch/censor.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'plugins') 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
+-- Copyright (c) 2016 - 2021, Přemysl Eric Janouch
-- -- 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 -- cgit v1.2.3-70-g09d2