diff --git a/app/belki/vk_bot.py b/app/belki/vk_bot.py index 4e1ef2c..b8c3f14 100644 --- a/app/belki/vk_bot.py +++ b/app/belki/vk_bot.py @@ -47,6 +47,7 @@ HELP_TEXT = ( "/осмотр дупло 6 Имя [ID] | вьюнок=1, паук=1\n\n" "Если убрать разделители |, бот поймёт строку и так, например:\n" "15.08 11:00 11:20 Дикая Вишня 1604614 Серолап 1617140\n" + "Дату также можно написать словами: «15 августа».\n" "Для статуса котёнка подойдут сокращения «сам» и «несам».\n\n" "Перед отправкой бот покажет, что понял, и попросит подтвердить. Каждый заход вводится отдельно. Скриншоты прикрепляйте вручную.\n\n" "Чтобы сбросить ввод, напишите /отмена.\n\n" @@ -75,6 +76,20 @@ _ROLE_TYPO_WORDS = ( "учитель", "учительница", "ведущий", "ведущая", "ученик", "ученица", "котёнок", "бельчонок", "подопечный", "подопечная", ) +_RUSSIAN_MONTHS = { + "января": 1, "январь": 1, "янв": 1, + "февраля": 2, "февраль": 2, "фев": 2, + "марта": 3, "март": 3, "мар": 3, + "апреля": 4, "апрель": 4, "апр": 4, + "мая": 5, "май": 5, + "июня": 6, "июнь": 6, "июн": 6, + "июля": 7, "июль": 7, "июл": 7, + "августа": 8, "август": 8, "авг": 8, + "сентября": 9, "сентябрь": 9, "сен": 9, "сент": 9, + "октября": 10, "октябрь": 10, "окт": 10, + "ноября": 11, "ноябрь": 11, "ноя": 11, + "декабря": 12, "декабрь": 12, "дек": 12, +} _INSPECTION_COUNT_RE = re.compile( r"(?i)(?\d{1,6})\s*(?:раз(?:а|ов)?|осмотр(?:а|ов)?)\b" ) @@ -134,6 +149,15 @@ def _normalise_natural_text(text: str) -> str: text = text.replace("—", "-").replace("–", "-").replace("−", "-") text = re.sub(r"(?i)\b(?:id|айди|№)\s*(?=\d)", "", text) text = _SPACED_ID_RE.sub(lambda match: match.group(1).replace(" ", ""), text) + def normalise_written_date(match: re.Match[str]) -> str: + return f"{int(match.group('day'))}.{_RUSSIAN_MONTHS[match.group('month').casefold()]:02d}" + + text = re.sub( + r"(?i)\b(?P[12]?\d|3[01])(?:-?го)?\s+(?P" + + "|".join(_RUSSIAN_MONTHS) + r")\b", + normalise_written_date, + text, + ) text = re.sub(r"\b(\d{1,2})[/-](\d{1,2})\b", r"\1.\2", text) # A bare ``15.08`` is a date, not 15:08. Preserve the first dotted pair # as the report date and treat later dotted pairs as clock values. diff --git a/structure_and_data.md b/structure_and_data.md index 66d9027..21cdd52 100644 --- a/structure_and_data.md +++ b/structure_and_data.md @@ -75,6 +75,7 @@ - 2026-08-25: shared domain limits now bound public calculation fan-out: at most 50 coaching kittens, 100 inspection resource rows, 100000 inspections, and 100000 units of one resource. API and VK reject oversized kitten lists before calculation. - 2026-08-25: report copy now uses a plural construction for several kittens, normative `провёл(-ла)` for lessons, and a readable empty-resource line instead of a standalone `0`. - 2026-08-25: free-form inspection parsing now distinguishes a labelled count (or a count immediately after the place) from date fragments and character IDs; it also understands explicit character labels and both `+N ресурс` and legacy `ресурс=N` loot notation. +- 2026-08-25: free-form coaching input additionally normalizes Russian written month names and common abbreviations (for example, `24 августа` and `1-го сент`) into the existing `ДД.ММ` date field. - 2026-08-25: `/api/admin/auth` now permits five password attempts per source in a rolling 15-minute window and clears that local budget after a successful sign-in. Edge rate limiting and TLS remain required deployment controls. # Обновление 2026-08-16: несколько котят diff --git a/tests/test_vk_conversation.py b/tests/test_vk_conversation.py index 96b8a0f..4dea116 100644 --- a/tests/test_vk_conversation.py +++ b/tests/test_vk_conversation.py @@ -157,6 +157,14 @@ class VkConversationTests(unittest.TestCase): self.assertEqual((inspected["fields"]["escort_name"], inspected["fields"]["escort_id"]), ("Дикая Вишня", 1604614)) self.assertEqual((inspected["fields"]["kitten_name"], inspected["fields"]["kitten_id"]), ("Серопопик", 1346767)) + def test_natural_bulk_input_normalizes_russian_written_dates(self): + for date_text, expected in (("24 августа", "24.08"), ("1-го сент", "1.09")): + with self.subTest(date_text=date_text): + inspected = inspect_bulk_text( + f"ЛУ {date_text} 21:00-22:00 Дикая Вишня [1604614] Серопопик [1346767] сам" + ) + self.assertEqual(inspected["fields"]["date"], expected) + def test_natural_zu_with_nonself_status_becomes_a_clarification_not_an_exception(self): inspected = inspect_bulk_text("24.08 ЗУ 21:00 22:00 Белка [1] Ученик [2] несам") self.assertEqual(inspected["status"], "needs_clarification") diff --git a/web/calculator.html b/web/calculator.html index 6712723..7338a86 100644 --- a/web/calculator.html +++ b/web/calculator.html @@ -79,7 +79,7 @@
Быстрый ввод

Вставьте данные одной строкой — символы | не нужны. Мы распознаем заполненные поля и подскажем, что ещё указать.

- +