parent
a6b5e64e15
commit
e5ab4a3eb2
9 changed files with 104 additions and 21 deletions
|
@ -18,24 +18,30 @@ class Admin::NgWord
|
|||
custom_ng_words.any? { |word| include?(text, word) }
|
||||
end
|
||||
|
||||
def hashtag_reject?(hashtag_count)
|
||||
post_hash_tags_max.positive? && post_hash_tags_max < hashtag_count
|
||||
def hashtag_reject?(hashtag_count, **options)
|
||||
hit = post_hash_tags_max.positive? && post_hash_tags_max < hashtag_count
|
||||
record_count!(:hashtag_count, hashtag_count, options) if hit
|
||||
hit
|
||||
end
|
||||
|
||||
def hashtag_reject_with_extractor?(text)
|
||||
hashtag_reject?(Extractor.extract_hashtags(text)&.size || 0)
|
||||
end
|
||||
|
||||
def mention_reject?(mention_count)
|
||||
post_mentions_max.positive? && post_mentions_max < mention_count
|
||||
def mention_reject?(mention_count, **options)
|
||||
hit = post_mentions_max.positive? && post_mentions_max < mention_count
|
||||
record_count!(:mention_count, mention_count, options) if hit
|
||||
hit
|
||||
end
|
||||
|
||||
def mention_reject_with_extractor?(text)
|
||||
mention_reject?(text.gsub(Account::MENTION_RE)&.count || 0)
|
||||
end
|
||||
|
||||
def stranger_mention_reject_with_count?(mention_count)
|
||||
post_stranger_mentions_max.positive? && post_stranger_mentions_max < mention_count
|
||||
def stranger_mention_reject_with_count?(mention_count, **options)
|
||||
hit = post_stranger_mentions_max.positive? && post_stranger_mentions_max < mention_count
|
||||
record_count!(:stranger_mention_count, mention_count, options) if hit
|
||||
hit
|
||||
end
|
||||
|
||||
def stranger_mention_reject_with_extractor?(text)
|
||||
|
@ -87,5 +93,19 @@ class Admin::NgWord
|
|||
keyword: keyword,
|
||||
}))
|
||||
end
|
||||
|
||||
def record_count!(type, count, options)
|
||||
return unless options[:text] && 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], reason: type)
|
||||
|
||||
NgwordHistory.create(options.merge({
|
||||
reason: type,
|
||||
text: options[:text],
|
||||
keyword: '',
|
||||
count: count,
|
||||
}))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,10 +12,11 @@
|
|||
# keyword :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# count :integer default(0), 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
|
||||
enum reason: { ng_words: 0, ng_words_for_stranger_mention: 1, hashtag_count: 2, mention_count: 3, stranger_mention_count: 4 }, _prefix: :within
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue