diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/track_selector.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/track_selector.rb index c5c1a58c60f..67d852317fa 100644 --- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/track_selector.rb +++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/track_selector.rb @@ -222,9 +222,15 @@ module DiscourseNarrativeBot end end + @@cooked_triggers = {} + + def cook(trigger) + @@cooked_triggers[trigger] ||= PrettyText.cook("@#{self.discobot_username} #{trigger}") + end + def match_trigger?(trigger) # we remove the leading
to allow for trigger to be at the end of a paragraph - cooked_trigger = PrettyText.cook("@#{self.discobot_username} #{trigger}")[3..-1] + cooked_trigger = cook(trigger)[3..-1] regexp = Regexp.new(cooked_trigger, 'i') match = @post.cooked.match(regexp) diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb index f60aad254d5..d703ab7e126 100644 --- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb +++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb @@ -416,6 +416,15 @@ describe DiscourseNarrativeBot::TrackSelector do expect(new_post.raw).to eq(random_mention_reply) end + it 'works with french locale' do + I18n.with_locale("fr") do + post.update!(raw: "@discobot afficher l'aide") + described_class.new(:reply, user, post_id: post.id).select + # gsub'ing to ensure non-breaking whitespaces matches regular whitespaces + expect(Post.last.raw.gsub(/[[:space:]]+/, " ")).to eq(help_message.gsub(/[[:space:]]+/, " ")) + end + end + it 'should not rate limit help message' do post.update!(raw: '@discobot') other_post = Fabricate(:post, raw: 'discobot', topic: post.topic)