mirror of
https://github.com/discourse/discourse.git
synced 2024-12-27 21:15:59 +08:00
24 lines
676 B
Ruby
24 lines
676 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scripts::BANNER_TOPIC) do
|
||
|
field :topic_id, component: :text, required: true
|
||
|
field :banner_until, component: :date_time
|
||
|
field :user, component: :user
|
||
|
|
||
|
version 1
|
||
|
|
||
|
triggerables [:point_in_time]
|
||
|
|
||
|
script do |_, fields|
|
||
|
next unless topic_id = fields.dig("topic_id", "value")
|
||
|
next unless topic = Topic.find_by(id: topic_id)
|
||
|
|
||
|
banner_until = fields.dig("banner_until", "value") || nil
|
||
|
|
||
|
username = fields.dig("user", "value") || Discourse.system_user.username
|
||
|
next unless user = User.find_by(username: username)
|
||
|
|
||
|
topic.make_banner!(user, banner_until)
|
||
|
end
|
||
|
end
|