From ed4d7ae1b9fba92a3f020982d54744f48e2b945e Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 27 Mar 2018 12:00:29 -0400 Subject: [PATCH] FIX: discobot fails when max_emojis_in_title=0 (#5710) * If discobot is enabled but max_emojis_in_title==0, try to strip emoji from the title when creating a new post --- .../discourse_narrative_bot/new_user_narrative.rb | 7 ++++++- plugins/discourse-narrative-bot/spec/user_spec.rb | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb index 9bd4819b5fd..26ab1437d64 100644 --- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb +++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb @@ -182,8 +182,13 @@ module DiscourseNarrativeBot #{instance_eval(&@next_instructions)} RAW + title = I18n.t("#{I18N_KEY}.hello.title", title: SiteSetting.title) + if SiteSetting.max_emojis_in_title == 0 + title = title.gsub(/:([\w\-+]+(?::t\d)?):/, '').strip + end + opts = { - title: I18n.t("#{I18N_KEY}.hello.title", title: SiteSetting.title), + title: title, target_usernames: @user.username, archetype: Archetype.private_message, subtype: TopicSubtype.system_message, diff --git a/plugins/discourse-narrative-bot/spec/user_spec.rb b/plugins/discourse-narrative-bot/spec/user_spec.rb index 86dde81499c..d0dba54a7ee 100644 --- a/plugins/discourse-narrative-bot/spec/user_spec.rb +++ b/plugins/discourse-narrative-bot/spec/user_spec.rb @@ -32,6 +32,21 @@ describe User do end end + context 'with title emoji disabled' do + before do + SiteSetting.disable_discourse_narrative_bot_welcome_post = false + SiteSetting.max_emojis_in_title = 0 + end + + it 'initiates the bot' do + expect { user }.to change { Topic.count }.by(1) + + expect(Topic.last.title).to eq(I18n.t( + 'discourse_narrative_bot.new_user_narrative.hello.title' + ).gsub(/:robot:/, '').strip) + end + end + context 'enabled' do before do SiteSetting.disable_discourse_narrative_bot_welcome_post = false