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,6 +5,8 @@ local crab = require "crab.c" | ||
5 | local table_insert = table.insert | 5 | local table_insert = table.insert |
6 | local table_unpack = table.unpack | 6 | local table_unpack = table.unpack |
7 | local mode, id, dict = ... | 7 | local mode, id, dict = ... |
8 | +local hideCode = utf8.codepoint("*") | ||
9 | + | ||
8 | 10 | ||
9 | local function toutf8(name) | 11 | local function toutf8(name) |
10 | local t = {} | 12 | local t = {} |
@@ -14,6 +16,16 @@ local function toutf8(name) | @@ -14,6 +16,16 @@ local function toutf8(name) | ||
14 | return t | 16 | return t |
15 | end | 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 | if mode == "sub" then | 29 | if mode == "sub" then |
18 | local CMD = {} | 30 | local CMD = {} |
19 | dict = tonumber(dict) | 31 | dict = tonumber(dict) |
@@ -23,8 +35,9 @@ if mode == "sub" then | @@ -23,8 +35,9 @@ if mode == "sub" then | ||
23 | return false | 35 | return false |
24 | end | 36 | end |
25 | local utftb = toutf8(name) | 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 | end | 41 | end |
29 | return true | 42 | return true |
30 | end | 43 | end |
@@ -45,7 +58,7 @@ else | @@ -45,7 +58,7 @@ else | ||
45 | 58 | ||
46 | local words = {} | 59 | local words = {} |
47 | for _, data in ipairs(forbidNames) do | 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 | if ok then table.insert(words, utftb) end | 62 | if ok then table.insert(words, utftb) end |
50 | end | 63 | end |
51 | local d = crab.open(words) | 64 | local d = crab.open(words) |
src/services/named.lua
@@ -5,6 +5,8 @@ local crab = require "crab.c" | @@ -5,6 +5,8 @@ local crab = require "crab.c" | ||
5 | local table_insert = table.insert | 5 | local table_insert = table.insert |
6 | local table_unpack = table.unpack | 6 | local table_unpack = table.unpack |
7 | local mode, id, dict = ... | 7 | local mode, id, dict = ... |
8 | +local hideCode = utf8.codepoint("*") | ||
9 | + | ||
8 | 10 | ||
9 | local function toutf8(name) | 11 | local function toutf8(name) |
10 | local t = {} | 12 | local t = {} |
@@ -14,6 +16,16 @@ local function toutf8(name) | @@ -14,6 +16,16 @@ local function toutf8(name) | ||
14 | return t | 16 | return t |
15 | end | 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 | if mode == "sub" then | 29 | if mode == "sub" then |
18 | local CMD = {} | 30 | local CMD = {} |
19 | dict = tonumber(dict) | 31 | dict = tonumber(dict) |
@@ -23,8 +35,9 @@ if mode == "sub" then | @@ -23,8 +35,9 @@ if mode == "sub" then | ||
23 | return false | 35 | return false |
24 | end | 36 | end |
25 | local utftb = toutf8(name) | 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 | end | 41 | end |
29 | return true | 42 | return true |
30 | end | 43 | end |
@@ -45,7 +58,7 @@ else | @@ -45,7 +58,7 @@ else | ||
45 | 58 | ||
46 | local words = {} | 59 | local words = {} |
47 | for _, data in ipairs(forbidNames) do | 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 | if ok then table.insert(words, utftb) end | 62 | if ok then table.insert(words, utftb) end |
50 | end | 63 | end |
51 | local d = crab.open(words) | 64 | local d = crab.open(words) |