FIX: adds post_quote as placeholder (#29083)

The script `send_chat_message` when used with the `post_created_edited` trigger now accepts `{{post_quote}}` as placeholder for the value of `message`.

This is made possible by a new method in `utils`. Usage:

```ruby
  placeholders["foo"] = utils.build_quote(post)
```
This commit is contained in:
Joffrey JAFFEUX
2024-10-08 21:55:11 +09:00
committed by GitHub
parent 9825bde811
commit 268213a93c
4 changed files with 104 additions and 8 deletions

View File

@ -205,6 +205,26 @@ module DiscourseAutomation
end
end
def self.build_quote(post)
return "" if post.nil? || post.raw.nil?
full_name = post.user.name
name =
if SiteSetting.display_name_on_posts && !SiteSetting.prioritize_username_in_ux
full_name || post.username
else
post.username
end
params = [name, "post:#{post.post_number}", "topic:#{post.topic_id}"]
if SiteSetting.display_name_on_posts && !SiteSetting.prioritize_username_in_ux && full_name
params.push("username:#{post.username}")
end
"[quote=#{params.join(", ")}]\n#{post.raw.strip}\n[/quote]\n\n"
end
def self.send_pm(
pm,
sender: Discourse.system_user.username,