nas/app/models/admin/ng_word.rb
KMY(雪あすか) 3a2030dfc8
Add: #43 フォローしていないアカウントからのリプライのNGワード (#148)
* Add: フォローしていないアカウントからのリプライのNGワード

* Test: ハッシュタグ使用量
2023-10-19 12:12:00 +09:00

48 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class Admin::NgWord
class << self
def reject?(text)
ng_words.any? { |word| include?(text, word) }
end
def reject_with_custom_words?(text, custom_ng_words)
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
end
def hashtag_reject_with_extractor?(text)
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)
if word.start_with?('?') && word.size >= 2
text =~ /#{word[1..]}/i
else
text.include?(word)
end
end
def ng_words
Setting.ng_words || []
end
def ng_words_for_stranger_mention
Setting.ng_words_for_stranger_mention || []
end
def post_hash_tags_max
value = Setting.post_hash_tags_max
value.is_a?(Integer) && value.positive? ? value : 0
end
end
end