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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
from aiogram import types as t
from shared.instances import bot, dp
from utils import filters as f
request_queue: list[int] = []
@dp.chat_join_request_handler()
async def приём_запроса(cjr: t.ChatJoinRequest):
if cjr.from_user.id not in request_queue:
request_queue.append(cjr.from_user.id)
r = await bot.send_message(
cjr.chat.id,
f'<a href="tg://user?id={cjr.from_user.id}">{cjr.from_user.mention}</a> хочет в чат',
parse_mode=t.ParseMode.HTML,
)
await bot.send_poll(
cjr.chat.id,
"Пускаем ?",
[
"Да",
"Нет",
],
False,
reply_to_message_id=r.message_id,
open_period=600,
reply_markup=t.InlineKeyboardMarkup().add(
t.InlineKeyboardButton(
"Проверить опрос",
callback_data=f"check_request_poll:{cjr.from_user.id}",
)
),
)
await bot.send_message(
cjr.from_user.id, "Заявка на вступление в группу будет вскоре рассмотрена"
)
@dp.callback_query_handler(
f.message.is_chat, lambda clb: clb.data.split(":")[0] == "check_request_poll"
)
async def проверить_запрос(clb: t.CallbackQuery):
poll = clb.message.poll
msg = clb.message
data = clb.data.split(":")
user_id = int(data[1])
if poll.total_voter_count < 4:
await clb.answer(f"Нужно хотябы 4 голоса, сейчас {poll.total_voter_count}")
else:
if not poll.is_closed:
await bot.stop_poll(msg.chat.id, msg.message_id)
request_queue.remove(user_id)
yes = poll.options[0].voter_count
no = poll.options[1].voter_count
win = max(yes, no)
if win == yes:
await bot.approve_chat_join_request(msg.chat.id, user_id)
await bot.send_message(
user_id, "Ваша заявка на вступление принята, добро пожаловать в группу"
)
elif win == no:
await bot.decline_chat_join_request(msg.chat.id, user_id)
await bot.send_message(user_id, "Ваша заявка на вступление НЕ принята")
if not msg.chat.has_protected_content:
await msg.forward(user_id)
|