mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
FIX: TL2 promotion message and advance training (#10679)
This is a little bit of refactoring. Core Discourse should have default promotion message for TL2. In addition, when the Discobot plugin is enabled, the user is invited to advanced training
This commit is contained in:

committed by
GitHub

parent
8867bd4abe
commit
0bb51dcbfa
@ -33,7 +33,6 @@ after_initialize do
|
||||
'../autoload/jobs/narrative_timeout.rb',
|
||||
'../autoload/jobs/narrative_init.rb',
|
||||
'../autoload/jobs/send_default_welcome_message.rb',
|
||||
'../autoload/jobs/send_advanced_tutorial_message.rb',
|
||||
'../autoload/jobs/onceoff/grant_badges.rb',
|
||||
'../autoload/jobs/onceoff/remap_old_bot_images.rb',
|
||||
'../lib/discourse_narrative_bot/actions.rb',
|
||||
@ -282,25 +281,28 @@ after_initialize do
|
||||
end
|
||||
end
|
||||
|
||||
self.on(:user_promoted) do |args|
|
||||
promoted_from_tl1 = args[:new_trust_level] == TrustLevel[2] &&
|
||||
args[:old_trust_level] == TrustLevel[1]
|
||||
|
||||
if SiteSetting.discourse_narrative_bot_enabled && promoted_from_tl1
|
||||
# The event 'user_promoted' is sometimes called from inside a transaction.
|
||||
# Use this helper to ensure the job is enqueued after commit to prevent
|
||||
# any race conditions.
|
||||
DB.after_commit do
|
||||
Jobs.enqueue(:send_advanced_tutorial_message, user_id: args[:user_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
UserAvatar.register_custom_user_gravatar_email_hash(
|
||||
DiscourseNarrativeBot::BOT_USER_ID,
|
||||
"discobot@discourse.org"
|
||||
)
|
||||
|
||||
self.on(:system_message_sent) do |args|
|
||||
return if args[:message_type] != 'tl2_promotion_message'
|
||||
return if !SiteSetting.discourse_narrative_bot_enabled
|
||||
|
||||
raw = I18n.t("discourse_narrative_bot.tl2_promotion_message.text_body_template",
|
||||
discobot_username: ::DiscourseNarrativeBot::Base.new.discobot_username,
|
||||
reset_trigger: "#{::DiscourseNarrativeBot::TrackSelector.reset_trigger} #{::DiscourseNarrativeBot::AdvancedUserNarrative.reset_trigger}")
|
||||
|
||||
PostCreator.create!(
|
||||
::DiscourseNarrativeBot::Base.new.discobot_user,
|
||||
title: I18n.t("discourse_narrative_bot.tl2_promotion_message.subject_template"),
|
||||
raw: raw,
|
||||
topic_id: args[:post].topic_id,
|
||||
skip_validations: true
|
||||
)
|
||||
end
|
||||
|
||||
PostGuardian.class_eval do
|
||||
alias_method :existing_can_create_post?, :can_create_post?
|
||||
|
||||
|
Reference in New Issue
Block a user