diff options
| author | Igor Tolmachov <me@igorek.dev> | 2022-12-05 22:29:41 +0900 |
|---|---|---|
| committer | Igor Tolmachov <me@igorek.dev> | 2022-12-05 22:29:41 +0900 |
| commit | 0de7969d30e3e57d681afdfcadd245f6988a0342 (patch) | |
| tree | bc0957e9208f51354aa2330dc20a090b7f680823 /handlers/config.py | |
| parent | 0d5cab62b0d077ad7946b64a534e3914f1cc79dd (diff) | |
| download | karpov_ai_bot-0de7969d30e3e57d681afdfcadd245f6988a0342.tar.gz karpov_ai_bot-0de7969d30e3e57d681afdfcadd245f6988a0342.zip | |
2.1
Diffstat (limited to 'handlers/config.py')
| -rw-r--r-- | handlers/config.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/handlers/config.py b/handlers/config.py index 7628805..2865694 100644 --- a/handlers/config.py +++ b/handlers/config.py | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | from copy import deepcopy | ||
| 1 | from json import JSONDecodeError, dumps, loads | 2 | from json import JSONDecodeError, dumps, loads |
| 2 | from logging import info | 3 | from logging import info |
| 3 | 4 | ||
| @@ -5,7 +6,8 @@ from aiogram import types as t | |||
| 5 | from pydantic import BaseModel, ValidationError | 6 | from pydantic import BaseModel, ValidationError |
| 6 | 7 | ||
| 7 | from shared.database import Message | 8 | from shared.database import Message |
| 8 | from shared.instances import config, dp, session | 9 | from shared.instances import chats, dp, session |
| 10 | from shared.samples import samples | ||
| 9 | from shared.settings import Config | 11 | from shared.settings import Config |
| 10 | from utils import filters as f | 12 | from utils import filters as f |
| 11 | 13 | ||
| @@ -13,9 +15,19 @@ from utils import filters as f | |||
| 13 | @dp.message_handler(f.user.is_admin, commands=["void"]) | 15 | @dp.message_handler(f.user.is_admin, commands=["void"]) |
| 14 | async def void_command(msg: t.Message) -> None: | 16 | async def void_command(msg: t.Message) -> None: |
| 15 | if msg.get_args() == "Я знаю что делаю": | 17 | if msg.get_args() == "Я знаю что делаю": |
| 18 | samples.delete(msg.chat.id) | ||
| 16 | with session.begin() as s: | 19 | with session.begin() as s: |
| 17 | s.query(Message).filter(Message.chat_id == msg.chat.id).delete() | 20 | query = s.query(Message).filter(Message.chat_id == msg.chat.id) |
| 18 | await msg.answer("Лоботомия проведена успешно") | 21 | if msg.reply_to_message is not None: |
| 22 | query = query.filter(Message.user_id == msg.reply_to_message.from_user.id) | ||
| 23 | query.delete() | ||
| 24 | if msg.reply_to_message is not None: | ||
| 25 | await msg.answer( | ||
| 26 | f'Связи пользователя <a href="tg://user?id={msg.reply_to_message.from_user.id}">{msg.reply_to_message.from_user.mention}</a> были очищены', | ||
| 27 | parse_mode=t.ParseMode.HTML, | ||
| 28 | ) | ||
| 29 | else: | ||
| 30 | await msg.answer("Связи были очищены") | ||
| 19 | else: | 31 | else: |
| 20 | await msg.answer( | 32 | await msg.answer( |
| 21 | "Напишите <code>/void Я знаю что делаю</code>", | 33 | "Напишите <code>/void Я знаю что делаю</code>", |
| @@ -79,7 +91,7 @@ async def settings_command(msg: t.Message) -> None: | |||
| 79 | 91 | ||
| 80 | return text | 92 | return text |
| 81 | 93 | ||
| 82 | chat_config = config.get_config(msg.chat.id) | 94 | chat_config = deepcopy(chats.get(msg.chat.id)) |
| 83 | args = msg.get_args().split() | 95 | args = msg.get_args().split() |
| 84 | if len(args) == 0: | 96 | if len(args) == 0: |
| 85 | text = f"<code>/config</code>{get_fields(chat_config)}" | 97 | text = f"<code>/config</code>{get_fields(chat_config)}" |
| @@ -88,8 +100,7 @@ async def settings_command(msg: t.Message) -> None: | |||
| 88 | elif len(args) == 2: | 100 | elif len(args) == 2: |
| 89 | try: | 101 | try: |
| 90 | text = set_filed(chat_config, args[0].split("."), args[1]) | 102 | text = set_filed(chat_config, args[0].split("."), args[1]) |
| 91 | config.set_config(msg.chat.id, Config.parse_obj(chat_config.dict())) | 103 | chats.set(msg.chat.id, Config.parse_obj(chat_config.dict())) |
| 92 | config.save("data/config.json") | ||
| 93 | except (JSONDecodeError, ValidationError): | 104 | except (JSONDecodeError, ValidationError): |
| 94 | text = "Неверное значение" | 105 | text = "Неверное значение" |
| 95 | else: | 106 | else: |
