diff --git a/main.exe b/main.exe new file mode 100644 index 0000000..79f9aeb Binary files /dev/null and b/main.exe differ diff --git a/tg_handle/tg.v b/tg_handle/tg.v index f023960..e43c9e1 100644 --- a/tg_handle/tg.v +++ b/tg_handle/tg.v @@ -155,6 +155,46 @@ fn (mut b TgBot) message_handler(update vgram.Update) { b.render_message(current_state.id,chat_id_str,previous_question) return } + + if previous_question.question_type == models.question_type_number.str() { + content := json.decode(models.QuizQuestionNumber, previous_question.content) or { + b.bot.send_message(chat_id: chat_id_str, text: 'Ошибка при обработке вопроса типа number') + return + } + mut message_text := update.message.text + if !message_text.is_int() { + b.bot.send_message( + chat_id: chat_id_str, + text: 'Допустимо вводить только число' + ) + return + } + mut min := 0 + mut max := 0 + number_value := message_text.int() + if content.range.contains('—') { + range_arr := content.range.split('—') + if range_arr.len == 2 { + min = range_arr[0].int() + max = range_arr[1].int() + } + } + if max > 0{ + if number_value < min || number_value > max { + b.bot.send_message( + chat_id: chat_id_str, + text: 'Введённое число вне заданного диапазона (${min} - ${max})' + ) + return + } + } + + // todo отправка в answerer + println(number_value) + + b.render_message(current_state.id, chat_id_str, previous_question) + return + } } } @@ -676,10 +716,37 @@ fn (mut b TgBot)render_date_question(state_id i64,chat_id_str string, question m } -fn (mut b TgBot)render_number_question(state_id i64,chat_id_str string, question models.QuizQuestion, content models.QuizQuestionNumber){ +fn (mut b TgBot) render_number_question(state_id i64, chat_id_str string, question models.QuizQuestion, content models.QuizQuestionNumber) { + mut range := '' + if content.range.contains('—') { + range_arr := content.range.split('—') + if range_arr.len == 2 { + range = ' (вводить числа от ${range_arr[0]} до ${range_arr[1]})' + } + } + + if content.choose_range { + b.bot.send_message( + chat_id: chat_id_str, + text: '*$question.title*\n\n${question.description}${range}', + parse_mode: 'Markdown' + ) + } else { + b.bot.send_message( + chat_id: chat_id_str, + text: '*$question.title*\n\n${question.description}', + parse_mode: 'Markdown' + ) + } + + b.repo.update_state(state_id, question.id) or { + b.bot.send_message(chat_id: chat_id_str, text: 'Ошибка при обновлении состояния респондента') + return + } } + fn (mut b TgBot)render_file_question(state_id i64,chat_id_str string, question models.QuizQuestion, content models.QuizQuestionFile){ }