# frozen_string_literal: true class WordWatcher def initialize(raw) @raw = raw end def self.words_for_action(action) WatchedWord.where(action: WatchedWord.actions[action.to_sym]).limit(1000).pluck(:word) end def self.words_for_action_exists?(action) WatchedWord.where(action: WatchedWord.actions[action.to_sym]).exists? end def self.get_cached_words(action) Discourse.cache.fetch(word_matcher_regexp_key(action), expires_in: 1.day) do words_for_action(action).presence end end def self.word_matcher_regexp(action) words = get_cached_words(action) if words words = words.map do |w| word = word_to_regexp(w) word = "(#{word})" if SiteSetting.watched_words_regular_expressions? word end regexp = words.join('|') if !SiteSetting.watched_words_regular_expressions? regexp = "(#{regexp})" regexp = "(?