Skip to content

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

FIX: Discobot onebox step sometimes not working (#31472)

Martin Brennan4eed96f51166
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 918ed69e0a1..d7c7cd4b3cb 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
@@ -269,9 +269,15 @@ module DiscourseNarrativeBot
post_topic_id = @post.topic_id
return unless valid_topic?(post_topic_id)
- @post.post_analyzer.cook(@post.raw, {})
+ # NOTE: This can be a bit brittle if people change the site text for
+ # discourse_narrative_bot.new_user_narrative.onebox.instructions, or if
+ # the user drops some other random link, but we accept that risk for now.
+ found_link =
+ @post.raw.match(
+ %r{https://en\.wikipedia\.org/wiki/(Inherently_funny_word|Death_by_coconut|Calculator_spelling)},
+ )
- if @post.post_analyzer.found_oneboxes?
+ if found_link
raw = <<~MD
#{I18n.t("#{I18N_KEY}.onebox.reply", i18n_post_args)}
diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
index 2fd1ed52605..605ba34cdce 100644
--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
@@ -338,13 +338,7 @@ RSpec.describe DiscourseNarrativeBot::NewUserNarrative do
end
describe "onebox tutorial" do
- before do
- Oneboxer
- .stubs(:cached_onebox)
- .with("https://en.wikipedia.org/wiki/ROT13")
- .returns("oneboxed Wikipedia")
- narrative.set_data(user, state: :tutorial_onebox, topic_id: topic.id)
- end
+ before { narrative.set_data(user, state: :tutorial_onebox, topic_id: topic.id) }
describe "when post is not in the right topic" do
it "should not do anything" do
@@ -404,7 +398,7 @@ RSpec.describe DiscourseNarrativeBot::NewUserNarrative do
before { SiteSetting.enable_emoji = false }
it "should create the right reply" do
- post.update!(raw: "https://en.wikipedia.org/wiki/ROT13")
+ post.update!(raw: "https://en.wikipedia.org/wiki/Death_by_coconut")
narrative.input(:reply, user, post: post)
new_post = Post.last
@@ -427,7 +421,7 @@ RSpec.describe DiscourseNarrativeBot::NewUserNarrative do
end
it "should create the right reply" do
- post.update!(raw: "https://en.wikipedia.org/wiki/ROT13")
+ post.update!(raw: "https://en.wikipedia.org/wiki/Death_by_coconut")
narrative.expects(:enqueue_timeout_job).with(user)
narrative.input(:reply, user, post: post)