diff options
Diffstat (limited to 'handlers/member.py')
| -rw-r--r-- | handlers/member.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/handlers/member.py b/handlers/member.py index c4b1495..a4fc4cc 100644 --- a/handlers/member.py +++ b/handlers/member.py | |||
| @@ -1,17 +1,17 @@ | |||
| 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.chat_join_request_handler() | 7 | @dp.chat_join_request_handler() |
| 8 | async def приём_запроса(cjr: t.ChatJoinRequest): | 8 | async def new_member(cjr: t.ChatJoinRequest) -> None: |
| 9 | r = await bot.send_message( | 9 | reply = await bot.send_message( |
| 10 | cjr.chat.id, | 10 | cjr.chat.id, |
| 11 | f'<a href="tg://user?id={cjr.from_user.id}">{cjr.from_user.mention}</a> хочет в чат', | 11 | f'<a href="tg://user?id={cjr.from_user.id}">{cjr.from_user.mention}</a> хочет в чат', |
| 12 | parse_mode=t.ParseMode.HTML, | 12 | parse_mode=t.ParseMode.HTML, |
| 13 | ) | 13 | ) |
| 14 | await r.reply_poll( | 14 | await reply.reply_poll( |
| 15 | "Пускаем ?", | 15 | "Пускаем ?", |
| 16 | [ | 16 | [ |
| 17 | "Да", | 17 | "Да", |
| @@ -33,28 +33,27 @@ async def приём_запроса(cjr: t.ChatJoinRequest): | |||
| 33 | @dp.callback_query_handler( | 33 | @dp.callback_query_handler( |
| 34 | f.message.is_chat, lambda clb: clb.data.split(":")[0] == "check_request_poll" | 34 | f.message.is_chat, lambda clb: clb.data.split(":")[0] == "check_request_poll" |
| 35 | ) | 35 | ) |
| 36 | async def проверить_запрос(clb: t.CallbackQuery): | 36 | async def check_poll(clb: t.CallbackQuery) -> None: |
| 37 | poll = clb.message.poll | 37 | poll = clb.message.poll |
| 38 | msg = clb.message | 38 | msg = clb.message |
| 39 | data = clb.data.split(":") | 39 | data = clb.data.split(":") |
| 40 | user_id = int(data[1]) | 40 | user_id = int(data[1]) |
| 41 | min_answers = config.get_config(msg.chat.id).commands.accept_member_answers_count | ||
| 41 | 42 | ||
| 42 | if poll.total_voter_count < 4: | 43 | if poll.total_voter_count < min_answers: |
| 43 | await clb.answer(f"Нужно хотябы 4 голоса, сейчас {poll.total_voter_count}") | 44 | await clb.answer( |
| 45 | f"Нужно хотябы {min_answers} голоса, сейчас {poll.total_voter_count}" | ||
| 46 | ) | ||
| 44 | else: | 47 | else: |
| 45 | if not poll.is_closed: | 48 | if not poll.is_closed: |
| 46 | await bot.stop_poll(msg.chat.id, msg.message_id) | 49 | await bot.stop_poll(msg.chat.id, msg.message_id) |
| 47 | 50 | ||
| 48 | yes = poll.options[0].voter_count | 51 | if poll.options[0].voter_count > poll.options[1].voter_count: |
| 49 | no = poll.options[1].voter_count | ||
| 50 | win = max(yes, no) | ||
| 51 | |||
| 52 | if win == yes: | ||
| 53 | await bot.approve_chat_join_request(msg.chat.id, user_id) | 52 | await bot.approve_chat_join_request(msg.chat.id, user_id) |
| 54 | await bot.send_message( | 53 | await bot.send_message( |
| 55 | user_id, "Ваша заявка на вступление принята, добро пожаловать в группу" | 54 | user_id, "Ваша заявка на вступление принята, добро пожаловать в группу" |
| 56 | ) | 55 | ) |
| 57 | elif win == no: | 56 | else: |
| 58 | await bot.decline_chat_join_request(msg.chat.id, user_id) | 57 | await bot.decline_chat_join_request(msg.chat.id, user_id) |
| 59 | await bot.send_message(user_id, "Ваша заявка на вступление НЕ принята") | 58 | await bot.send_message(user_id, "Ваша заявка на вступление НЕ принята") |
| 60 | if not msg.chat.has_protected_content: | 59 | if not msg.chat.has_protected_content: |
