2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
require 'distributed_mutex'
|
|
|
|
|
|
|
|
module DiscourseNarrativeBot
|
|
|
|
class NewUserNarrative < Base
|
|
|
|
I18N_KEY = "discourse_narrative_bot.new_user_narrative".freeze
|
|
|
|
BADGE_NAME = 'Certified'.freeze
|
|
|
|
|
|
|
|
TRANSITION_TABLE = {
|
|
|
|
begin: {
|
|
|
|
init: {
|
|
|
|
next_state: :tutorial_bookmark,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.bookmark.instructions", base_uri: Discourse.base_uri) },
|
2017-05-24 01:50:20 -04:00
|
|
|
action: :say_hello
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_bookmark: {
|
|
|
|
next_state: :tutorial_onebox,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.onebox.instructions", base_uri: Discourse.base_uri) },
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
bookmark: {
|
|
|
|
action: :reply_to_bookmark
|
|
|
|
},
|
|
|
|
|
|
|
|
reply: {
|
|
|
|
next_state: :tutorial_bookmark,
|
|
|
|
action: :missing_bookmark
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_onebox: {
|
|
|
|
next_state: :tutorial_emoji,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.emoji.instructions", base_uri: Discourse.base_uri) },
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_onebox
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_emoji: {
|
2017-07-13 02:12:45 -04:00
|
|
|
prerequisite: Proc.new { SiteSetting.enable_emoji },
|
2017-05-24 01:50:20 -04:00
|
|
|
next_state: :tutorial_mention,
|
|
|
|
next_instructions: Proc.new {
|
2017-06-01 15:15:22 -04:00
|
|
|
I18n.t("#{I18N_KEY}.mention.instructions",
|
|
|
|
discobot_username: self.discobot_user.username,
|
|
|
|
base_uri: Discourse.base_uri)
|
2017-05-24 01:50:20 -04:00
|
|
|
},
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_emoji
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_mention: {
|
2018-08-23 02:58:07 -04:00
|
|
|
prerequisite: Proc.new { SiteSetting.enable_mentions },
|
2017-05-24 01:50:20 -04:00
|
|
|
next_state: :tutorial_formatting,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.formatting.instructions", base_uri: Discourse.base_uri) },
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_mention
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_formatting: {
|
|
|
|
next_state: :tutorial_quote,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.quoting.instructions", base_uri: Discourse.base_uri) },
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_formatting
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_quote: {
|
|
|
|
next_state: :tutorial_images,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.images.instructions", base_uri: Discourse.base_uri) },
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_quote
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_images: {
|
|
|
|
next_state: :tutorial_flag,
|
|
|
|
next_instructions: Proc.new {
|
|
|
|
I18n.t("#{I18N_KEY}.flag.instructions",
|
|
|
|
guidelines_url: url_helpers(:guidelines_url),
|
2017-06-01 15:15:22 -04:00
|
|
|
about_url: url_helpers(:about_index_url),
|
|
|
|
base_uri: Discourse.base_uri)
|
2017-05-24 01:50:20 -04:00
|
|
|
},
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_image
|
|
|
|
},
|
|
|
|
like: {
|
|
|
|
action: :track_like
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_flag: {
|
2018-09-06 20:33:27 -04:00
|
|
|
prerequisite: Proc.new { SiteSetting.allow_flagging_staff },
|
2017-05-24 01:50:20 -04:00
|
|
|
next_state: :tutorial_search,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.search.instructions", base_uri: Discourse.base_uri) },
|
2017-05-24 01:50:20 -04:00
|
|
|
flag: {
|
|
|
|
action: :reply_to_flag
|
|
|
|
},
|
|
|
|
reply: {
|
|
|
|
next_state: :tutorial_flag,
|
|
|
|
action: :missing_flag
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_search: {
|
|
|
|
next_state: :end,
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_search
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-16 14:36:54 -04:00
|
|
|
def self.search_answer
|
|
|
|
':herb:'
|
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
def self.reset_trigger
|
|
|
|
I18n.t('discourse_narrative_bot.new_user_narrative.reset_trigger')
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_bot(user, post)
|
|
|
|
if pm_to_bot?(post)
|
2017-07-27 21:20:09 -04:00
|
|
|
reset_data(user, topic_id: post.topic_id)
|
2017-05-24 01:50:20 -04:00
|
|
|
else
|
|
|
|
reset_data(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
Jobs.enqueue_in(2.seconds, :narrative_init, user_id: user.id, klass: self.class.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def synchronize(user)
|
|
|
|
if Rails.env.test?
|
|
|
|
yield
|
|
|
|
else
|
|
|
|
DistributedMutex.synchronize("new_user_narrative_#{user.id}") { yield }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def init_tutorial_search
|
|
|
|
topic = @post.topic
|
|
|
|
post = topic.first_post
|
|
|
|
|
|
|
|
MessageBus.publish('/new_user_narrative/tutorial_search', {}, user_ids: [@user.id])
|
|
|
|
|
|
|
|
raw = <<~RAW
|
|
|
|
#{post.raw}
|
|
|
|
|
2019-10-16 14:36:54 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.search.hidden_message", i18n_post_args.merge(search_answer: NewUserNarrative.search_answer))}
|
2017-05-24 01:50:20 -04:00
|
|
|
RAW
|
|
|
|
|
|
|
|
PostRevisor.new(post, topic).revise!(
|
2017-05-25 22:09:42 -04:00
|
|
|
self.discobot_user,
|
2017-05-24 01:50:20 -04:00
|
|
|
{ raw: raw },
|
2017-07-27 21:20:09 -04:00
|
|
|
skip_validations: true, force_new_version: true
|
2017-05-24 01:50:20 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
set_state_data(:post_version, post.reload.version || 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def clean_up_tutorial_search
|
|
|
|
first_post = @post.topic.first_post
|
|
|
|
first_post.revert_to(get_state_data(:post_version) - 1)
|
|
|
|
first_post.save!
|
|
|
|
first_post.publish_change_to_clients!(:revised)
|
|
|
|
end
|
|
|
|
|
|
|
|
def say_hello
|
|
|
|
raw = I18n.t(
|
|
|
|
"#{I18N_KEY}.hello.message",
|
2017-06-01 15:15:22 -04:00
|
|
|
i18n_post_args(
|
|
|
|
username: @user.username,
|
|
|
|
title: SiteSetting.title
|
|
|
|
)
|
2017-05-24 01:50:20 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
raw = <<~RAW
|
|
|
|
#{raw}
|
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
|
|
|
RAW
|
|
|
|
|
2018-03-27 12:00:29 -04:00
|
|
|
title = I18n.t("#{I18N_KEY}.hello.title", title: SiteSetting.title)
|
|
|
|
if SiteSetting.max_emojis_in_title == 0
|
|
|
|
title = title.gsub(/:([\w\-+]+(?::t\d)?):/, '').strip
|
|
|
|
end
|
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
opts = {
|
2018-03-27 12:00:29 -04:00
|
|
|
title: title,
|
2017-05-24 01:50:20 -04:00
|
|
|
target_usernames: @user.username,
|
2017-07-12 16:00:18 -04:00
|
|
|
archetype: Archetype.private_message,
|
|
|
|
subtype: TopicSubtype.system_message,
|
2017-05-24 01:50:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if @post &&
|
2018-03-05 02:38:05 -05:00
|
|
|
@post.topic.private_message? &&
|
2017-05-24 01:50:20 -04:00
|
|
|
@post.topic.topic_allowed_users.pluck(:user_id).include?(@user.id)
|
|
|
|
|
|
|
|
opts = opts.merge(topic_id: @post.topic_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
if @data[:topic_id]
|
2020-02-24 09:55:12 -05:00
|
|
|
opts = opts
|
|
|
|
.merge(topic_id: @data[:topic_id])
|
|
|
|
.except(:title, :target_usernames, :archetype)
|
2017-05-24 01:50:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
post = reply_to(@post, raw, opts)
|
|
|
|
@data[:topic_id] = post.topic.id
|
|
|
|
@data[:track] = self.class.to_s
|
|
|
|
post
|
|
|
|
end
|
|
|
|
|
|
|
|
def missing_bookmark
|
|
|
|
return unless valid_topic?(@post.topic_id)
|
2017-05-25 22:09:42 -04:00
|
|
|
return if @post.user_id == self.discobot_user.id
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
fake_delay
|
|
|
|
enqueue_timeout_job(@user)
|
2017-06-01 15:15:22 -04:00
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.bookmark.not_found", i18n_post_args)) unless @data[:attempted]
|
2017-05-24 01:50:20 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_bookmark
|
|
|
|
return unless valid_topic?(@post.topic_id)
|
2017-05-25 22:09:42 -04:00
|
|
|
return unless @post.user_id == self.discobot_user.id
|
2017-05-24 01:50:20 -04:00
|
|
|
|
2020-03-26 22:17:18 -04:00
|
|
|
profile_page_url = url_helpers(:user_url, username: @user.username)
|
|
|
|
bookmark_url = if SiteSetting.enable_bookmarks_with_reminders?
|
|
|
|
"#{profile_page_url}/activity/bookmarks-with-reminders"
|
|
|
|
else
|
|
|
|
"#{profile_page_url}/activity/bookmarks"
|
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
raw = <<~RAW
|
2020-03-26 22:17:18 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.bookmark.reply", i18n_post_args(bookmark_url: bookmark_url))}
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
|
|
|
RAW
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
reply = reply_to(@post, raw)
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
reply
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_onebox
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
|
|
|
@post.post_analyzer.cook(@post.raw, {})
|
|
|
|
|
|
|
|
if @post.post_analyzer.found_oneboxes?
|
|
|
|
raw = <<~RAW
|
2017-06-01 15:15:22 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.onebox.reply", i18n_post_args)}
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
|
|
|
RAW
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
reply = reply_to(@post, raw)
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
reply
|
|
|
|
else
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.onebox.not_found", i18n_post_args)) unless @data[:attempted]
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def track_like
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
|
|
|
post_liked = PostAction.find_by(
|
|
|
|
post_action_type_id: PostActionType.types[:like],
|
|
|
|
post_id: @data[:last_post_id],
|
|
|
|
user_id: @user.id
|
|
|
|
)
|
|
|
|
|
|
|
|
if post_liked
|
|
|
|
set_state_data(:liked, true)
|
|
|
|
|
|
|
|
if (post_id = get_state_data(:post_id)) && (post = Post.find_by(id: post_id))
|
|
|
|
fake_delay
|
|
|
|
like_post(post)
|
|
|
|
|
|
|
|
raw = <<~RAW
|
2017-06-01 15:15:22 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.images.reply", i18n_post_args)}
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
|
|
|
RAW
|
|
|
|
|
|
|
|
reply = reply_to(@post, raw)
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
return reply
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_image
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
|
|
|
transition = true
|
|
|
|
attempted_count = get_state_data(:attempted) || 0
|
|
|
|
|
|
|
|
if attempted_count < 2
|
|
|
|
@data[:skip_attempted] = true
|
|
|
|
@data[:attempted] = false
|
|
|
|
else
|
|
|
|
@data[:skip_attempted] = false
|
|
|
|
end
|
|
|
|
|
2018-11-14 21:51:17 -05:00
|
|
|
cooked = @post.post_analyzer.cook(@post.raw, {})
|
|
|
|
|
|
|
|
if Nokogiri::HTML.fragment(cooked).css("img").size > 0
|
2017-05-24 01:50:20 -04:00
|
|
|
set_state_data(:post_id, @post.id)
|
|
|
|
|
|
|
|
if get_state_data(:liked)
|
|
|
|
raw = <<~RAW
|
2017-06-01 15:15:22 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.images.reply", i18n_post_args)}
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
|
|
|
RAW
|
|
|
|
|
|
|
|
like_post(@post)
|
|
|
|
else
|
|
|
|
raw = I18n.t(
|
|
|
|
"#{I18N_KEY}.images.like_not_found",
|
2017-06-01 15:15:22 -04:00
|
|
|
i18n_post_args(url: Post.find_by(id: @data[:last_post_id]).url)
|
2017-05-24 01:50:20 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
transition = false
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raw = I18n.t(
|
|
|
|
"#{I18N_KEY}.images.not_found",
|
2017-10-10 01:46:58 -04:00
|
|
|
i18n_post_args(image_url: "#{Discourse.base_url}/plugins/discourse-narrative-bot/images/dog-walk.gif")
|
2017-05-24 01:50:20 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
transition = false
|
|
|
|
end
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
set_state_data(:attempted, attempted_count + 1) if !transition
|
|
|
|
reply = reply_to(@post, raw) unless @data[:attempted] && !transition
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
transition ? reply : false
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_formatting
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
|
|
|
if Nokogiri::HTML.fragment(@post.cooked).css("b", "strong", "em", "i", ".bbcode-i", ".bbcode-b").size > 0
|
|
|
|
raw = <<~RAW
|
2017-06-01 15:15:22 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.formatting.reply", i18n_post_args)}
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
|
|
|
RAW
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
reply = reply_to(@post, raw)
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
reply
|
|
|
|
else
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.formatting.not_found", i18n_post_args)) unless @data[:attempted]
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_quote
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
|
|
|
doc = Nokogiri::HTML.fragment(@post.cooked)
|
|
|
|
|
|
|
|
if doc.css(".quote").size > 0
|
|
|
|
raw = <<~RAW
|
2017-06-01 15:15:22 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.quoting.reply", i18n_post_args)}
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
|
|
|
RAW
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
reply = reply_to(@post, raw)
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
reply
|
|
|
|
else
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.quoting.not_found", i18n_post_args)) unless @data[:attempted]
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_emoji
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
|
|
|
doc = Nokogiri::HTML.fragment(@post.cooked)
|
|
|
|
|
|
|
|
if doc.css(".emoji").size > 0
|
|
|
|
raw = <<~RAW
|
2017-06-01 15:15:22 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.emoji.reply", i18n_post_args)}
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
|
|
|
RAW
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
reply = reply_to(@post, raw)
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
reply
|
|
|
|
else
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.emoji.not_found", i18n_post_args)) unless @data[:attempted]
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_mention
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
|
|
|
if bot_mentioned?(@post)
|
|
|
|
raw = <<~RAW
|
2017-06-01 15:15:22 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.mention.reply", i18n_post_args)}
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
|
|
|
RAW
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
reply = reply_to(@post, raw)
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
reply
|
|
|
|
else
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
unless @data[:attempted]
|
|
|
|
reply_to(@post, I18n.t(
|
|
|
|
"#{I18N_KEY}.mention.not_found",
|
2017-06-01 15:15:22 -04:00
|
|
|
i18n_post_args(
|
|
|
|
username: @user.username,
|
|
|
|
discobot_username: self.discobot_user.username
|
|
|
|
)
|
2017-05-24 01:50:20 -04:00
|
|
|
))
|
|
|
|
end
|
|
|
|
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def missing_flag
|
|
|
|
return unless valid_topic?(@post.topic_id)
|
|
|
|
return if @post.user_id == -2
|
|
|
|
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.flag.not_found", i18n_post_args)) unless @data[:attempted]
|
2017-05-24 01:50:20 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_flag
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
return unless @post.user.id == -2
|
|
|
|
|
|
|
|
raw = <<~RAW
|
2017-06-01 15:15:22 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.flag.reply", i18n_post_args)}
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
|
|
|
RAW
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
reply = reply_to(@post, raw)
|
|
|
|
@post.post_actions.where(user_id: @user.id).destroy_all
|
|
|
|
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
reply
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_search
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
2019-10-16 14:36:54 -04:00
|
|
|
if @post.raw.match(/#{NewUserNarrative.search_answer}/)
|
2017-05-24 01:50:20 -04:00
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.search.reply", i18n_post_args(search_url: url_helpers(:search_url))))
|
2017-05-24 01:50:20 -04:00
|
|
|
else
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.search.not_found", i18n_post_args)) unless @data[:attempted]
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_reply
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
reply_to(
|
|
|
|
@post,
|
|
|
|
I18n.t("#{I18N_KEY}.end.message",
|
2017-06-01 15:15:22 -04:00
|
|
|
i18n_post_args(
|
|
|
|
username: @user.username,
|
|
|
|
base_url: Discourse.base_url,
|
|
|
|
certificate: certificate,
|
|
|
|
discobot_username: self.discobot_user.username,
|
|
|
|
advanced_trigger: AdvancedUserNarrative.reset_trigger
|
|
|
|
)
|
2017-05-24 01:50:20 -04:00
|
|
|
),
|
|
|
|
topic_id: @data[:topic_id]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def like_post(post)
|
2019-01-03 12:03:01 -05:00
|
|
|
PostActionCreator.like(self.discobot_user, post)
|
2017-05-24 01:50:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def welcome_topic
|
|
|
|
Topic.find_by(slug: 'welcome-to-discourse', archetype: Archetype.default) ||
|
|
|
|
Topic.recent(1).first
|
|
|
|
end
|
|
|
|
|
|
|
|
def url_helpers(url, opts = {})
|
2019-05-06 21:27:05 -04:00
|
|
|
Rails.application.routes.url_helpers.public_send(
|
|
|
|
url,
|
|
|
|
opts.merge(host: Discourse.base_url)
|
|
|
|
)
|
2017-05-24 01:50:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|