UX: Let users know they disabled discobot and they can't interact with it. (#12534)

UX: Let users know they disabled discobot and they can’t interact with it. (#12534)

Discobot will reply to users they need to enable onboarding tips to interact with them when issued a command.

diff --git a/plugins/discourse-narrative-bot/config/locales/server.en.yml b/plugins/discourse-narrative-bot/config/locales/server.en.yml
index 2d4887f..ef15b09 100644
--- a/plugins/discourse-narrative-bot/config/locales/server.en.yml
+++ b/plugins/discourse-narrative-bot/config/locales/server.en.yml
@@ -135,6 +135,7 @@ en:
 
           `@%{discobot_username} %{magic_8_ball_trigger}`
           > :crystal_ball: You may rely on it
+        discobot_disabled: You’ve disabled me in your preferences. You need to allow new user onboarding tips to interact with me.
 
       do_not_understand:
         first_response: |-
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 a87dba3..2ac5f73 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
@@ -126,7 +126,9 @@ module DiscourseNarrativeBot
 
     def bot_commands(hint = true)
       raw =
-        if match_data = match_trigger?("#{self.class.dice_trigger} (\\d+)d(\\d+)")
+        if @user.manually_disabled_discobot?
+          I18n.t(self.class.i18n_key('random_mention.discobot_disabled'))
+        elsif match_data = match_trigger?("#{self.class.dice_trigger} (\\d+)d(\\d+)")
           DiscourseNarrativeBot::Dice.roll(match_data[1].to_i, match_data[2].to_i)
         elsif match_trigger?(self.class.quote_trigger)
           DiscourseNarrativeBot::QuoteGenerator.generate(@user)
diff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rb
index 3aee263..f66219c 100644
--- a/plugins/discourse-narrative-bot/plugin.rb
+++ b/plugins/discourse-narrative-bot/plugin.rb
@@ -163,7 +163,7 @@ after_initialize do
 
     case SiteSetting.discourse_narrative_bot_welcome_post_type
     when 'new_user_track'
-      if enqueue_narrative_bot_job?
+      if enqueue_narrative_bot_job? && !manually_disabled_discobot?
         Jobs.enqueue_in(delay, :narrative_init,
           user_id: self.id,
           klass: DiscourseNarrativeBot::NewUserNarrative.to_s
@@ -174,12 +174,15 @@ after_initialize do
     end
   end
 
+  self.add_to_class(:user, :manually_disabled_discobot?) do
+    user_option&.skip_new_user_tips
+  end
+
   self.add_to_class(:user, :enqueue_narrative_bot_job?) do
     SiteSetting.discourse_narrative_bot_enabled &&
       self.human? &&
       !self.anonymous? &&
       !self.staged &&
-      !user_option&.skip_new_user_tips &&
       !SiteSetting.discourse_narrative_bot_ignored_usernames.split('|'.freeze).include?(self.username)
   end
 
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 f4131cd..e2e5729 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
@@ -19,6 +19,8 @@ describe DiscourseNarrativeBot::TrackSelector do
   before do
     stub_request(:get, "http://api.forismatic.com/api/1.0/?format=json&lang=en&method=getQuote").
       to_return(status: 200, body: "{\"quoteText\":\"Be Like Water\",\"quoteAuthor\":\"Bruce Lee\"}")
+
+      SiteSetting.discourse_narrative_bot_enabled = true
   end
 
   let(:help_message) do
@@ -466,6 +468,16 @@ describe DiscourseNarrativeBot::TrackSelector do
           expect(new_post.raw).to eq(random_mention_reply)
         end
 
+        it 'tells the user to enable the onboarding tips first' do
+          user.user_option.update!(skip_new_user_tips: true)
+          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(I18n.t('discourse_narrative_bot.track_selector.random_mention.discobot_disabled'))
+        end
+
         it "should be case insensitive towards discobot's username" do
           discobot_user.update!(username: 'DisCoBot')
 
diff --git a/plugins/discourse-narrative-bot/spec/user_spec.rb b/plugins/discourse-narrative-bot/spec/user_spec.rb
index f775dd7..d2eb773 100644
--- a/plugins/discourse-narrative-bot/spec/user_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/user_spec.rb
@@ -167,4 +167,12 @@ describe User do
       expect(DiscourseNarrativeBot::Store.get(user.id)).to eq(nil)
     end
   end
+
+  describe '#manually_disabled_discobot?' do
+    it 'returns true if the user manually disabled new user tips' do
+      user.user_option.skip_new_user_tips = true
+
+      expect(user.manually_disabled_discobot?).to eq(true)
+    end
+  end
 end

GitHub sha: 87b5d16c

This commit appears in #12534 which was approved by eviltrout. It was merged by romanrizzi.