discourse/plugins/discourse-narrative-bot/autoload/jobs/send_default_welcome_message.rb
Roman Rizzi c63e84dc62
FEATURE: Send a message to new TL2 users and point them to the advanced tutorial (#8335)
* FEATURE: Send a message to new TL2 users and point them to the advanced tutorial

* DEV: Use a method to find the discobot user
2019-11-13 18:31:49 -03:00

28 lines
836 B
Ruby

# frozen_string_literal: true
module Jobs
class SendDefaultWelcomeMessage < ::Jobs::Base
def execute(args)
if user = User.find_by(id: args[:user_id])
type = user.invited_by ? 'welcome_invite' : 'welcome_user'
params = SystemMessage.new(user).defaults
title = I18n.t("system_messages.#{type}.subject_template", params)
raw = I18n.t("system_messages.#{type}.text_body_template", params)
discobot_user = ::DiscourseNarrativeBot::Base.new.discobot_user
post = PostCreator.create!(
discobot_user,
title: title,
raw: raw,
archetype: Archetype.private_message,
target_usernames: user.username,
skip_validations: true
)
post.topic.update_status('closed', true, discobot_user)
end
end
end
end