feat: add quick choices to VK dialog

This commit is contained in:
nyan404 committed 2026-08-16 15:40:38 +03:00
1 parent 94665a24ad
commit fe70303e87
2 files changed
+53

No files matched your search

+29
View File
@@ -4,6 +4,7 @@ import json
import os
import random
import re
from datetime import datetime
from typing import Any, Iterator
from urllib.parse import urlencode
from urllib.request import Request, urlopen
@@ -316,6 +317,9 @@ class BelkiBot:
return {
"menu:lu": "/лу", "menu:zu": "/зу", "menu:training": "/урок",
"menu:inspection": "/осмотр", "menu:help": "/help", "menu:cancel": "/отмена",
"quick:today": "__today__", "quick:no_resources": "без ресурсов",
"place:hollow": "дупло", "place:crevice": "расщелина",
"skill:lu": "ЛУ", "skill:zu": "ЗУ",
"confirm:yes": "да", "confirm:no": "нет",
"independence:self": "сам", "independence:nonself": "несам",
}.get(str(value))
@@ -402,6 +406,16 @@ class BelkiDialog:
}
if state and state.get("mode") == "coaching":
next_key = next((key for key, _ in self._ORDERS["coaching"] if not self._has_field(state, key)), None)
if next_key == "skill":
return {"one_time": False, "buttons": [
[self._button("ЛУ", "skill:lu", "primary"), self._button("ЗУ", "skill:zu", "primary")],
[self._button("Отмена", "menu:cancel", "negative")],
]}
if next_key == "date":
return {"one_time": False, "buttons": [
[self._button("Сегодня", "quick:today", "primary")],
[self._button("Отмена", "menu:cancel", "negative")],
]}
if next_key == "independence":
return {
"one_time": False,
@@ -409,6 +423,18 @@ class BelkiDialog:
[self._button("Отмена", "menu:cancel", "negative")]],
}
return {"one_time": False, "buttons": [[self._button("Отмена", "menu:cancel", "negative")]]}
if state and state.get("mode") == "inspection":
next_key = next((key for key, _ in self._ORDERS["inspection"] if not self._has_field(state, key)), None)
if next_key == "place":
return {"one_time": False, "buttons": [
[self._button("Дупло", "place:hollow", "primary"), self._button("Расщелина", "place:crevice", "primary")],
[self._button("Отмена", "menu:cancel", "negative")],
]}
if next_key == "resources":
return {"one_time": False, "buttons": [
[self._button("Без ресурсов", "quick:no_resources", "secondary")],
[self._button("Отмена", "menu:cancel", "negative")],
]}
if state:
return {"one_time": False, "buttons": [[self._button("Отмена", "menu:cancel", "negative")]]}
return {
@@ -555,6 +581,9 @@ class BelkiDialog:
def _consume_field(self, state: dict[str, Any], text: str) -> str:
key = next((key for key, _ in self._ORDERS[state["mode"]] if not self._has_field(state, key)), None)
if key == "date":
if text.lower() in ("сегодня", "__today__"):
state[key] = datetime.now().strftime("%d.%m")
return self._ask_next(state)
if not re.fullmatch(r"\d{2}\.\d{2}", text):
return "Дата должна быть в формате ДД.ММ, например 15.08."
state[key] = text