censor_bear 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/censor_bear/stop_words_controller.rb +1 -1
- data/app/helpers/censor_bear/application_helper.rb +4 -0
- data/app/views/censor_bear/logs/index.html.erb +2 -0
- data/app/views/censor_bear/logs/show.html.erb +10 -0
- data/app/views/censor_bear/stop_words/_form.html.haml +5 -5
- data/db/migrate/20211129093508_create_censor_bear_logs.rb +2 -0
- data/lib/censor_bear/censor.rb +18 -17
- data/lib/censor_bear/version.rb +1 -1
- data/lib/censor_bear.rb +18 -5
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c0acc1f6d43f1e10ddbc406e7dc4aa1bfb37ad8c821d048282695d5c9d0ade9
|
4
|
+
data.tar.gz: b6228ea570225303bc1c8147f8006b1efa362f19aeb95673f72ed6414d879d22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c09a551d136e8bc286399cb40e66b17103d8124861b8620650b3e63a221829562ef3e17262fa82f9b14e336b9c6ed79f0f3de05b9ec9935eb9910688b5d668d0
|
7
|
+
data.tar.gz: 21dc98c9d40fa65381f623d4f37b2dbe465590d2dd41136d18c8743d82c5f6cbaa4de3b4cd351434b3e13917f21fc0064c634b1a9712f4cb44194fad8f2967f1
|
@@ -46,7 +46,7 @@ module CensorBear
|
|
46
46
|
|
47
47
|
def load_stop_words
|
48
48
|
builder ||= stop_word_scope
|
49
|
-
builder = builder.where("
|
49
|
+
builder = builder.where("key ilike ?", "%#{params[:q]}%") if params[:q].present?
|
50
50
|
builder = builder.order(id: :desc)
|
51
51
|
|
52
52
|
@pagy, @stop_words = pagy(builder)
|
@@ -10,6 +10,16 @@
|
|
10
10
|
<%= @log.action %>
|
11
11
|
</p>
|
12
12
|
|
13
|
+
<p>
|
14
|
+
<strong>Scenario:</strong>
|
15
|
+
<%= @log.scenario %>
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<p>
|
19
|
+
<strong>Stage:</strong>
|
20
|
+
<%= @log.stage %>
|
21
|
+
</p>
|
22
|
+
|
13
23
|
<p>
|
14
24
|
<strong>Filtered content:</strong>
|
15
25
|
<%= @log.filtered_content %>
|
@@ -10,19 +10,19 @@
|
|
10
10
|
%div= form.text_field :key, class: "border p-1 w-full rounded-md"
|
11
11
|
%div
|
12
12
|
%div{class: "text-gray-500 text-xs"}= form.label :ugc, "UGC内容处理方式"
|
13
|
-
%div= form.select :ugc, options_for_select(CensorBear.action_options,
|
13
|
+
%div= form.select :ugc, options_for_select(CensorBear.action_options, stop_word.ugc), class: "border p-1 w-full rounded-md"
|
14
14
|
%div
|
15
15
|
%div{class: "text-gray-500 text-xs"}= form.label :username, "用户名处理方式"
|
16
|
-
%div= form.select :username, options_for_select(CensorBear.action_options,
|
16
|
+
%div= form.select :username, options_for_select(CensorBear.action_options, stop_word.username), class: "border p-1 w-full rounded-md"
|
17
17
|
%div
|
18
18
|
%div{class: "text-gray-500 text-xs"}= form.label :nickname, "用户昵称处理方式"
|
19
|
-
%div= form.select :nickname, options_for_select(CensorBear.action_options,
|
19
|
+
%div= form.select :nickname, options_for_select(CensorBear.action_options, stop_word.nickname), class: "border p-1 w-full rounded-md"
|
20
20
|
%div
|
21
21
|
%div{class: "text-gray-500 text-xs"}= form.label :signature, "签名处理方式"
|
22
|
-
%div= form.select :signature, options_for_select(CensorBear.action_options,
|
22
|
+
%div= form.select :signature, options_for_select(CensorBear.action_options, stop_word.signature), class: "border p-1 w-full rounded-md"
|
23
23
|
%div
|
24
24
|
%div{class: "text-gray-500 text-xs"}= form.label :dialog, "私信处理方式"
|
25
|
-
%div= form.select :dialog, options_for_select(CensorBear.action_options,
|
25
|
+
%div= form.select :dialog, options_for_select(CensorBear.action_options, stop_word.dialog), class: "border p-1 w-full rounded-md"
|
26
26
|
%div
|
27
27
|
%div{class: "text-gray-500 text-xs"}= form.label :replacement, "过滤词替换"
|
28
28
|
%div= form.text_field :replacement, class: "border p-1 w-full rounded-md"
|
@@ -2,7 +2,9 @@ class CreateCensorBearLogs < ActiveRecord::Migration[6.1]
|
|
2
2
|
def change
|
3
3
|
create_table :censor_bear_logs do |t|
|
4
4
|
t.text :original_content
|
5
|
+
t.string :scenario
|
5
6
|
t.string :action
|
7
|
+
t.string :stage
|
6
8
|
t.text :filtered_content
|
7
9
|
t.string :mod_words, array: true, default: []
|
8
10
|
|
data/lib/censor_bear/censor.rb
CHANGED
@@ -25,29 +25,18 @@ module CensorBear
|
|
25
25
|
return Result.new(@content) unless CensorBear::StopWord::FIELDS.include?(@type)
|
26
26
|
|
27
27
|
if @content.match(QQ_REG)
|
28
|
-
CensorBear
|
29
|
-
original_content: @content,
|
30
|
-
action: "#{@type}_regex_qq",
|
31
|
-
filtered_content: nil,
|
32
|
-
mod_words: @mod_words
|
33
|
-
)
|
28
|
+
CensorBear.info(@content, @type, 'BANNED', 'qq_regex')
|
34
29
|
raise NotPassedException
|
35
30
|
end
|
36
31
|
|
37
32
|
if @content.match(WX_REG)
|
38
|
-
@
|
39
|
-
CensorBear::Log.create(
|
40
|
-
original_content: @content,
|
41
|
-
action: "#{@type}_regex_wx",
|
42
|
-
filtered_content: nil,
|
43
|
-
mod_words: @mod_words
|
44
|
-
)
|
33
|
+
CensorBear.info(@content, @type, 'BANNED', 'wx_regex')
|
45
34
|
raise NotPassedException
|
46
35
|
end
|
47
36
|
|
48
37
|
local_check
|
49
38
|
|
50
|
-
#
|
39
|
+
# 用户相关类型直接禁止创建
|
51
40
|
raise NotPassedException if @is_mod && %w[username signature dialog nickname].include?(@type)
|
52
41
|
|
53
42
|
Result.new(@content, @is_mod, @mod_words.uniq)
|
@@ -64,14 +53,26 @@ module CensorBear
|
|
64
53
|
case action
|
65
54
|
when 'REPLACE'
|
66
55
|
@content = @content.gsub(finder, word.replacement)
|
67
|
-
CensorBear
|
56
|
+
CensorBear.info(
|
57
|
+
original_content, @type, action, 'local_check',
|
58
|
+
filtered_content: @content,
|
59
|
+
mod_words: [word.key]
|
60
|
+
)
|
68
61
|
when 'MOD'
|
69
62
|
@is_mod = true
|
70
|
-
CensorBear
|
63
|
+
CensorBear.info(
|
64
|
+
original_content, @type, action, 'local_check',
|
65
|
+
filtered_content: nil,
|
66
|
+
mod_words: [word.key]
|
67
|
+
)
|
71
68
|
when 'BANNED'
|
72
69
|
@is_mod = true
|
73
70
|
# 禁止的直接抛出异常
|
74
|
-
CensorBear
|
71
|
+
CensorBear.info(
|
72
|
+
original_content, @type, action, 'local_check',
|
73
|
+
filtered_content: nil,
|
74
|
+
mod_words: [word.key]
|
75
|
+
)
|
75
76
|
raise NotPassedException
|
76
77
|
end
|
77
78
|
end
|
data/lib/censor_bear/version.rb
CHANGED
data/lib/censor_bear.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'censor_bear/version'
|
2
|
+
require 'censor_bear/engine'
|
3
|
+
require 'censor_bear/censor'
|
4
|
+
require 'censor_bear/configuration'
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'hamlit'
|
7
7
|
require 'pagy'
|
8
8
|
|
9
9
|
module CensorBear
|
@@ -31,6 +31,19 @@ module CensorBear
|
|
31
31
|
Censor.new(content, type).check_text
|
32
32
|
end
|
33
33
|
|
34
|
+
def info(content, scenario, action, stage, options = {})
|
35
|
+
filtered_content = options['filtered_content'] || nil
|
36
|
+
mod_words = options['mod_words'] || []
|
37
|
+
|
38
|
+
CensorBear::Log.create(
|
39
|
+
original_content: content,
|
40
|
+
scenario: scenario,
|
41
|
+
action: action,
|
42
|
+
stage: stage,
|
43
|
+
filtered_content: filtered_content,
|
44
|
+
mod_words: mod_words
|
45
|
+
)
|
46
|
+
end
|
34
47
|
|
35
48
|
def action_options
|
36
49
|
I18n.t('censor_log.action').map { |k, v| [v, k.to_s] }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: censor_bear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 42up
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 6.0.
|
19
|
+
version: 6.0.4
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 6.0.
|
22
|
+
version: 6.0.4.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 6.0.
|
29
|
+
version: 6.0.4
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 6.0.
|
32
|
+
version: 6.0.4.1
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: hamlit
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|