diff --git a/src/services/chated.lua b/src/services/chated.lua index 38bef4e..fca72a5 100644 --- a/src/services/chated.lua +++ b/src/services/chated.lua @@ -5,6 +5,8 @@ local crab = require "crab.c" local table_insert = table.insert local table_unpack = table.unpack local mode, id, dict = ... +local hideCode = utf8.codepoint("*") + local function toutf8(name) local t = {} @@ -14,6 +16,16 @@ local function toutf8(name) return t end +local function fix(a, b) + for i, v in pairs(a) do + if b[i] == hideCode then + a[i] = hideCode + end + end + return utf8.char(table_unpack(a)) +end + + if mode == "sub" then local CMD = {} dict = tonumber(dict) @@ -23,8 +35,9 @@ if mode == "sub" then return false end local utftb = toutf8(name) - if crab.filter(dict, utftb) then - return false, utf8.char(table_unpack(utftb)) + local utftbU = toutf8(string.upper(name)) + if crab.filter(dict, utftbU) then + return false, fix(utftb, utftbU) end return true end @@ -45,7 +58,7 @@ else local words = {} for _, data in ipairs(forbidNames) do - local ok, utftb = pcall(toutf8, data.name) + local ok, utftb = pcall(toutf8, string.upper(data.name)) if ok then table.insert(words, utftb) end end local d = crab.open(words) diff --git a/src/services/named.lua b/src/services/named.lua index 9fb1591..e32524c 100644 --- a/src/services/named.lua +++ b/src/services/named.lua @@ -5,6 +5,8 @@ local crab = require "crab.c" local table_insert = table.insert local table_unpack = table.unpack local mode, id, dict = ... +local hideCode = utf8.codepoint("*") + local function toutf8(name) local t = {} @@ -14,6 +16,16 @@ local function toutf8(name) return t end +local function fix(a, b) + for i, v in pairs(a) do + if b[i] == hideCode then + a[i] = hideCode + end + end + return utf8.char(table_unpack(a)) +end + + if mode == "sub" then local CMD = {} dict = tonumber(dict) @@ -23,8 +35,9 @@ if mode == "sub" then return false end local utftb = toutf8(name) - if crab.filter(dict, utftb) then - return false, utf8.char(table_unpack(utftb)) + local utftbU = toutf8(string.upper(name)) + if crab.filter(dict, utftbU) then + return false, fix(utftb, utftbU) end return true end @@ -45,7 +58,7 @@ else local words = {} for _, data in ipairs(forbidNames) do - local ok, utftb = pcall(toutf8, data.name) + local ok, utftb = pcall(toutf8, string.upper(data.name)) if ok then table.insert(words, utftb) end end local d = crab.open(words) -- libgit2 0.21.2