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

This commit is contained in:
Mayfield 2022-08-18 13:32:30 -04:00 committed by GitHub
parent 6e682cc7c4
commit 542cd1ff90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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)

View File

@ -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')