Add: #568 ハッシュタグ・メンション上限を超えた投稿もNGワード履歴に記録 (#579)

This commit is contained in:
KMY(雪あすか) 2024-02-17 12:16:41 +09:00 committed by GitHub
parent a6b5e64e15
commit e5ab4a3eb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 104 additions and 21 deletions

View file

@ -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