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,
|
2020-10-09 07:51:24 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.bookmark.instructions", base_uri: Discourse.base_path) },
|
2017-05-24 01:50:20 -04:00
|
|
|
action: :say_hello
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_bookmark: {
|
|
|
|
next_state: :tutorial_onebox,
|
2020-10-09 07:51:24 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.onebox.instructions", base_uri: Discourse.base_path) },
|
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,
|
2020-10-09 07:51:24 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.emoji.instructions", base_uri: Discourse.base_path) },
|
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",
|
2020-06-25 07:29:55 -04:00
|
|
|
discobot_username: self.discobot_username,
|
2020-10-09 07:51:24 -04:00
|
|
|
base_uri: Discourse.base_path)
|
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,
|
2020-10-09 07:51:24 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.formatting.instructions", base_uri: Discourse.base_path) },
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_mention
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_formatting: {
|
|
|
|
next_state: :tutorial_quote,
|
2020-10-09 07:51:24 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.quoting.instructions", base_uri: Discourse.base_path) },
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_formatting
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_quote: {
|
|
|
|
next_state: :tutorial_images,
|
2020-10-09 07:51:24 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.images.instructions", base_uri: Discourse.base_path) },
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_quote
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-08-21 13:13:13 -04:00
|
|
|
# Note: tutorial_images and tutorial_likes are mutually exclusive.
|
|
|
|
# The prerequisites should ensure only one of them is called.
|
2017-05-24 01:50:20 -04:00
|
|
|
tutorial_images: {
|
2020-08-21 13:13:13 -04:00
|
|
|
prerequisite: Proc.new { @user.has_trust_level?(SiteSetting.min_trust_to_post_embedded_media) },
|
|
|
|
next_state: :tutorial_likes,
|
2020-10-09 07:51:24 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.likes.instructions", base_uri: Discourse.base_path) },
|
2020-08-21 13:13:13 -04:00
|
|
|
reply: {
|
|
|
|
action: :reply_to_image
|
|
|
|
},
|
|
|
|
like: {
|
|
|
|
action: :track_images_like
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tutorial_likes: {
|
|
|
|
prerequisite: Proc.new { !@user.has_trust_level?(SiteSetting.min_trust_to_post_embedded_media) },
|
2017-05-24 01:50:20 -04:00
|
|
|
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),
|
2020-10-09 07:51:24 -04:00
|
|
|
base_uri: Discourse.base_path)
|
2017-05-24 01:50:20 -04:00
|
|
|
},
|
|
|
|
like: {
|
2020-08-21 13:13:13 -04:00
|
|
|
action: :reply_to_likes
|
|
|
|
},
|
|
|
|
reply: {
|
|
|
|
next_state: :tutorial_likes,
|
|
|
|
action: :missing_likes_like
|
2017-05-24 01:50:20 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
2020-10-09 07:51:24 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.search.instructions", base_uri: Discourse.base_path) },
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-09 22:46:51 -04:00
|
|
|
def self.badge_name
|
|
|
|
BADGE_NAME
|
|
|
|
end
|
|
|
|
|
2019-10-16 14:36:54 -04:00
|
|
|
def self.search_answer
|
|
|
|
':herb:'
|
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
|
2020-10-27 10:49:22 -04:00
|
|
|
def self.search_answer_emoji
|
|
|
|
"\u{1F33F}"
|
|
|
|
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)
|
|
|
|
reset_data(user, topic_id: post.topic_id)
|
|
|
|
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])
|
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
2017-05-24 01:50:20 -04:00
|
|
|
#{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))}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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 },
|
|
|
|
skip_validations: true, force_new_version: true
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
2017-05-24 01:50:20 -04:00
|
|
|
#{raw}
|
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
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)
|
2020-04-28 20:53:37 -04:00
|
|
|
bookmark_url = "#{profile_page_url}/activity/bookmarks"
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
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)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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?
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
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)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-08-21 13:13:13 -04:00
|
|
|
def track_images_like
|
2017-05-24 01:50:20 -04:00
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
2020-08-21 13:13:13 -04:00
|
|
|
post_liked = PostAction.exists?(
|
2017-05-24 01:50:20 -04:00
|
|
|
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)
|
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
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)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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, {})
|
|
|
|
|
2020-05-04 23:46:57 -04:00
|
|
|
if Nokogiri::HTML5.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)
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
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)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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
|
2020-08-21 13:13:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def missing_likes_like
|
|
|
|
return unless valid_topic?(@post.topic_id)
|
|
|
|
return if @post.user_id == self.discobot_user.id
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
|
|
|
|
last_post = Post.find_by(id: @data[:last_post_id])
|
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.likes.not_found", i18n_post_args(url: last_post.url)))
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_likes
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
|
|
|
post_liked = PostAction.exists?(
|
|
|
|
post_action_type_id: PostActionType.types[:like],
|
|
|
|
post_id: @data[:last_post_id],
|
|
|
|
user_id: @user.id
|
|
|
|
)
|
|
|
|
|
|
|
|
if post_liked
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
2020-08-21 13:13:13 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.likes.reply", i18n_post_args)}
|
|
|
|
|
|
|
|
#{instance_eval(&@next_instructions)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2020-08-21 13:13:13 -04:00
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
reply = reply_to(@post, raw)
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
return reply
|
|
|
|
end
|
|
|
|
|
|
|
|
false
|
2017-05-24 01:50:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_formatting
|
|
|
|
post_topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(post_topic_id)
|
|
|
|
|
2020-05-04 23:46:57 -04:00
|
|
|
if Nokogiri::HTML5.fragment(@post.cooked).css("b", "strong", "em", "i", ".bbcode-i", ".bbcode-b").size > 0
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
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)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2020-05-04 23:46:57 -04:00
|
|
|
doc = Nokogiri::HTML5.fragment(@post.cooked)
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
if doc.css(".quote").size > 0
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
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)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2020-05-04 23:46:57 -04:00
|
|
|
doc = Nokogiri::HTML5.fragment(@post.cooked)
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
if doc.css(".emoji").size > 0
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
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)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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)
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
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)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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,
|
2020-06-25 07:29:55 -04:00
|
|
|
discobot_username: self.discobot_username
|
2017-06-01 15:15:22 -04:00
|
|
|
)
|
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)
|
2020-08-03 21:38:04 -04:00
|
|
|
|
|
|
|
# Remove any incorrect flags so that they can try again
|
|
|
|
if @post.user_id == -2
|
|
|
|
@post.post_actions
|
|
|
|
.where(user_id: @user.id)
|
|
|
|
.where("post_action_type_id IN (?)", (PostActionType.flag_types.values - [PostActionType.types[:inappropriate]]))
|
|
|
|
.destroy_all
|
|
|
|
end
|
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}.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
|
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raw = <<~MD
|
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)}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2020-10-27 10:49:22 -04:00
|
|
|
if @post.raw.include?(NewUserNarrative.search_answer) || @post.raw.include?(NewUserNarrative.search_answer_emoji)
|
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,
|
2020-06-25 07:29:55 -04:00
|
|
|
discobot_username: self.discobot_username,
|
2017-06-01 15:15:22 -04:00
|
|
|
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
|