Commit 10ea6c0f8e74d15ba81ac8ce867bca4af6685a2e
1 parent
8e524d41
屏蔽字 优化
Showing
2 changed files
with
32 additions
and
6 deletions
Show diff stats
src/services/chated.lua
... | ... | @@ -5,6 +5,8 @@ local crab = require "crab.c" |
5 | 5 | local table_insert = table.insert |
6 | 6 | local table_unpack = table.unpack |
7 | 7 | local mode, id, dict = ... |
8 | +local hideCode = utf8.codepoint("*") | |
9 | + | |
8 | 10 | |
9 | 11 | local function toutf8(name) |
10 | 12 | local t = {} |
... | ... | @@ -14,6 +16,16 @@ local function toutf8(name) |
14 | 16 | return t |
15 | 17 | end |
16 | 18 | |
19 | +local function fix(a, b) | |
20 | + for i, v in pairs(a) do | |
21 | + if b[i] == hideCode then | |
22 | + a[i] = hideCode | |
23 | + end | |
24 | + end | |
25 | + return utf8.char(table_unpack(a)) | |
26 | +end | |
27 | + | |
28 | + | |
17 | 29 | if mode == "sub" then |
18 | 30 | local CMD = {} |
19 | 31 | dict = tonumber(dict) |
... | ... | @@ -23,8 +35,9 @@ if mode == "sub" then |
23 | 35 | return false |
24 | 36 | end |
25 | 37 | local utftb = toutf8(name) |
26 | - if crab.filter(dict, utftb) then | |
27 | - return false, utf8.char(table_unpack(utftb)) | |
38 | + local utftbU = toutf8(string.upper(name)) | |
39 | + if crab.filter(dict, utftbU) then | |
40 | + return false, fix(utftb, utftbU) | |
28 | 41 | end |
29 | 42 | return true |
30 | 43 | end |
... | ... | @@ -45,7 +58,7 @@ else |
45 | 58 | |
46 | 59 | local words = {} |
47 | 60 | for _, data in ipairs(forbidNames) do |
48 | - local ok, utftb = pcall(toutf8, data.name) | |
61 | + local ok, utftb = pcall(toutf8, string.upper(data.name)) | |
49 | 62 | if ok then table.insert(words, utftb) end |
50 | 63 | end |
51 | 64 | local d = crab.open(words) | ... | ... |
src/services/named.lua
... | ... | @@ -5,6 +5,8 @@ local crab = require "crab.c" |
5 | 5 | local table_insert = table.insert |
6 | 6 | local table_unpack = table.unpack |
7 | 7 | local mode, id, dict = ... |
8 | +local hideCode = utf8.codepoint("*") | |
9 | + | |
8 | 10 | |
9 | 11 | local function toutf8(name) |
10 | 12 | local t = {} |
... | ... | @@ -14,6 +16,16 @@ local function toutf8(name) |
14 | 16 | return t |
15 | 17 | end |
16 | 18 | |
19 | +local function fix(a, b) | |
20 | + for i, v in pairs(a) do | |
21 | + if b[i] == hideCode then | |
22 | + a[i] = hideCode | |
23 | + end | |
24 | + end | |
25 | + return utf8.char(table_unpack(a)) | |
26 | +end | |
27 | + | |
28 | + | |
17 | 29 | if mode == "sub" then |
18 | 30 | local CMD = {} |
19 | 31 | dict = tonumber(dict) |
... | ... | @@ -23,8 +35,9 @@ if mode == "sub" then |
23 | 35 | return false |
24 | 36 | end |
25 | 37 | local utftb = toutf8(name) |
26 | - if crab.filter(dict, utftb) then | |
27 | - return false, utf8.char(table_unpack(utftb)) | |
38 | + local utftbU = toutf8(string.upper(name)) | |
39 | + if crab.filter(dict, utftbU) then | |
40 | + return false, fix(utftb, utftbU) | |
28 | 41 | end |
29 | 42 | return true |
30 | 43 | end |
... | ... | @@ -45,7 +58,7 @@ else |
45 | 58 | |
46 | 59 | local words = {} |
47 | 60 | for _, data in ipairs(forbidNames) do |
48 | - local ok, utftb = pcall(toutf8, data.name) | |
61 | + local ok, utftb = pcall(toutf8, string.upper(data.name)) | |
49 | 62 | if ok then table.insert(words, utftb) end |
50 | 63 | end |
51 | 64 | local d = crab.open(words) | ... | ... |