Skip to content

A platform for community discussion. Free, open, simple.

FIX: allow extra whitespace when asking discobot to perform a bot command (#17738)

Mayfield542cd1ff90ed
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 2ac5f733647..039b4b15486 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
@@ -227,7 +227,7 @@ module DiscourseNarrativeBot
@@cooked_triggers = {}
def cook(trigger)
- @@cooked_triggers[trigger] ||= PrettyText.cook("@#{self.discobot_username} #{trigger}")
+ @@cooked_triggers[trigger] ||= PrettyText.cook("@#{self.discobot_username}\\s+#{trigger}")
end
def match_trigger?(trigger)
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 543192f6cfc..36905b777f9 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
@@ -591,6 +591,17 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
))
end
+ it 'should ignore extra whitespace proceeding the mention' do
+ post.update!(raw: '@discobot roll 2d1')
+ 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.dice.results",
+ results: '1, 1'
+ ))
+ end
+
context 'when dice roll is requested incorrectly' do
it 'should create the right reply' do
post.update!(raw: 'roll 2d1 @discobot')