2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
module DiscourseNarrativeBot
|
|
|
|
class AdvancedUserNarrative < Base
|
|
|
|
I18N_KEY = "discourse_narrative_bot.advanced_user_narrative".freeze
|
|
|
|
BADGE_NAME = "Licensed".freeze
|
|
|
|
|
|
|
|
TRANSITION_TABLE = {
|
|
|
|
begin: {
|
|
|
|
next_state: :tutorial_edit,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.edit.instructions", i18n_post_args) },
|
2017-05-24 01:50:20 -04:00
|
|
|
init: {
|
|
|
|
action: :start_advanced_track,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tutorial_edit: {
|
|
|
|
next_state: :tutorial_delete,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.delete.instructions", i18n_post_args) },
|
2017-05-24 01:50:20 -04:00
|
|
|
edit: {
|
|
|
|
action: :reply_to_edit,
|
|
|
|
},
|
|
|
|
reply: {
|
|
|
|
next_state: :tutorial_edit,
|
|
|
|
action: :missing_edit,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tutorial_delete: {
|
|
|
|
next_state: :tutorial_recover,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.recover.instructions", i18n_post_args) },
|
2017-05-24 01:50:20 -04:00
|
|
|
delete: {
|
|
|
|
action: :reply_to_delete,
|
|
|
|
},
|
|
|
|
reply: {
|
|
|
|
next_state: :tutorial_delete,
|
|
|
|
action: :missing_delete,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tutorial_recover: {
|
|
|
|
next_state: :tutorial_category_hashtag,
|
|
|
|
next_instructions:
|
|
|
|
Proc.new do
|
2020-06-24 01:45:50 -04:00
|
|
|
category = Category.secured(Guardian.new(@user)).last
|
2017-05-24 01:50:20 -04:00
|
|
|
slug = category.slug
|
2023-01-06 15:42:16 -05:00
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
if parent_category = category.parent_category
|
|
|
|
slug = "#{parent_category.slug}#{CategoryHashtag::SEPARATOR}#{slug}"
|
|
|
|
end
|
2023-01-06 15:42:16 -05:00
|
|
|
|
2023-01-16 19:16:28 -05:00
|
|
|
# TODO (martin) When enable_experimental_hashtag_autocomplete is the only option
|
|
|
|
# update the instructions and remove instructions_experimental, as well as the
|
|
|
|
# not_found translation
|
|
|
|
if SiteSetting.enable_experimental_hashtag_autocomplete
|
|
|
|
I18n.t(
|
|
|
|
"#{I18N_KEY}.category_hashtag.instructions_experimental",
|
|
|
|
i18n_post_args(category: "##{slug}"),
|
|
|
|
)
|
|
|
|
else
|
|
|
|
I18n.t(
|
|
|
|
"#{I18N_KEY}.category_hashtag.instructions",
|
|
|
|
i18n_post_args(category: "##{slug}"),
|
|
|
|
)
|
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
end,
|
|
|
|
recover: {
|
|
|
|
action: :reply_to_recover,
|
|
|
|
},
|
|
|
|
reply: {
|
|
|
|
next_state: :tutorial_recover,
|
|
|
|
action: :missing_recover,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tutorial_category_hashtag: {
|
|
|
|
next_state: :tutorial_change_topic_notification_level,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions:
|
|
|
|
Proc.new do
|
|
|
|
I18n.t("#{I18N_KEY}.change_topic_notification_level.instructions", i18n_post_args)
|
|
|
|
end,
|
2017-05-24 01:50:20 -04:00
|
|
|
reply: {
|
|
|
|
action: :reply_to_category_hashtag,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tutorial_change_topic_notification_level: {
|
|
|
|
next_state: :tutorial_poll,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.poll.instructions", i18n_post_args) },
|
2017-05-24 01:50:20 -04:00
|
|
|
topic_notification_level_changed: {
|
|
|
|
action: :reply_to_topic_notification_level_changed,
|
|
|
|
},
|
|
|
|
reply: {
|
2017-07-13 02:12:45 -04:00
|
|
|
next_state: :tutorial_change_topic_notification_level,
|
2017-05-24 01:50:20 -04:00
|
|
|
action: :missing_topic_notification_level_change,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tutorial_poll: {
|
2020-02-27 09:01:59 -05:00
|
|
|
prerequisite:
|
|
|
|
Proc.new do
|
|
|
|
SiteSetting.poll_enabled &&
|
|
|
|
@user.has_trust_level?(SiteSetting.poll_minimum_trust_level_to_create)
|
|
|
|
end,
|
2017-05-24 01:50:20 -04:00
|
|
|
next_state: :tutorial_details,
|
2017-06-01 15:15:22 -04:00
|
|
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.details.instructions", i18n_post_args) },
|
2017-05-24 01:50:20 -04:00
|
|
|
reply: {
|
|
|
|
action: :reply_to_poll,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tutorial_details: {
|
|
|
|
next_state: :end,
|
|
|
|
reply: {
|
|
|
|
action: :reply_to_details,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-04-09 22:46:51 -04:00
|
|
|
def self.badge_name
|
|
|
|
BADGE_NAME
|
|
|
|
end
|
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
def self.reset_trigger
|
|
|
|
I18n.t("discourse_narrative_bot.advanced_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 init_tutorial_edit
|
|
|
|
data = get_data(@user)
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
2020-06-25 07:29:55 -04:00
|
|
|
post =
|
|
|
|
PostCreator.create!(
|
|
|
|
@user,
|
|
|
|
raw:
|
|
|
|
I18n.t(
|
|
|
|
"#{I18N_KEY}.edit.bot_created_post_raw",
|
|
|
|
i18n_post_args(discobot_username: self.discobot_username),
|
2023-01-06 15:42:16 -05:00
|
|
|
),
|
2020-06-25 07:29:55 -04:00
|
|
|
topic_id: data[:topic_id],
|
|
|
|
skip_bot: true,
|
|
|
|
skip_validations: true,
|
|
|
|
)
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
set_state_data(:post_id, post.id)
|
|
|
|
post
|
|
|
|
end
|
|
|
|
|
|
|
|
def init_tutorial_recover
|
|
|
|
data = get_data(@user)
|
|
|
|
|
2020-06-25 07:29:55 -04:00
|
|
|
post =
|
|
|
|
PostCreator.create!(
|
|
|
|
@user,
|
|
|
|
raw:
|
|
|
|
I18n.t(
|
|
|
|
"#{I18N_KEY}.recover.deleted_post_raw",
|
|
|
|
i18n_post_args(discobot_username: self.discobot_username),
|
2023-01-06 15:42:16 -05:00
|
|
|
),
|
2018-09-06 22:18:13 -04:00
|
|
|
topic_id: data[:topic_id],
|
|
|
|
skip_bot: true,
|
|
|
|
skip_validations: true,
|
|
|
|
)
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
set_state_data(:post_id, post.id)
|
2017-06-16 00:03:34 -04:00
|
|
|
|
|
|
|
opts = { skip_bot: true }
|
|
|
|
|
|
|
|
if SiteSetting.delete_removed_posts_after < 1
|
|
|
|
opts[:delete_removed_posts_after] = 1
|
|
|
|
|
2019-03-28 14:29:33 -04:00
|
|
|
result = PostActionCreator.notify_moderators(self.discobot_user, post)
|
2023-03-02 10:40:53 -05:00
|
|
|
result.reviewable.perform(self.discobot_user, :ignore_and_do_nothing)
|
2017-06-16 00:03:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
PostDestroyer.new(@user, post, opts).destroy
|
2017-05-24 01:50:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def start_advanced_track
|
2017-06-01 15:15:22 -04:00
|
|
|
raw = I18n.t("#{I18N_KEY}.start_message", i18n_post_args(username: @user.username))
|
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
|
|
|
|
|
|
|
opts = {
|
|
|
|
title: I18n.t("#{I18N_KEY}.title"),
|
|
|
|
target_usernames: @user.username,
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
}
|
|
|
|
|
2018-03-05 02:38:05 -05:00
|
|
|
if @post && @post.topic.private_message? &&
|
2017-05-24 01:50:20 -04:00
|
|
|
@post.topic.topic_allowed_users.pluck(:user_id).include?(@user.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 reply_to_edit
|
|
|
|
return unless valid_topic?(@post.topic_id)
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
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}.edit.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_to(@post, raw)
|
|
|
|
end
|
|
|
|
|
|
|
|
def missing_edit
|
|
|
|
post_id = get_state_data(:post_id)
|
|
|
|
return unless valid_topic?(@post.topic_id) && post_id != @post.id
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
unless @data[:attempted]
|
|
|
|
reply_to(
|
|
|
|
@post,
|
2017-06-01 15:15:22 -04:00
|
|
|
I18n.t("#{I18N_KEY}.edit.not_found", i18n_post_args(url: Post.find_by(id: post_id).url)),
|
2017-05-24 01:50:20 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_delete
|
|
|
|
return unless valid_topic?(@topic_id)
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
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}.delete.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
|
|
|
|
2017-05-25 22:09:42 -04:00
|
|
|
PostCreator.create!(self.discobot_user, raw: raw, topic_id: @topic_id)
|
2017-05-24 01:50:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def missing_delete
|
|
|
|
return unless valid_topic?(@post.topic_id)
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
unless @data[:attempted]
|
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.delete.not_found", i18n_post_args))
|
2023-01-06 15:42:16 -05:00
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_recover
|
|
|
|
return unless valid_topic?(@post.topic_id)
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
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
|
2019-04-24 19:29:20 -04:00
|
|
|
#{I18n.t("#{I18N_KEY}.recover.reply", i18n_post_args(deletion_after: SiteSetting.delete_removed_posts_after))}
|
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
|
|
|
|
2017-05-25 22:09:42 -04:00
|
|
|
PostCreator.create!(self.discobot_user, raw: raw, topic_id: @post.topic_id)
|
2017-05-24 01:50:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def missing_recover
|
|
|
|
unless valid_topic?(@post.topic_id) &&
|
|
|
|
post_id = get_state_data(:post_id) && @post.id != post_id
|
2023-01-06 15:42:16 -05:00
|
|
|
return
|
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
unless @data[:attempted]
|
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.recover.not_found", i18n_post_args))
|
2023-01-06 15:42:16 -05:00
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_category_hashtag
|
|
|
|
topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(topic_id)
|
|
|
|
|
2023-01-16 19:16:28 -05:00
|
|
|
hashtag_css_class =
|
|
|
|
SiteSetting.enable_experimental_hashtag_autocomplete ? ".hashtag-cooked" : ".hashtag"
|
|
|
|
if Nokogiri::HTML5.fragment(@post.cooked).css(hashtag_css_class).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}.category_hashtag.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_to(@post, raw)
|
|
|
|
else
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
unless @data[:attempted]
|
2023-01-16 19:16:28 -05:00
|
|
|
if SiteSetting.enable_experimental_hashtag_autocomplete
|
|
|
|
reply_to(
|
|
|
|
@post,
|
|
|
|
I18n.t("#{I18N_KEY}.category_hashtag.not_found_experimental", i18n_post_args),
|
|
|
|
)
|
|
|
|
else
|
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.category_hashtag.not_found", i18n_post_args))
|
|
|
|
end
|
2023-01-06 15:42:16 -05:00
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def missing_topic_notification_level_change
|
|
|
|
return unless valid_topic?(@post.topic_id)
|
|
|
|
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
unless @data[:attempted]
|
|
|
|
reply_to(
|
|
|
|
@post,
|
|
|
|
I18n.t("#{I18N_KEY}.change_topic_notification_level.not_found", i18n_post_args),
|
|
|
|
)
|
2023-01-06 15:42:16 -05:00
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_topic_notification_level_changed
|
|
|
|
return unless valid_topic?(@topic_id)
|
|
|
|
|
|
|
|
fake_delay
|
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}.change_topic_notification_level.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
|
|
|
|
|
2017-05-25 22:09:42 -04:00
|
|
|
post = PostCreator.create!(self.discobot_user, raw: raw, topic_id: @topic_id)
|
2017-06-02 18:15:08 -04:00
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
post
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_poll
|
|
|
|
topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(topic_id)
|
|
|
|
|
2020-05-04 23:46:57 -04:00
|
|
|
if Nokogiri::HTML5.fragment(@post.cooked).css(".poll").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}.poll.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_to(@post, raw)
|
|
|
|
else
|
|
|
|
fake_delay
|
2017-06-01 15:15:22 -04:00
|
|
|
unless @data[:attempted]
|
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.poll.not_found", i18n_post_args))
|
2023-01-06 15:42:16 -05:00
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_details
|
|
|
|
topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(topic_id)
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
2020-05-04 23:46:57 -04:00
|
|
|
if Nokogiri::HTML5.fragment(@post.cooked).css("details").size > 0
|
2017-06-01 15:15:22 -04:00
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.details.reply", i18n_post_args))
|
2017-05-24 01:50:20 -04:00
|
|
|
else
|
2017-06-01 15:15:22 -04:00
|
|
|
unless @data[:attempted]
|
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.details.not_found", i18n_post_args))
|
2023-01-06 15:42:16 -05:00
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_to_wiki
|
|
|
|
topic_id = @post.topic_id
|
|
|
|
return unless valid_topic?(topic_id)
|
|
|
|
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
if @post.wiki
|
2017-06-01 15:15:22 -04:00
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.wiki.reply", i18n_post_args))
|
2017-05-24 01:50:20 -04:00
|
|
|
else
|
2017-06-01 15:15:22 -04:00
|
|
|
unless @data[:attempted]
|
|
|
|
reply_to(@post, I18n.t("#{I18N_KEY}.wiki.not_found", i18n_post_args))
|
2023-01-06 15:42:16 -05:00
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
enqueue_timeout_job(@user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_reply
|
|
|
|
fake_delay
|
|
|
|
|
|
|
|
reply_to(
|
|
|
|
@post,
|
2017-06-01 15:15:22 -04:00
|
|
|
I18n.t("#{I18N_KEY}.end.message", i18n_post_args(certificate: certificate("advanced"))),
|
2017-05-24 01:50:20 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def synchronize(user)
|
|
|
|
if Rails.env.test?
|
|
|
|
yield
|
|
|
|
else
|
|
|
|
DistributedMutex.synchronize("advanced_user_narrative_#{user.id}") { yield }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|