DEV: adds post_created_edited suport to chat (#28757)

This commit is contained in:
Joffrey JAFFEUX
2024-09-05 17:17:18 +02:00
committed by GitHub
parent b7cfd4e146
commit 9b630c8cca
6 changed files with 135 additions and 2 deletions

View File

@ -12,6 +12,11 @@ module DiscourseAutomation
DiscourseAutomation::Automation
.where(trigger: name, enabled: true)
.find_each do |automation|
original_post_only = automation.trigger_field("original_post_only")
if original_post_only["value"]
next if topic.posts_count > 1
end
first_post_only = automation.trigger_field("first_post_only")
if first_post_only["value"]
next if post.user.user_stat.post_count != 1
@ -44,6 +49,11 @@ module DiscourseAutomation
next if !category_ids.include?(restricted_category["value"])
end
restricted_tags = automation.trigger_field("restricted_tags")
if restricted_tags["value"]
next if (restricted_tags["value"] & topic.tags.map(&:name)).empty?
end
restricted_group_id = automation.trigger_field("restricted_group")["value"]
if restricted_group_id.present?
next if !topic.private_message?
@ -66,7 +76,15 @@ module DiscourseAutomation
next if selected_action == :edited && action != :edit
end
automation.trigger!("kind" => name, "action" => action, "post" => post)
automation.trigger!(
"kind" => name,
"action" => action,
"post" => post,
"placeholders" => {
"topic_url" => topic.relative_url,
"topic_title" => topic.title,
},
)
end
end

View File

@ -13,11 +13,16 @@ DiscourseAutomation::Triggerable.add(DiscourseAutomation::Triggers::POST_CREATED
],
}
field :restricted_category, component: :category
field :restricted_tags, component: :tags
field :restricted_group, component: :group
field :ignore_automated, component: :boolean
field :ignore_group_members, component: :boolean
field :valid_trust_levels, component: :"trust-levels"
field :original_post_only, component: :boolean
field :first_post_only, component: :boolean
field :first_topic_only, component: :boolean
field :skip_via_email, component: :boolean
placeholder :topic_url
placeholder :topic_title
end