FIX: Allow users to rename discobot without having to rebuild.
This commit is contained in:
parent
8268c98cf9
commit
7028bdceed
|
@ -1,11 +1,7 @@
|
|||
module DiscourseNarrativeBot
|
||||
module Actions
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
def self.discobot_user
|
||||
@discobot ||= User.find(-2)
|
||||
end
|
||||
def discobot_user
|
||||
@discobot ||= User.find(-2)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -18,11 +14,11 @@ module DiscourseNarrativeBot
|
|||
reply_to_post_number: post.post_number
|
||||
}
|
||||
|
||||
new_post = PostCreator.create!(self.class.discobot_user, default_opts.merge(opts))
|
||||
new_post = PostCreator.create!(self.discobot_user, default_opts.merge(opts))
|
||||
reset_rate_limits(post) if new_post
|
||||
new_post
|
||||
else
|
||||
PostCreator.create!(self.class.discobot_user, { raw: raw }.merge(opts))
|
||||
PostCreator.create!(self.discobot_user, { raw: raw }.merge(opts))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -64,7 +60,7 @@ module DiscourseNarrativeBot
|
|||
valid = false
|
||||
|
||||
doc.css(".mention").each do |mention|
|
||||
valid = true if mention.text == "@#{self.class.discobot_user.username}"
|
||||
valid = true if mention.text == "@#{self.discobot_user.username}"
|
||||
end
|
||||
|
||||
valid
|
||||
|
|
|
@ -124,7 +124,7 @@ module DiscourseNarrativeBot
|
|||
post = PostCreator.create!(@user, {
|
||||
raw: I18n.t(
|
||||
"#{I18N_KEY}.edit.bot_created_post_raw",
|
||||
discobot_username: self.class.discobot_user.username
|
||||
discobot_username: self.discobot_user.username
|
||||
),
|
||||
topic_id: data[:topic_id],
|
||||
skip_bot: true
|
||||
|
@ -140,7 +140,7 @@ module DiscourseNarrativeBot
|
|||
post = PostCreator.create!(@user, {
|
||||
raw: I18n.t(
|
||||
"#{I18N_KEY}.recover.deleted_post_raw",
|
||||
discobot_username: self.class.discobot_user.username
|
||||
discobot_username: self.discobot_user.username
|
||||
),
|
||||
topic_id: data[:topic_id],
|
||||
skip_bot: true
|
||||
|
@ -223,7 +223,7 @@ module DiscourseNarrativeBot
|
|||
#{instance_eval(&@next_instructions)}
|
||||
RAW
|
||||
|
||||
PostCreator.create!(self.class.discobot_user,
|
||||
PostCreator.create!(self.discobot_user,
|
||||
raw: raw,
|
||||
topic_id: @topic_id
|
||||
)
|
||||
|
@ -248,7 +248,7 @@ module DiscourseNarrativeBot
|
|||
#{instance_eval(&@next_instructions)}
|
||||
RAW
|
||||
|
||||
PostCreator.create!(self.class.discobot_user,
|
||||
PostCreator.create!(self.discobot_user,
|
||||
raw: raw,
|
||||
topic_id: @post.topic_id
|
||||
)
|
||||
|
@ -306,7 +306,7 @@ module DiscourseNarrativeBot
|
|||
|
||||
fake_delay
|
||||
|
||||
post = PostCreator.create!(self.class.discobot_user,
|
||||
post = PostCreator.create!(self.discobot_user,
|
||||
raw: raw,
|
||||
topic_id: @topic_id
|
||||
)
|
||||
|
|
|
@ -40,7 +40,7 @@ module DiscourseNarrativeBot
|
|||
tutorial_emoji: {
|
||||
next_state: :tutorial_mention,
|
||||
next_instructions: Proc.new {
|
||||
I18n.t("#{I18N_KEY}.mention.instructions", discobot_username: self.class.discobot_user.username)
|
||||
I18n.t("#{I18N_KEY}.mention.instructions", discobot_username: self.discobot_user.username)
|
||||
},
|
||||
reply: {
|
||||
action: :reply_to_emoji
|
||||
|
@ -148,7 +148,7 @@ module DiscourseNarrativeBot
|
|||
RAW
|
||||
|
||||
PostRevisor.new(post, topic).revise!(
|
||||
self.class.discobot_user,
|
||||
self.discobot_user,
|
||||
{ raw: raw },
|
||||
{ skip_validations: true, force_new_version: true }
|
||||
)
|
||||
|
@ -201,7 +201,7 @@ module DiscourseNarrativeBot
|
|||
|
||||
def missing_bookmark
|
||||
return unless valid_topic?(@post.topic_id)
|
||||
return if @post.user_id == self.class.discobot_user.id
|
||||
return if @post.user_id == self.discobot_user.id
|
||||
|
||||
fake_delay
|
||||
enqueue_timeout_job(@user)
|
||||
|
@ -211,7 +211,7 @@ module DiscourseNarrativeBot
|
|||
|
||||
def reply_to_bookmark
|
||||
return unless valid_topic?(@post.topic_id)
|
||||
return unless @post.user_id == self.class.discobot_user.id
|
||||
return unless @post.user_id == self.discobot_user.id
|
||||
|
||||
raw = <<~RAW
|
||||
#{I18n.t("#{I18N_KEY}.bookmark.reply", profile_page_url: url_helpers(:user_url, username: @user.username))}
|
||||
|
@ -434,7 +434,7 @@ module DiscourseNarrativeBot
|
|||
reply_to(@post, I18n.t(
|
||||
"#{I18N_KEY}.mention.not_found",
|
||||
username: @user.username,
|
||||
discobot_username: self.class.discobot_user.username
|
||||
discobot_username: self.discobot_user.username
|
||||
))
|
||||
end
|
||||
|
||||
|
@ -496,7 +496,7 @@ module DiscourseNarrativeBot
|
|||
username: @user.username,
|
||||
base_url: Discourse.base_url,
|
||||
certificate: certificate,
|
||||
discobot_username: self.class.discobot_user.username,
|
||||
discobot_username: self.discobot_user.username,
|
||||
advanced_trigger: AdvancedUserNarrative.reset_trigger
|
||||
),
|
||||
topic_id: @data[:topic_id]
|
||||
|
@ -504,7 +504,7 @@ module DiscourseNarrativeBot
|
|||
end
|
||||
|
||||
def like_post(post)
|
||||
PostAction.act(self.class.discobot_user, post, PostActionType.types[:like])
|
||||
PostAction.act(self.discobot_user, post, PostActionType.types[:like])
|
||||
end
|
||||
|
||||
def welcome_topic
|
||||
|
|
|
@ -136,7 +136,7 @@ module DiscourseNarrativeBot
|
|||
help_message
|
||||
elsif hint
|
||||
message = I18n.t(self.class.i18n_key('random_mention.reply'),
|
||||
discobot_username: self.class.discobot_user.username,
|
||||
discobot_username: self.discobot_user.username,
|
||||
help_trigger: self.class.help_trigger
|
||||
)
|
||||
|
||||
|
@ -172,7 +172,7 @@ module DiscourseNarrativeBot
|
|||
tracks << AdvancedUserNarrative.reset_trigger
|
||||
end
|
||||
|
||||
discobot_username = self.class.discobot_user.username
|
||||
discobot_username = self.discobot_user.username
|
||||
|
||||
message = I18n.t(
|
||||
self.class.i18n_key('random_mention.tracks'),
|
||||
|
@ -227,7 +227,7 @@ module DiscourseNarrativeBot
|
|||
if pm_to_bot?(@post)
|
||||
post_raw = @post.raw
|
||||
|
||||
post_raw.match(/^@#{self.class.discobot_user.username} #{self.class.skip_trigger}/i) ||
|
||||
post_raw.match(/^@#{self.discobot_user.username} #{self.class.skip_trigger}/i) ||
|
||||
post_raw.strip == self.class.skip_trigger
|
||||
else
|
||||
false
|
||||
|
@ -235,7 +235,7 @@ module DiscourseNarrativeBot
|
|||
end
|
||||
|
||||
def match_trigger?(trigger)
|
||||
discobot_username = self.class.discobot_user.username
|
||||
discobot_username = self.discobot_user.username
|
||||
regexp = Regexp.new("<a class=\"mention\".*>@#{discobot_username}</a> #{trigger}", 'i')
|
||||
match = @post.cooked.match(regexp)
|
||||
|
||||
|
@ -248,13 +248,13 @@ module DiscourseNarrativeBot
|
|||
|
||||
def like_user_post
|
||||
if @post.raw.match(/thank/i)
|
||||
PostAction.act(self.class.discobot_user, @post, PostActionType.types[:like])
|
||||
PostAction.act(self.discobot_user, @post, PostActionType.types[:like])
|
||||
end
|
||||
end
|
||||
|
||||
def bot_mentioned?
|
||||
@bot_mentioned ||= PostAnalyzer.new(@post.raw, @post.topic_id).raw_mentions.include?(
|
||||
self.class.discobot_user.username
|
||||
self.discobot_user.username
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -230,7 +230,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
|
|||
end
|
||||
|
||||
it 'should create the right reply' do
|
||||
post.update!(user: described_class.discobot_user)
|
||||
post.update!(user: discobot_user)
|
||||
narrative.expects(:enqueue_timeout_job).with(user)
|
||||
|
||||
narrative.input(:bookmark, user, post: post)
|
||||
|
@ -402,7 +402,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
|
|||
post_action = PostAction.last
|
||||
|
||||
expect(post_action.post_action_type_id).to eq(PostActionType.types[:like])
|
||||
expect(post_action.user).to eq(described_class.discobot_user)
|
||||
expect(post_action.user).to eq(discobot_user)
|
||||
expect(post_action.post).to eq(new_post)
|
||||
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_flag)
|
||||
end
|
||||
|
@ -456,7 +456,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
|
|||
post_action = PostAction.last
|
||||
|
||||
expect(post_action.post_action_type_id).to eq(PostActionType.types[:like])
|
||||
expect(post_action.user).to eq(described_class.discobot_user)
|
||||
expect(post_action.user).to eq(discobot_user)
|
||||
expect(post_action.post).to eq(new_post)
|
||||
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_flag)
|
||||
end
|
||||
|
@ -728,7 +728,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
|
|||
end
|
||||
|
||||
describe 'flag tutorial' do
|
||||
let(:post) { Fabricate(:post, user: described_class.discobot_user, topic: topic) }
|
||||
let(:post) { Fabricate(:post, user: discobot_user, topic: topic) }
|
||||
let(:flag) { Fabricate(:flag, post: post, user: user) }
|
||||
let(:other_post) { Fabricate(:post, user: user, topic: topic) }
|
||||
|
||||
|
@ -833,7 +833,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
|
|||
end
|
||||
|
||||
describe 'when post contain the right answer' do
|
||||
let(:post) { Fabricate(:post, user: described_class.discobot_user, topic: topic) }
|
||||
let(:post) { Fabricate(:post, user: discobot_user, topic: topic) }
|
||||
let(:flag) { Fabricate(:flag, post: post, user: user) }
|
||||
|
||||
before do
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
|||
|
||||
describe DiscourseNarrativeBot::TrackSelector do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:discobot_user) { described_class.discobot_user }
|
||||
let(:discobot_user) { User.find(-2) }
|
||||
let(:narrative) { DiscourseNarrativeBot::NewUserNarrative.new }
|
||||
|
||||
let(:random_mention_reply) do
|
||||
|
|
Loading…
Reference in New Issue