feat: add sent report history lookup
This commit is contained in:
1 parent
546fa37fce
commit
3ebab303a5
12 files changed
+393
-18
No files matched your search
+40
-2
@@ -9,11 +9,12 @@ import re
|
||||
import threading
|
||||
import time
|
||||
import unicodedata
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from difflib import SequenceMatcher
|
||||
from typing import Any
|
||||
from urllib.parse import urlencode
|
||||
from urllib.request import Request, urlopen
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from .api import ApiError, calculate_payload
|
||||
from .domain import MAX_COACHING_KITTENS
|
||||
@@ -954,7 +955,7 @@ class BelkiBot:
|
||||
pass
|
||||
value = payload.get("command") if isinstance(payload, dict) else payload
|
||||
return {
|
||||
"menu:lu": "/лу", "menu:zu": "/зу", "menu:training": "/урок",
|
||||
"menu:lu": "/лу", "menu:zu": "/зу", "menu:training": "/урок", "menu:my_reports": "/мои-отчёты",
|
||||
"menu:inspection": "/осмотр", "menu:goal": "/цель", "menu:help": "/help", "menu:cancel": "/отмена", "menu:application": "/заявка", "menu:rename": "/изменить-имя",
|
||||
"points:coaching": "прокачка", "points:training": "тренировка", "points:inspection": "осмотр",
|
||||
"application:feathers": "/перо", "application:kitten": "/бельчонок",
|
||||
@@ -1230,6 +1231,7 @@ class BelkiDialog:
|
||||
[self._button("Прокачка ЛУ", "menu:lu", "primary"), self._button("Прокачка ЗУ", "menu:zu", "primary")],
|
||||
[self._button("Тренировка", "menu:training", "secondary"), self._button("Осмотр", "menu:inspection", "secondary")],
|
||||
[self._button("Калькулятор баллов", "menu:goal", "secondary")],
|
||||
[self._button("Мои отчёты", "menu:my_reports", "secondary")],
|
||||
[self._button("Подать заявку", "menu:application", "secondary")],
|
||||
[self._button("Изменить имя кота", "menu:rename", "secondary")],
|
||||
[self._button("Помощь", "menu:help", "secondary")],
|
||||
@@ -1728,6 +1730,8 @@ class BelkiDialog:
|
||||
onboarding_response = self._ensure_profile(actor_id, text)
|
||||
if onboarding_response is not None:
|
||||
return onboarding_response
|
||||
if text.casefold() in {"/мои-отчёты", "/мои-отчеты", "мои отчёты", "мои отчеты"}:
|
||||
return self._my_reports(actor_id)
|
||||
if text.lower() in ("/отмена", "отмена", "нет") and actor_id in self._states:
|
||||
self._reset(actor_id)
|
||||
return "Текущий ввод отменён. Для нового отчёта используйте /лу, /зу или /help."
|
||||
@@ -1792,6 +1796,40 @@ class BelkiDialog:
|
||||
except (ApiError, ValueError) as exc:
|
||||
return str(exc)
|
||||
|
||||
def _my_reports(self, actor_id: int) -> str:
|
||||
"""Format the latest confirmed report submissions for one VK user."""
|
||||
if self.calculation_store is None:
|
||||
return "История отчётов сейчас недоступна. Попробуйте позже."
|
||||
try:
|
||||
reports = self.calculation_store.list_vk_reports(actor_id, limit=100)
|
||||
except Exception:
|
||||
logger.exception("Unable to load VK report history for actor %s", actor_id)
|
||||
return "Не удалось загрузить историю отчётов. Попробуйте позже."
|
||||
if not reports:
|
||||
return "Вы ещё не отправляли отчёты через VK-бота."
|
||||
|
||||
labels = {"coaching": "Прокачка", "training": "Тренировка", "inspection": "Осмотр"}
|
||||
lines = ["Ваши отправленные отчёты:"]
|
||||
truncated = False
|
||||
for report in reports:
|
||||
raw_timestamp = str(report.get("created_at", ""))
|
||||
try:
|
||||
parsed_timestamp = datetime.fromisoformat(raw_timestamp.replace("Z", "+00:00"))
|
||||
if parsed_timestamp.tzinfo is None:
|
||||
parsed_timestamp = parsed_timestamp.replace(tzinfo=timezone.utc)
|
||||
timestamp = parsed_timestamp.astimezone(ZoneInfo("Europe/Moscow")).strftime("%d.%m.%Y %H:%M")
|
||||
except ValueError:
|
||||
timestamp = raw_timestamp[:16].replace("T", " ") or "Дата неизвестна"
|
||||
label = labels.get(report.get("mode"), "Отчёт")
|
||||
entry = f"\n{timestamp} · {label} · №{report['id']}\n{report['message']}"
|
||||
if sum(map(len, lines)) + len(entry) > 3500:
|
||||
truncated = True
|
||||
break
|
||||
lines.append(entry)
|
||||
if truncated:
|
||||
lines.append("\nПоказана часть последних отчётов. Остальные можно найти на сайте по ID кота.")
|
||||
return "".join(lines)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Запускает VK-бота, настроив API-клиент, хранилища и цикл событий."""
|
||||
|
||||
Reference in new issue
Block a user