Module: SlackQuestionAbilities
- Included in:
- SkillActions
- Defined in:
- src/abilities/slack_question_abilities.rb
Defined Under Namespace
Classes: Option
Instance Method Summary collapse
-
#ask_bool(question, vars: nil) ⇒ Boolean
(also: #ask_for_bool)
Ask a question and return a boolean depending on the answer.
-
#ask_options(text, options, numbered: true) ⇒ Object
(also: #ask_for_options, #ask_for_option, #ask_option)
Ask for a choice between several options.
-
#ask_string(question, vars: nil) ⇒ String
(also: #ask_for_string)
Ask a question and return the answer's text.
-
#ask_time(question, vars: nil, future: nil, past: nil) ⇒ Time?
(also: #ask_for_time)
Ask for datetime input.
-
#confirm(question, vars: nil) ⇒ void
Ask for confirmation of an action.
Instance Method Details
#ask_bool(question, vars: nil) ⇒ Boolean Also known as: ask_for_bool
Ask a question and return a boolean depending on the answer
Positive answers such as yes
, ok
, :+1:
, etc. give true
.
Negative answers such as no
, not
, :-1:
, etc. give false
.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'src/abilities/slack_question_abilities.rb', line 65 def ask_bool(question, vars: nil) say question, vars: vars entities = (await_next_response..text) if strings(:wit_entities, :yes).include? entities.single.bool_response true elsif strings(:wit_entities, :no).include? entities.single.bool_response false else ask_bool any_string(:ask_for_bool, :i_dont_understand) end end |
#ask_options(text, options, numbered: true) ⇒ Object Also known as: ask_for_options, ask_for_option, ask_option
Ask for a choice between several options
The options can be either numbered or not. Numbered options are presented as a list and the user can choose by replying with a number. Unnumbered options are presented as plain text and the user is required to reply with the option itself.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'src/abilities/slack_question_abilities.rb', line 132 def (text, , numbered: true) if numbered = .map.with_index { |option, i| "#{i + 1}) #{option}" } say "#{text}\n\n#{.join("\n")}\n" else = .map(&:to_s) say "#{join_with_or()}?".capitalize end loop do response = await_next_response..text.downcase.strip if numbered response = response.gsub(/^[^0-9]*|[\(\)\.]/, '').to_i return [response - 1].value if response >= 1 && response <= .size = (1...size).to_a.map { |i| "\"#{i}\"" } say "Не те разбирам, моля те отговори с #{join_with_or }" else response = response.gsub(/\!\.\?/, '') selected_option = .find { |option| option.match? response } return selected_option.value if selected_option = .map { |option| "\"#{option}\"" } say "Не те разбирам, моля те отговори с #{join_with_or }" end end end |
#ask_string(question, vars: nil) ⇒ String Also known as: ask_for_string
Ask a question and return the answer's text
46 47 48 49 |
# File 'src/abilities/slack_question_abilities.rb', line 46 def ask_string(question, vars: nil) say question, vars: vars await_next_response..text end |
#ask_time(question, vars: nil, future: nil, past: nil) ⇒ Time? Also known as: ask_for_time
Ask for datetime input
May trigger multiple questions if the first datetime is ambiguous.
178 179 180 181 182 |
# File 'src/abilities/slack_question_abilities.rb', line 178 def ask_time(question, vars: nil, future: nil, past: nil) say question, vars: vars await_next_response.extracted_time(future: future, past: past) end |
#confirm(question, vars: nil) ⇒ void
This method returns an undefined value.
Ask for confirmation of an action
If a negative confirmation is given, reacts with :+1:
on the answer and
stops the current interaction directly. This means that the result does not
need to be checked.
96 97 98 99 100 101 |
# File 'src/abilities/slack_question_abilities.rb', line 96 def confirm(question, vars: nil) unless ask_bool(question, vars: vars) react_with '+1' raise Interaction::StopInteraction end end |