From 977bbb1f456bd5a85f8a8d5d2e9fb27beb5ce43c Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 8 Jun 2017 18:59:44 +0900 Subject: [PATCH] FIX: Bot mentioned check should be case insensitive. --- .../lib/discourse_narrative_bot/track_selector.rb | 4 ++-- .../discourse_narrative_bot/track_selector_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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 2a5934c76a2..2888489f020 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 @@ -245,13 +245,13 @@ module DiscourseNarrativeBot def bot_mentioned? @bot_mentioned ||= PostAnalyzer.new(@post.raw, @post.topic_id).raw_mentions.include?( - self.discobot_user.username + self.discobot_user.username.downcase ) end def public_reply? !SiteSetting.discourse_narrative_bot_disable_public_replies && - (bot_mentioned? || reply_to_bot_post?(@post)) + (reply_to_bot_post?(@post) || bot_mentioned?) end def terminate_track(data) 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 075c8f6ab87..213aa6917e3 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 @@ -427,6 +427,16 @@ describe DiscourseNarrativeBot::TrackSelector do expect(new_post.raw).to eq(random_mention_reply) end + it "should be case insensitive towards discobot's username" do + discobot_user.update!(username: 'DisCoBot') + + post.update!(raw: 'Show me what you can do @discobot') + described_class.new(:reply, user, post_id: post.id).select + new_post = Post.last + expect(new_post.raw).to eq(random_mention_reply) + end + + describe 'rate limiting random reply message in public topic' do let(:topic) { Fabricate(:topic) } let(:other_post) { Fabricate(:post, raw: '@discobot show me something', topic: topic) }