mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
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
This commit is contained in:
parent
a4b89f8187
commit
c63e84dc62
|
@ -74,6 +74,7 @@ class Promotion
|
|||
@user.save!
|
||||
@user.user_profile.recook_bio
|
||||
@user.user_profile.save!
|
||||
DiscourseEvent.trigger(:user_promoted, user_id: @user.id, new_trust_level: new_level, old_trust_level: old_level)
|
||||
Group.user_trust_level_change!(@user.id, @user.trust_level)
|
||||
BadgeGranter.queue_badge_grant(Badge::Trigger::TrustLevelChange, user: @user)
|
||||
end
|
||||
|
@ -141,5 +142,4 @@ class Promotion
|
|||
user.change_trust_level!(2, log_action_for: performed_by || Discourse.system_user)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Jobs
|
||||
class SendAdvancedTutorialMessage < ::Jobs::Base
|
||||
def execute(args)
|
||||
user = User.find_by(id: args[:user_id])
|
||||
raise Discourse::InvalidParameters.new(:user_id) if user.nil?
|
||||
|
||||
PostCreator.create!(
|
||||
Discourse.system_user,
|
||||
title: I18n.t("discourse_narrative_bot.tl2_promotion_message.subject_template"),
|
||||
raw: I18n.t("discourse_narrative_bot.tl2_promotion_message.text_body_template"),
|
||||
archetype: Archetype.private_message,
|
||||
target_usernames: user.username,
|
||||
skip_validations: true
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,7 +9,7 @@ module Jobs
|
|||
|
||||
title = I18n.t("system_messages.#{type}.subject_template", params)
|
||||
raw = I18n.t("system_messages.#{type}.text_body_template", params)
|
||||
discobot_user = User.find(-2)
|
||||
discobot_user = ::DiscourseNarrativeBot::Base.new.discobot_user
|
||||
|
||||
post = PostCreator.create!(
|
||||
discobot_user,
|
||||
|
|
|
@ -22,6 +22,15 @@ en:
|
|||
discourse_narrative_bot:
|
||||
bio: "Hi, I’m not a real person. I’m a bot that can teach you about this site. To interact with me, send me a message or mention **`@%{discobot_username}`** anywhere."
|
||||
|
||||
tl2_promotion_message:
|
||||
subject_template: "Congratulations on your trust level promotion!"
|
||||
text_body_template: |
|
||||
Now that you’ve been promoted, it’s time to learn about some advanced features!
|
||||
|
||||
Reply to this message with `@discobot start advanced tutorial` to find out more about what you can do.
|
||||
|
||||
We invite you to keep getting involved – we enjoy having you around.
|
||||
|
||||
timeout:
|
||||
message: |-
|
||||
Hey @%{username}, just checking in because I haven’t heard from you in a while.
|
||||
|
|
|
@ -18,7 +18,7 @@ module DiscourseNarrativeBot
|
|||
end
|
||||
|
||||
@date = I18n.l(date, format: :date_only)
|
||||
@discobot_user = User.find(-2)
|
||||
@discobot_user = ::DiscourseNarrativeBot::Base.new.discobot_user
|
||||
end
|
||||
|
||||
def new_user_track
|
||||
|
|
|
@ -33,6 +33,7 @@ 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',
|
||||
|
@ -245,4 +246,13 @@ 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
|
||||
Jobs.enqueue(:send_advanced_tutorial_message, user_id: args[:user_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
|
||||
let(:discobot_user) { User.find(-2) }
|
||||
let(:discobot_user) { ::DiscourseNarrativeBot::Base.new.discobot_user }
|
||||
let(:first_post) { Fabricate(:post, user: discobot_user) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
|||
|
||||
describe DiscourseNarrativeBot::NewUserNarrative do
|
||||
let!(:welcome_topic) { Fabricate(:topic, title: 'Welcome to Discourse') }
|
||||
let(:discobot_user) { User.find(-2) }
|
||||
let(:discobot_user) { ::DiscourseNarrativeBot::Base.new.discobot_user }
|
||||
let(:first_post) { Fabricate(:post, user: discobot_user) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
|||
|
||||
describe DiscourseNarrativeBot::TrackSelector do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:discobot_user) { User.find(-2) }
|
||||
let(:discobot_user) { ::DiscourseNarrativeBot::Base.new.discobot_user }
|
||||
let(:narrative) { DiscourseNarrativeBot::NewUserNarrative.new }
|
||||
|
||||
let(:random_mention_reply) do
|
||||
|
|
|
@ -6,7 +6,7 @@ RSpec.describe Jobs::DiscourseNarrativeBot::RemapOldBotImages do
|
|||
context "when bot's post contains an old link" do
|
||||
let(:post) do
|
||||
Fabricate(:post,
|
||||
user: User.find(-2),
|
||||
user: ::DiscourseNarrativeBot::Base.new.discobot_user,
|
||||
raw: 'If you’d like to learn more, select <img src="/images/font-awesome-gear.png" width="16" height="16"> <img src="/images/font-awesome-ellipsis.png" width="16" height="16"> below and <img src="/images/font-awesome-bookmark.png" width="16" height="16"> **bookmark this private message**. If you do, there may be a :gift: in your future!'
|
||||
)
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ RSpec.describe Jobs::DiscourseNarrativeBot::RemapOldBotImages do
|
|||
context 'subfolder' do
|
||||
let(:post) do
|
||||
Fabricate(:post,
|
||||
user: User.find(-2),
|
||||
user: ::DiscourseNarrativeBot::Base.new.discobot_user,
|
||||
raw: 'If you’d like to learn more, select <img src="/community/images/font-awesome-ellipsis.png" width="16" height="16"> below and <img src="/community/images/font-awesome-bookmark.png" width="16" height="16"> **bookmark this private message**. If you do, there may be a :gift: in your future!'
|
||||
)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Jobs::SendAdvancedTutorialMessage do
|
||||
before do
|
||||
Jobs.run_immediately!
|
||||
SiteSetting.discourse_narrative_bot_enabled = true
|
||||
end
|
||||
|
||||
it 'sends a message to the promoted user' do
|
||||
user = Fabricate(:user)
|
||||
discobot_user = Discourse.system_user
|
||||
Jobs.enqueue(:send_advanced_tutorial_message, user_id: user.id)
|
||||
|
||||
topic = Topic.last
|
||||
|
||||
expect(topic).not_to be_nil
|
||||
expect(topic.user).to eq(discobot_user)
|
||||
expect(topic.archetype).to eq(Archetype.private_message)
|
||||
expect(topic.topic_allowed_users.pluck(:user_id)).to contain_exactly(
|
||||
discobot_user.id, user.id
|
||||
)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user