nas/app/models/admin/sensitive_word.rb
KMY(雪あすか) ed246f0d03
Change: #648 センシティブワードの入力フォーム (#653)
* Change: #648 センシティブワードの入力フォーム

* Wip: 行の追加削除

* Wip: 設定の保存、マイグレーション

* 不要な処理を削除

* マイグレーションコード調整
2024-03-19 08:18:34 +09:00

34 lines
888 B
Ruby

# frozen_string_literal: true
class Admin::SensitiveWord
class << self
def sensitive?(text, spoiler_text, local: true)
exposure_text = spoiler_text.presence || text
sensitive_words = ::SensitiveWord.caches
sensitive_words.select!(&:remote) unless local
return sensitive_words.filter(&:spoiler).any? { |word| include?(spoiler_text, word) } if spoiler_text.present?
sensitive_words.any? { |word| include?(exposure_text, word) }
end
def modified_text(text, spoiler_text)
spoiler_text.present? ? "#{spoiler_text}\n\n#{text}" : text
end
def alternative_text
Setting.auto_warning_text.presence || I18n.t('admin.sensitive_words.alert') || 'CW'
end
private
def include?(text, word)
if word.regexp
text =~ /#{word.keyword}/
else
text.include?(word.keyword)
end
end
end
end