FEATURE: Allow tutorials to declare prerequisite before it starts.

This commit is contained in:
Guo Xiang Tan
2017-07-13 15:12:45 +09:00
parent 79a084dd58
commit c049e18203
4 changed files with 67 additions and 27 deletions

View File

@ -74,7 +74,7 @@ module DiscourseNarrativeBot
action: :reply_to_topic_notification_level_changed
},
reply: {
next_state: :tutorial_notification_level,
next_state: :tutorial_change_topic_notification_level,
action: :missing_topic_notification_level_change
}
},

View File

@ -19,6 +19,21 @@ module DiscourseNarrativeBot
begin
opts = transition
loop do
next_state = opts[:next_state]
break if next_state == :end
next_opts = self.class::TRANSITION_TABLE.fetch(next_state)
prerequisite = next_opts[:prerequisite]
break if !prerequisite || instance_eval(&prerequisite)
[:next_state, :next_instructions].each do |key|
opts[key] = next_opts[key]
end
end
rescue InvalidTransitionError
# For given input, no transition for current state
return

View File

@ -38,6 +38,7 @@ module DiscourseNarrativeBot
},
tutorial_emoji: {
prerequisite: Proc.new { SiteSetting.enable_emoji },
next_state: :tutorial_mention,
next_instructions: Proc.new {
I18n.t("#{I18N_KEY}.mention.instructions",