diff --git a/AI/talk_handler.py b/AI/talk_handler.py index e88b073..2e99a10 100644 --- a/AI/talk_handler.py +++ b/AI/talk_handler.py @@ -20,7 +20,7 @@ logger = logging.getLogger(__name__) # Основные настройки поведения и стиля бота редактируются здесь. LLAMA_API_URL = os.getenv("LLAMA_API_URL", "https://mirror.porno4free.ru/zovos-ai/") -DB_PATH = os.getenv("CHAT_HISTORY_DB_PATH") or str(Path(__file__).resolve().with_name("chat_history.sqlite3")) +DB_PATH = os.getenv("CHAT_HISTORY_DB_PATH") or getattr(__import__("config"), "CHAT_HISTORY_DB_PATH", str(Path(__file__).resolve().with_name("chat_history.sqlite3"))) BOT_MEMORY_NAME = os.getenv("BOT_MEMORY_NAME", "бот") SKIP_TOKEN = "" FORCE_DISABLE_THINKING = os.getenv("LLAMA_FORCE_DISABLE_THINKING", "1").lower() not in {"0", "false", "no"} diff --git a/games/betting.py b/games/betting.py index 933da3c..d805de8 100644 --- a/games/betting.py +++ b/games/betting.py @@ -59,7 +59,10 @@ def _init_bets_db() -> None: conn.commit() -_init_bets_db() +try: + _init_bets_db() +except Exception: + logger.warning("Could not init bets DB at import time (will retry on first use)") def remember_user_sport_context(user_id: int, sport_alias: str) -> None: diff --git a/games/casino.py b/games/casino.py index 6c4a534..1d4e744 100644 --- a/games/casino.py +++ b/games/casino.py @@ -57,6 +57,9 @@ def update_user_length(user_id: int, delta: float) -> float | None: if row is None: return None new_length = round(float(row[0]) + delta, 1) + # Не даём уйти ниже 0 при проигрыше + if delta < 0 and new_length < 0: + new_length = 0.0 conn.execute( "UPDATE penis_stats SET length = ? WHERE user_id = ?", (new_length, user_id), @@ -68,6 +71,7 @@ def update_user_length(user_id: int, delta: float) -> float | None: return None + def play_casino(user_id: int, bet: float) -> str: current = get_user_length(user_id) if current is None: diff --git a/games/fortune.py b/games/fortune.py index 7ac5c71..c4d9593 100644 --- a/games/fortune.py +++ b/games/fortune.py @@ -30,7 +30,7 @@ async def generate_fortune(topic: str) -> tuple[str, str, str]: } async with aiohttp.ClientSession() as session: - async with session.post(url, json=payload, timeout=aiohttp.ClientTimeout(total=120)) as resp: + async with session.post(url, json=payload, timeout=aiohttp.ClientTimeout(total=30)) as resp: data = await resp.json() text = data["choices"][0]["message"]["content"].strip() diff --git a/games/uwu.py b/games/uwu.py index 831d09e..9b7db44 100644 --- a/games/uwu.py +++ b/games/uwu.py @@ -55,28 +55,6 @@ CAPTIONS = [ "Я нейросеть, помогите, меня держат в заложниках" ] -async def handle_uwu_cmd(message: types.Message): - args = message.text.split(maxsplit=1) - - if len(args) > 1 and args[1].strip() == "-h": - help_msg = ( - "🐈 Справка по тегам e621:\n\n" - "Перечислите любые теги через пробел после команды.\n" - "• rating: rating:safe (безопасные), rating:questionable, rating:explicit (NSFW)\n" - "• score: score:>500 (искать популярные посты с рейтингом больше 500)\n" - "• Исключить тег: поставьте минус, например -fox\n\n" - "Пример: /uwu wolf -rating:explicit score:>100\n" - "По умолчанию: rating:safe score:>500 -animated" - ) - await message.reply(help_msg, parse_mode="HTML") - return - - tags = "rating:safe score:>500 -animated" - if len(args) > 1: - tags = args[1].strip() - - tags += " order:random score:>300" - async def fetch_uwu_post(tags: str) -> dict: url = "https://e621.net/posts.json" params = { diff --git a/main.py b/main.py index 64b337d..02b60ef 100644 --- a/main.py +++ b/main.py @@ -597,11 +597,14 @@ def minutes_until_next_lesson(now: datetime | None = None) -> str: start_today = lesson_start_for(0) end_today = lesson_end_today() if start_today <= now < end_today: + next_dt = None for i in range(1, 8): next_day = (day + i) % 7 if next_day in lesson_days: next_dt = lesson_start_for(i) break + if next_dt is None: + return "Следующий урок не найден." delta = next_dt - now total_seconds = int(delta.total_seconds()) days = total_seconds // 86400 @@ -613,6 +616,7 @@ def minutes_until_next_lesson(now: datetime | None = None) -> str: f"Мозг начнет догнивать через {days} дн {hours} ч {minutes} мин" ) + delta = None for i in range(0, 8): next_day = (day + i) % 7 if next_day in lesson_days: @@ -621,12 +625,16 @@ def minutes_until_next_lesson(now: datetime | None = None) -> str: delta = candidate - now break + if delta is None: + return "Ближайший урок не найден, кайфуй." + total_seconds = int(delta.total_seconds()) days = total_seconds // 86400 hours = (total_seconds % 86400) // 3600 minutes = (total_seconds % 3600) // 60 return f"Твой мозг окончательно сгниет, а очко порвется через: {days} дн {hours} ч {minutes} мин" + def _prepare_magnit_query(value: str) -> str: value = re.sub(r"(?<=[a-zа-яё])(?=[A-ZА-ЯЁ])", " ", value) value = re.sub(r"[_-]+", " ", value)