aboutsummaryrefslogtreecommitdiff
path: root/handlers/pin.py
blob: fc81ed14f656eef37f8ba197b7c6161d859cc993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from aiogram import types as t

from shared.instances import bot, dp
from utils import filters as f


@dp.message_handler(f.message.is_chat, commands=["pin"])
async def закрепить_хуету(msg: t.Message):
    await msg.delete()
    if msg.reply_to_message:
        r = await msg.reply_to_message.reply(
            f'<a href="tg://user?id={msg.from_user.id}">{msg.from_user.mention}</a> хочет закрепить сообщение',
            parse_mode=t.ParseMode.HTML,
        )
        await r.reply_poll(
            "Закрепить ?",
            [
                "Да",
                "УДАЛИ НАХУЙ",
                "Нет",
            ],
            reply_markup=t.InlineKeyboardMarkup().add(
                t.InlineKeyboardButton(
                    "Проверить опрос",
                    callback_data=f"check_pin_poll:{msg.reply_to_message.message_id}",
                )
            ),
        )
    else:
        await msg.answer("Ты умник, ответь на сообщение")


@dp.callback_query_handler(
    f.message.is_chat, lambda clb: clb.data.split(":")[0] == "check_pin_poll"
)
async def проверить_закреп(clb: t.CallbackQuery):
    poll = clb.message.poll
    msg = clb.message
    pin = int(clb.data.split(":")[1])

    if poll.total_voter_count < 2:
        await clb.answer(f"Нужно хотябы 2 голоса, сейчас {poll.total_voter_count}")
    else:
        if not poll.is_closed:
            await bot.stop_poll(msg.chat.id, msg.message_id)

        yes = poll.options[0].voter_count
        delete = poll.options[1].voter_count
        win = max(yes, delete)

        if win == yes:
            await msg.chat.pin_message(pin)
        elif win == delete:
            await msg.chat.delete_message(pin)
        await msg.delete()