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.word_matcher_regexp(action) s = Discourse.cache.fetch(word_matcher_regexp_key(action), expires_in: 1.day) do words = words_for_action(action) if words.empty? nil else regexp = '(' + words.map { |w| word_to_regexp(w) }.join('|'.freeze) + ')' SiteSetting.watched_words_regular_expressions? ? regexp : "(?