mirror of
https://github.com/discourse/discourse.git
synced 2026-08-14 06:55:03 -05:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user