From 8e2b19caa5d92ddad8a8e87b6aae724d3198a14b Mon Sep 17 00:00:00 2001 From: Igor Tolmachov Date: Sat, 9 Jul 2022 12:59:06 +0900 Subject: Фикс бага MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/gen.py | 4 ++-- shared/config.py | 8 ++++++-- utils/filters.py | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/handlers/gen.py b/handlers/gen.py index 43301c5..b618fec 100644 --- a/handlers/gen.py +++ b/handlers/gen.py @@ -43,7 +43,7 @@ async def изменить_шанс_срания(msg: t.Message): try: chance = int(msg.get_args().split()[0]) if 0 <= chance <= 100: - config.chances[msg.chat.id] = chance + config.chances[str(msg.chat.id)] = chance config.save() else: raise RuntimeError() @@ -54,7 +54,7 @@ async def изменить_шанс_срания(msg: t.Message): "Я хз что не так, но я знаю что ты дебил \n /chance <ЧИСЛО ОТ 0 ДО 100>" ) else: - await msg.answer(f"Я сру с шансом в: {config.chances.get(msg.chat.id, 10)}%") + await msg.answer(f"Я сру с шансом в: {config.chances.get(str(msg.chat.id), 10)}%") @dp.message_handler(f.message.chance, content_types=[t.ContentType.ANY]) diff --git a/shared/config.py b/shared/config.py index 4c64220..09ced45 100644 --- a/shared/config.py +++ b/shared/config.py @@ -1,11 +1,15 @@ +import logging from copy import deepcopy from json import dump, load from os import environ as env from os import path from typing import Any +logging.info("Load configs") + if not path.exists("data/settings.json"): - open("data/settings.json", "w").close() + with open("data/settings.json", "w") as f: + f.write("{}") fields: dict[str, Any] = { "chances": {}, } @@ -21,4 +25,4 @@ def save(): # Configs token = env["TOKEN"] -chances = settings["chances"] +chances: dict[str, int] = settings["chances"] diff --git a/utils/filters.py b/utils/filters.py index 5dc280b..9b8ce5c 100644 --- a/utils/filters.py +++ b/utils/filters.py @@ -13,7 +13,7 @@ class message: @staticmethod def chance(msg: t.Message): - return config.chances.get(msg.chat.id, 10) >= randint(1, 100) + return config.chances.get(str(msg.chat.id), 10) >= randint(1, 100) @staticmethod def has_text(msg: t.Message): -- cgit v1.2.3