diff options
Diffstat (limited to 'handlers/pin.py')
| -rw-r--r-- | handlers/pin.py | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/handlers/pin.py b/handlers/pin.py index fc81ed1..9eb91a4 100644 --- a/handlers/pin.py +++ b/handlers/pin.py | |||
| @@ -1,22 +1,21 @@ | |||
| 1 | from aiogram import types as t | 1 | from aiogram import types as t |
| 2 | 2 | ||
| 3 | from shared.instances import bot, dp | 3 | from shared.instances import bot, config, dp |
| 4 | from utils import filters as f | 4 | from utils import filters as f |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | @dp.message_handler(f.message.is_chat, commands=["pin"]) | 7 | @dp.message_handler(f.message.is_chat, commands=["pin"]) |
| 8 | async def закрепить_хуету(msg: t.Message): | 8 | async def pin_command(msg: t.Message) -> None: |
| 9 | await msg.delete() | 9 | await msg.delete() |
| 10 | if msg.reply_to_message: | 10 | if msg.reply_to_message: |
| 11 | r = await msg.reply_to_message.reply( | 11 | reply = await msg.reply_to_message.reply( |
| 12 | f'<a href="tg://user?id={msg.from_user.id}">{msg.from_user.mention}</a> хочет закрепить сообщение', | 12 | f'<a href="tg://user?id={msg.from_user.id}">{msg.from_user.mention}</a> хочет закрепить сообщение', |
| 13 | parse_mode=t.ParseMode.HTML, | 13 | parse_mode=t.ParseMode.HTML, |
| 14 | ) | 14 | ) |
| 15 | await r.reply_poll( | 15 | await reply.reply_poll( |
| 16 | "Закрепить ?", | 16 | "Закрепить сообщение ?", |
| 17 | [ | 17 | [ |
| 18 | "Да", | 18 | "Да", |
| 19 | "УДАЛИ НАХУЙ", | ||
| 20 | "Нет", | 19 | "Нет", |
| 21 | ], | 20 | ], |
| 22 | reply_markup=t.InlineKeyboardMarkup().add( | 21 | reply_markup=t.InlineKeyboardMarkup().add( |
| @@ -33,23 +32,18 @@ async def закрепить_хуету(msg: t.Message): | |||
| 33 | @dp.callback_query_handler( | 32 | @dp.callback_query_handler( |
| 34 | f.message.is_chat, lambda clb: clb.data.split(":")[0] == "check_pin_poll" | 33 | f.message.is_chat, lambda clb: clb.data.split(":")[0] == "check_pin_poll" |
| 35 | ) | 34 | ) |
| 36 | async def проверить_закреп(clb: t.CallbackQuery): | 35 | async def check_poll(clb: t.CallbackQuery) -> None: |
| 37 | poll = clb.message.poll | 36 | poll = clb.message.poll |
| 38 | msg = clb.message | 37 | msg = clb.message |
| 39 | pin = int(clb.data.split(":")[1]) | 38 | pin = int(clb.data.split(":")[1]) |
| 39 | min_answers = config.get_config(msg.chat.id).commands.pin_answers_count | ||
| 40 | 40 | ||
| 41 | if poll.total_voter_count < 2: | 41 | if poll.total_voter_count < min_answers: |
| 42 | await clb.answer(f"Нужно хотябы 2 голоса, сейчас {poll.total_voter_count}") | 42 | await clb.answer( |
| 43 | f"Нужно хотябы {min_answers} голоса, сейчас {poll.total_voter_count}" | ||
| 44 | ) | ||
| 43 | else: | 45 | else: |
| 46 | if poll.options[0].voter_count > poll.options[1].voter_count: | ||
| 47 | await msg.chat.pin_message(pin) | ||
| 44 | if not poll.is_closed: | 48 | if not poll.is_closed: |
| 45 | await bot.stop_poll(msg.chat.id, msg.message_id) | 49 | await bot.stop_poll(msg.chat.id, msg.message_id) |
| 46 | |||
| 47 | yes = poll.options[0].voter_count | ||
| 48 | delete = poll.options[1].voter_count | ||
| 49 | win = max(yes, delete) | ||
| 50 | |||
| 51 | if win == yes: | ||
| 52 | await msg.chat.pin_message(pin) | ||
| 53 | elif win == delete: | ||
| 54 | await msg.chat.delete_message(pin) | ||
| 55 | await msg.delete() | ||
