parent
0ca2a73fd2
commit
7421c89431
19 changed files with 262 additions and 17 deletions
|
@ -2,8 +2,16 @@
|
|||
|
||||
class Admin::NgWord
|
||||
class << self
|
||||
def reject?(text)
|
||||
ng_words.any? { |word| include?(text, word) }
|
||||
def reject?(text, **options)
|
||||
hit_word = ng_words.detect { |word| include?(text, word) ? word : nil }
|
||||
record!(:ng_words, text, hit_word, options) if hit_word.present?
|
||||
hit_word.present?
|
||||
end
|
||||
|
||||
def stranger_mention_reject?(text, **options)
|
||||
hit_word = ng_words_for_stranger_mention.detect { |word| include?(text, word) ? word : nil }
|
||||
record!(:ng_words_for_stranger_mention, text, hit_word, options) if hit_word.present?
|
||||
hit_word.present?
|
||||
end
|
||||
|
||||
def reject_with_custom_words?(text, custom_ng_words)
|
||||
|
@ -18,10 +26,6 @@ class Admin::NgWord
|
|||
hashtag_reject?(Extractor.extract_hashtags(text)&.size || 0)
|
||||
end
|
||||
|
||||
def stranger_mention_reject?(text)
|
||||
ng_words_for_stranger_mention.any? { |word| include?(text, word) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def include?(text, word)
|
||||
|
@ -44,5 +48,18 @@ class Admin::NgWord
|
|||
value = Setting.post_hash_tags_max
|
||||
value.is_a?(Integer) && value.positive? ? value : 0
|
||||
end
|
||||
|
||||
def record!(type, text, keyword, options)
|
||||
return unless options[:uri] && options[:target_type]
|
||||
return if options.key?(:public) && !options.delete(:public)
|
||||
|
||||
return if NgwordHistory.where('created_at > ?', 1.day.ago).exists?(uri: options[:uri], keyword: options[:keyword])
|
||||
|
||||
NgwordHistory.create(options.merge({
|
||||
reason: type,
|
||||
text: text,
|
||||
keyword: keyword,
|
||||
}))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
21
app/models/ngword_history.rb
Normal file
21
app/models/ngword_history.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: ngword_histories
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# uri :string not null
|
||||
# target_type :integer not null
|
||||
# reason :integer not null
|
||||
# text :string not null
|
||||
# keyword :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
class NgwordHistory < ApplicationRecord
|
||||
include Paginable
|
||||
|
||||
enum target_type: { status: 0, account_note: 1, account_name: 2 }, _suffix: :blocked
|
||||
enum reason: { ng_words: 0, ng_words_for_stranger_mention: 1 }, _prefix: :within
|
||||
end
|
|
@ -14,7 +14,6 @@
|
|||
# sign_in_count :integer default(0), not null
|
||||
# current_sign_in_at :datetime
|
||||
# last_sign_in_at :datetime
|
||||
# admin :boolean default(FALSE), not null
|
||||
# confirmation_token :string
|
||||
# confirmed_at :datetime
|
||||
# confirmation_sent_at :datetime
|
||||
|
@ -29,7 +28,6 @@
|
|||
# otp_backup_codes :string is an Array
|
||||
# account_id :bigint(8) not null
|
||||
# disabled :boolean default(FALSE), not null
|
||||
# moderator :boolean default(FALSE), not null
|
||||
# invite_id :bigint(8)
|
||||
# chosen_languages :string is an Array
|
||||
# created_by_application_id :bigint(8)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue