fix(goal): bound public calculator inputs

This commit is contained in:
nyan404 committed 2026-08-25 03:34:58 +03:00
1 parent 041d717439
commit 5d6e5987d1
8 files changed
+58 -8

No files matched your search

+8 -2
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import json
from math import isfinite
import os
import random
import re
@@ -1283,12 +1284,17 @@ class BelkiDialog:
value = float(text.replace(",", "."))
except ValueError:
return "Баллы укажите числом, например 12 или 12,5."
if not isfinite(value):
return "Баллы укажите конечным числом, например 12 или 12,5."
if value < 0:
return "Баллы не могут быть отрицательными."
state[key] = int(value) if value.is_integer() else value
elif key in ("minutes_per_session", "kitten_count"):
if not re.fullmatch(r"\d+", text) or int(text) <= 0:
return "Укажите положительное целое число."
from .domain import MAX_GOAL_KITTENS, MAX_GOAL_MINUTES_PER_SESSION
maximum = MAX_GOAL_MINUTES_PER_SESSION if key == "minutes_per_session" else MAX_GOAL_KITTENS
if not re.fullmatch(r"\d+", text) or not 0 < int(text) <= maximum:
label = "длительность захода" if key == "minutes_per_session" else "количество котят"
return f"Укажите {label}: целое число от 1 до {maximum}."
state[key] = int(text)
elif key == "kitten_independence":
value = self._independence(text)