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

This issue was found via Discobot. In part of the tutorial
for Discobot, it asks for a URL on one line so it can demonstrate
how oneboxes work.

The way it does this when the user replies is to cook the
post raw and check if there is a cached onebox for the URL
in the post. However, if you reply really fast to Discobot
with the URL without waiting for the onebox to appear in the
composer preview, it's not cached by the time we do this
check in the Discobot code.

This commit fixes the issue by following a more simplified
approach, where we check for the existence of one of the
following links from the onebox instructions:

```
https://en.wikipedia.org/wiki/Inherently_funny_word
https://en.wikipedia.org/wiki/Death_by_coconut
https://en.wikipedia.org/wiki/Calculator_spelling
```

This will fall down if someone customizes the onebox
step text, or if the user uses a different link instead,
but we are willing to accept that risk at this time to simplify things.
This commit is contained in:
Martin Brennan
2025-02-25 12:41:37 +10:00
committed by GitHub
parent ae5ad250f6
commit 4eed96f511
2 changed files with 11 additions and 11 deletions

View File

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