censor_bear 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '078a28407918d44f7b3d06d43c666f1bf98e68356069e3d1bfee2ef5d329e865'
4
- data.tar.gz: 2d2470c0a97cf841387ed7467b2c5b5e5e79a1c60685dcd29a1445277bff83be
3
+ metadata.gz: 0c0acc1f6d43f1e10ddbc406e7dc4aa1bfb37ad8c821d048282695d5c9d0ade9
4
+ data.tar.gz: b6228ea570225303bc1c8147f8006b1efa362f19aeb95673f72ed6414d879d22
5
5
  SHA512:
6
- metadata.gz: eebc94c7d69c693cdc6f8917b377caff1e108ce34e13a497feb2acd7599c550d043dbcbfdc3bc2d099e27de8c3e3d7f294139149c8c54b16fe06f89ac12ceb60
7
- data.tar.gz: abe0d7ad46a83b0ecc37bb3f5ab4244d5afa68c1a028e9bdd1c3e53e85c58f3c98ab30e0a85b64c6c2acec53c7c86a7f9ec86fa84b2a548141c55744fae1eec4
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("word ilike ?", "%#{params[:q]}%") if params[:q].present?
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)
@@ -1,5 +1,9 @@
1
1
  module CensorBear
2
2
  module ApplicationHelper
3
3
  include Pagy::Frontend
4
+
5
+ def current_user
6
+ main_app.scope.request.env['warden'].user
7
+ end
4
8
  end
5
9
  end
@@ -17,6 +17,8 @@
17
17
  <% @logs.each do |log| %>
18
18
  <tr>
19
19
  <td><%= log.original_content %></td>
20
+ <td><%= log.scenario %></td>
21
+ <td><%= log.stage %></td>
20
22
  <td><%= log.action %></td>
21
23
  <td><%= log.filtered_content %></td>
22
24
  <td><%= log.mod_words %></td>
@@ -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, params[:action_type]), class: "border p-1 w-full rounded-md"
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, params[:action_type]), class: "border p-1 w-full rounded-md"
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, params[:action_type]), class: "border p-1 w-full rounded-md"
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, params[:action_type]), class: "border p-1 w-full rounded-md"
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, params[:action_type]), class: "border p-1 w-full rounded-md"
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
 
@@ -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::Log.create(
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
- @is_mod = true
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::Log.create(original_content: original_content, action: "#{@type}_#{action}", filtered_content: @content, mod_words: [word.key])
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::Log.create(original_content: original_content, action: "#{@type}_#{action}", filtered_content: nil, mod_words: [word.key])
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::Log.create(original_content: original_content, action: "#{@type}_#{action}", filtered_content: nil, mod_words: [word.key])
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
@@ -1,3 +1,3 @@
1
1
  module CensorBear
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/lib/censor_bear.rb CHANGED
@@ -1,9 +1,9 @@
1
- require "censor_bear/version"
2
- require "censor_bear/engine"
3
- require "censor_bear/censor"
4
- require "censor_bear/configuration"
1
+ require 'censor_bear/version'
2
+ require 'censor_bear/engine'
3
+ require 'censor_bear/censor'
4
+ require 'censor_bear/configuration'
5
5
 
6
- require "hamlit"
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.2
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-01 00:00:00.000000000 Z
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.0
19
+ version: 6.0.4
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 6.0.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.0
29
+ version: 6.0.4
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 6.0.0
32
+ version: 6.0.4.1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: hamlit
35
35
  requirement: !ruby/object:Gem::Requirement