FEATURE: Autotag watched words (#12244)

New topics with be matched against a set of watched words and be
tagged accordingly.
This commit is contained in:
Bianca Nenciu
2021-03-03 10:53:38 +02:00
committed by GitHub
parent 8d38438725
commit b49b455e47
9 changed files with 86 additions and 10 deletions
+10 -2
View File
@@ -8,7 +8,7 @@ class WordWatcher
def self.words_for_action(action)
words = WatchedWord.where(action: WatchedWord.actions[action.to_sym]).limit(1000)
if action.to_sym == :replace
if action.to_sym == :replace || action.to_sym == :tag
words.pluck(:word, :replacement).to_h
else
words.pluck(:word)
@@ -31,7 +31,7 @@ class WordWatcher
def self.word_matcher_regexp(action, raise_errors: false)
words = get_cached_words(action)
if words
if action.to_sym == :replace
if action.to_sym == :replace || action.to_sym == :tag
words = words.keys
end
words = words.map do |w|
@@ -110,4 +110,12 @@ class WordWatcher
false
end
end
def matches?(word)
if SiteSetting.watched_words_regular_expressions?
Regexp.new(word).match?(@raw)
else
@raw.include?(word)
end
end
end