FIX: Wrong discobot tutorial started for certain locales.
If a locale has triggers that start with the same word, our regexp will always end up matching the first trigger. For example, `start tutorial` and `start tutorial advanced` To support the change, we have to make the match on triggers more restrictive. `@discobot quote here` will no longer work like `@discobot quote`.
This commit is contained in:
parent
b574276e6e
commit
636b6c3a5a
|
@ -227,7 +227,7 @@ module DiscourseNarrativeBot
|
|||
|
||||
def match_trigger?(trigger)
|
||||
discobot_username = self.discobot_user.username
|
||||
regexp = Regexp.new("<a class=\"mention\".*>@#{discobot_username}</a> #{trigger}", 'i')
|
||||
regexp = Regexp.new("<a class=\"mention\".*>@#{discobot_username}</a> #{trigger}</p>", 'i')
|
||||
match = @post.cooked.match(regexp)
|
||||
|
||||
if @is_pm_to_bot
|
||||
|
|
|
@ -580,8 +580,7 @@ describe DiscourseNarrativeBot::TrackSelector 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\"}")
|
||||
|
||||
['@discobot quote', 'hello @discobot quote there'].each do |raw|
|
||||
post.update!(raw: raw)
|
||||
post.update!(raw: "@discobot quote")
|
||||
described_class.new(:reply, user, post_id: post.id).select
|
||||
new_post = Post.last
|
||||
|
||||
|
@ -590,7 +589,6 @@ describe DiscourseNarrativeBot::TrackSelector do
|
|||
quote: "Be Like Water", author: "Bruce Lee"
|
||||
))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when quote is requested incorrectly' do
|
||||
it 'should create the right reply' do
|
||||
|
@ -661,6 +659,32 @@ describe DiscourseNarrativeBot::TrackSelector do
|
|||
end.to_not change { Post.count }
|
||||
end
|
||||
end
|
||||
|
||||
describe "when new and advanced user triggers overlap" do
|
||||
before do
|
||||
@overrides = []
|
||||
|
||||
@overrides << TranslationOverride.upsert!(
|
||||
I18n.locale, 'discourse_narrative_bot.new_user_narrative.reset_trigger', 'tutorial'
|
||||
)
|
||||
|
||||
@overrides << TranslationOverride.upsert!(
|
||||
I18n.locale, 'discourse_narrative_bot.advanced_user_narrative.reset_trigger', 'tutorial advanced'
|
||||
)
|
||||
end
|
||||
|
||||
after do
|
||||
@overrides.each(&:destroy!)
|
||||
end
|
||||
|
||||
it "should start the right track" do
|
||||
post.update!(raw: "@discobot #{I18n.t('discourse_narrative_bot.track_selector.reset_trigger')} #{DiscourseNarrativeBot::AdvancedUserNarrative.reset_trigger}")
|
||||
|
||||
expect do
|
||||
described_class.new(:reply, user, post_id: post.id).select
|
||||
end.to change { Post.count }.by(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue