censor_bear 0.1.0 → 0.1.1
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 +4 -4
- data/db/migrate/20211126133758_create_censor_bear_stop_words.rb +2 -0
- data/lib/censor_bear/censor.rb +24 -0
- data/lib/censor_bear/configuration.rb +5 -0
- data/lib/censor_bear/version.rb +1 -1
- data/lib/censor_bear.rb +3 -0
- data/lib/tasks/censor_bear_tasks.rake +58 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cdef69a9d04136c6116ed8245122bda98d27849a91e313487282be5d0640c4d
|
4
|
+
data.tar.gz: 5088b2e4f868403f242b62344af06edbe47daf4e90bbbaa264848e7c982e574d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b9138dc7b8af468e6fb59960f1bdc6801927c986758c90d709f49ce408b4a6127bf520e5480198c667717f24a2bfc9cd657938e385a5440c3c811862f47f682
|
7
|
+
data.tar.gz: 80966dea001f69dd7db9a1a64d6c687a67062a39fd01b2809a3a1c5d9b028b2066526e69594730805f76c975c49255da8974e6063e2446e7136aa2cf8bd61d89
|
data/lib/censor_bear/censor.rb
CHANGED
@@ -10,6 +10,9 @@ module CensorBear
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class Censor
|
13
|
+
QQ_REG = /(?:[加茄qQ企鹅号码\s]{1,}|[群号]{1,}|[叩叩]{1,}|[抠抠]{1,}|[扣扣]{1,})(?:[\u4e00-\u9eff]*)(?:[:,:]?)([\d\s]{6,})/
|
14
|
+
WX_REG = /(?:[加+微++➕薇?vV威卫星♥❤姓xX信]{2,}|weixin|weix)(?:[,❤️.\s]?)(?:[\u4e00-\u9eff]?)(?:[:,:]?)([\w\s]{6,})/
|
15
|
+
|
13
16
|
def initialize(content, type = 'ugc')
|
14
17
|
@is_mod = false
|
15
18
|
@mod_words = []
|
@@ -21,6 +24,27 @@ module CensorBear
|
|
21
24
|
return Result.new(@content) if @content.blank?
|
22
25
|
return Result.new(@content) unless CensorBear::StopWord::FIELDS.include?(@type)
|
23
26
|
|
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
|
+
)
|
34
|
+
raise NotPassedException
|
35
|
+
end
|
36
|
+
|
37
|
+
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
|
+
)
|
45
|
+
raise NotPassedException
|
46
|
+
end
|
47
|
+
|
24
48
|
local_check
|
25
49
|
|
26
50
|
# 用户相关类型直接封禁,速错
|
data/lib/censor_bear/version.rb
CHANGED
data/lib/censor_bear.rb
CHANGED
@@ -17,6 +17,9 @@ module CensorBear
|
|
17
17
|
@config.user_class = 'User'
|
18
18
|
@config.current_user_method = 'current_user'
|
19
19
|
@config.user_name_method = 'name'
|
20
|
+
@config.import_file_path = "#{Rails.root}/tmp/dest_sensitives.txt"
|
21
|
+
@config.format_from_file_path = "#{Rails.root}/tmp/from_sensitives.txt"
|
22
|
+
@config.format_dest_file_path = "#{Rails.root}/tmp/dest_sensitives.txt"
|
20
23
|
@config
|
21
24
|
end
|
22
25
|
|
@@ -1,4 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
namespace :censor_bear do
|
2
|
+
desc 'Format words'
|
3
|
+
task format: :environment do
|
4
|
+
from_file = File.read(CensorBear.config.format_from_file_path)
|
5
|
+
File.open(CensorBear.config.format_dest_file_path, 'w') do |f|
|
6
|
+
from_file.each_line do |word|
|
7
|
+
line = "#{word.strip!}={BANNED}|{BANNED}|{BANNED}|{BANNED}\r\n"
|
8
|
+
f.write(line)
|
9
|
+
f.flush
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Import words'
|
15
|
+
task import: :environment do
|
16
|
+
is_overwrite = true
|
17
|
+
file = File.read(CensorBear.config.import_file_path)
|
18
|
+
# lines = doc.split(/\n/)
|
19
|
+
file.each_line do |line|
|
20
|
+
line.strip!
|
21
|
+
key, rule_str = line.split('=')
|
22
|
+
rules = rule_str.split('|')
|
23
|
+
ugc = parse(rules[0]).blank? ? 'replace' : parse(rules[0])
|
24
|
+
username = parse(rules[1]) || 'ignore'
|
25
|
+
signature = parse(rules[2]) || 'ignore'
|
26
|
+
dialog = parse(rules[3]) || 'ignore'
|
27
|
+
nickname = parse(rules[1]) || 'ignore'
|
28
|
+
replacement = ugc == 'replace' ? rules[0] : '**'
|
29
|
+
|
30
|
+
payload = {
|
31
|
+
key: key,
|
32
|
+
ugc: ugc,
|
33
|
+
username: username,
|
34
|
+
signature: signature,
|
35
|
+
dialog: dialog,
|
36
|
+
nickname: nickname,
|
37
|
+
replacement: replacement,
|
38
|
+
user_id: User.last&.id,
|
39
|
+
created_at: Time.now,
|
40
|
+
updated_at: Time.now
|
41
|
+
}
|
42
|
+
|
43
|
+
word = CensorBear::StopWord.find_by(key: key)
|
44
|
+
if word
|
45
|
+
word.update_columns(payload) if is_overwrite
|
46
|
+
else
|
47
|
+
CensorBear::StopWord.create(payload)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def parse(rule)
|
53
|
+
return nil if rule.blank?
|
54
|
+
|
55
|
+
r = rule.match(/^{(\w+)}$/)
|
56
|
+
r.blank? ? nil : r[1].downcase
|
57
|
+
end
|
58
|
+
end
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 42up
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|