aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Tolmachov <me@igorek.dev>2022-07-09 12:59:06 +0900
committerIgor Tolmachov <me@igorek.dev>2022-07-09 12:59:06 +0900
commit8e2b19caa5d92ddad8a8e87b6aae724d3198a14b (patch)
tree0186c54017430fcbdab14cbfc8a22e4ea68a274d
parentdd5afe2b16cf6f5acb8f3345617a7aa9d8b01c57 (diff)
downloadkarpov_ai_bot-8e2b19caa5d92ddad8a8e87b6aae724d3198a14b.tar.gz
karpov_ai_bot-8e2b19caa5d92ddad8a8e87b6aae724d3198a14b.zip
Фикс бага
-rw-r--r--handlers/gen.py4
-rw-r--r--shared/config.py8
-rw-r--r--utils/filters.py2
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):
43 try: 43 try:
44 chance = int(msg.get_args().split()[0]) 44 chance = int(msg.get_args().split()[0])
45 if 0 <= chance <= 100: 45 if 0 <= chance <= 100:
46 config.chances[msg.chat.id] = chance 46 config.chances[str(msg.chat.id)] = chance
47 config.save() 47 config.save()
48 else: 48 else:
49 raise RuntimeError() 49 raise RuntimeError()
@@ -54,7 +54,7 @@ async def изменить_шанс_срания(msg: t.Message):
54 "Я хз что не так, но я знаю что ты дебил \n /chance <ЧИСЛО ОТ 0 ДО 100>" 54 "Я хз что не так, но я знаю что ты дебил \n /chance <ЧИСЛО ОТ 0 ДО 100>"
55 ) 55 )
56 else: 56 else:
57 await msg.answer(f"Я сру с шансом в: {config.chances.get(msg.chat.id, 10)}%") 57 await msg.answer(f"Я сру с шансом в: {config.chances.get(str(msg.chat.id), 10)}%")
58 58
59 59
60@dp.message_handler(f.message.chance, content_types=[t.ContentType.ANY]) 60@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 @@
1import logging
1from copy import deepcopy 2from copy import deepcopy
2from json import dump, load 3from json import dump, load
3from os import environ as env 4from os import environ as env
4from os import path 5from os import path
5from typing import Any 6from typing import Any
6 7
8logging.info("Load configs")
9
7if not path.exists("data/settings.json"): 10if not path.exists("data/settings.json"):
8 open("data/settings.json", "w").close() 11 with open("data/settings.json", "w") as f:
12 f.write("{}")
9fields: dict[str, Any] = { 13fields: dict[str, Any] = {
10 "chances": {}, 14 "chances": {},
11} 15}
@@ -21,4 +25,4 @@ def save():
21 25
22# Configs 26# Configs
23token = env["TOKEN"] 27token = env["TOKEN"]
24chances = settings["chances"] 28chances: 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:
13 13
14 @staticmethod 14 @staticmethod
15 def chance(msg: t.Message): 15 def chance(msg: t.Message):
16 return config.chances.get(msg.chat.id, 10) >= randint(1, 100) 16 return config.chances.get(str(msg.chat.id), 10) >= randint(1, 100)
17 17
18 @staticmethod 18 @staticmethod
19 def has_text(msg: t.Message): 19 def has_text(msg: t.Message):