|
@@ -10,38 +10,67 @@ from wbb import app, WELCOME_DELAY_KICK_SEC
|
|
|
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, ChatPermissions, User
|
|
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, ChatPermissions, User
|
|
|
from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant, ChatAdminRequired
|
|
from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant, ChatAdminRequired
|
|
|
from wbb.utils.errors import capture_err
|
|
from wbb.utils.errors import capture_err
|
|
|
|
|
+from wbb.utils.filter_groups import welcome_captcha_group
|
|
|
from wbb.utils.dbfunctions import is_gbanned_user
|
|
from wbb.utils.dbfunctions import is_gbanned_user
|
|
|
|
|
+from random import randint, shuffle
|
|
|
|
|
|
|
|
|
|
+answers = []
|
|
|
|
|
|
|
|
-@app.on_message(filters.new_chat_members)
|
|
|
|
|
|
|
+
|
|
|
|
|
+@app.on_message(filters.new_chat_members, group=welcome_captcha_group)
|
|
|
@capture_err
|
|
@capture_err
|
|
|
async def welcome(_, message: Message):
|
|
async def welcome(_, message: Message):
|
|
|
|
|
+ global answers
|
|
|
"""Mute new member and send message with button"""
|
|
"""Mute new member and send message with button"""
|
|
|
for member in message.new_chat_members:
|
|
for member in message.new_chat_members:
|
|
|
|
|
+ n1 = str(randint(1, 99))
|
|
|
|
|
+ n2 = str(randint(1, 99))
|
|
|
|
|
+ r1 = str(randint(1, 99))
|
|
|
|
|
+ r2 = str(randint(1, 99))
|
|
|
|
|
+ r3 = str(randint(1, 99))
|
|
|
|
|
+ correct_answer = str(int(n1) + int(n2))
|
|
|
|
|
+ answers.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "user_id": member.id,
|
|
|
|
|
+ "correct_answer": correct_answer
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
try:
|
|
try:
|
|
|
if await is_gbanned_user(member.id):
|
|
if await is_gbanned_user(member.id):
|
|
|
await message.chat.kick_member(member.id)
|
|
await message.chat.kick_member(member.id)
|
|
|
continue
|
|
continue
|
|
|
if member.is_bot:
|
|
if member.is_bot:
|
|
|
continue # ignore bots
|
|
continue # ignore bots
|
|
|
- text = (f"Welcome, {(member.mention())}\n**Are you human?**\n"
|
|
|
|
|
- "You will be removed from this chat if you are not verified "
|
|
|
|
|
- f"in {WELCOME_DELAY_KICK_SEC} seconds")
|
|
|
|
|
|
|
+ text = (f"**Welcome**, {(member.mention())}\n**Are you human?**\n"
|
|
|
|
|
+ f"Solve this expression in less than {WELCOME_DELAY_KICK_SEC} seconds.\n"
|
|
|
|
|
+ f"**Expression:** __{n1} + {n2}__")
|
|
|
await message.chat.restrict_member(member.id, ChatPermissions())
|
|
await message.chat.restrict_member(member.id, ChatPermissions())
|
|
|
except ChatAdminRequired:
|
|
except ChatAdminRequired:
|
|
|
continue
|
|
continue
|
|
|
|
|
+
|
|
|
|
|
+ keyboard = [
|
|
|
|
|
+ InlineKeyboardButton(
|
|
|
|
|
+ f"{r1}",
|
|
|
|
|
+ callback_data=f"pressed_button {r1} {member.id}"
|
|
|
|
|
+ ),
|
|
|
|
|
+ InlineKeyboardButton(
|
|
|
|
|
+ f"{r2}",
|
|
|
|
|
+ callback_data=f"pressed_button {r2} {member.id}"
|
|
|
|
|
+ ),
|
|
|
|
|
+ InlineKeyboardButton(
|
|
|
|
|
+ f"{r3}",
|
|
|
|
|
+ callback_data=f"pressed_button {r3} {member.id}"
|
|
|
|
|
+ ),
|
|
|
|
|
+ InlineKeyboardButton(
|
|
|
|
|
+ f"{correct_answer}",
|
|
|
|
|
+ callback_data=f"pressed_button {correct_answer} {member.id}"
|
|
|
|
|
+ )
|
|
|
|
|
+ ]
|
|
|
|
|
+ shuffle(keyboard)
|
|
|
|
|
+ keyb = InlineKeyboardMarkup([keyboard])
|
|
|
button_message = await message.reply(
|
|
button_message = await message.reply(
|
|
|
text,
|
|
text,
|
|
|
- reply_markup=InlineKeyboardMarkup(
|
|
|
|
|
- [
|
|
|
|
|
- [
|
|
|
|
|
- InlineKeyboardButton(
|
|
|
|
|
- "Press Here to Verify",
|
|
|
|
|
- callback_data="pressed_button {}".format(member.id)
|
|
|
|
|
- )
|
|
|
|
|
- ]
|
|
|
|
|
- ]
|
|
|
|
|
- ),
|
|
|
|
|
|
|
+ reply_markup=keyb,
|
|
|
quote=True
|
|
quote=True
|
|
|
)
|
|
)
|
|
|
asyncio.create_task(kick_restricted_after_delay(
|
|
asyncio.create_task(kick_restricted_after_delay(
|
|
@@ -51,13 +80,22 @@ async def welcome(_, message: Message):
|
|
|
|
|
|
|
|
@app.on_callback_query(filters.regex("pressed_button"))
|
|
@app.on_callback_query(filters.regex("pressed_button"))
|
|
|
async def callback_query_welcome_button(client, callback_query):
|
|
async def callback_query_welcome_button(client, callback_query):
|
|
|
|
|
+ global answers
|
|
|
"""After the new member presses the button, set his permissions to
|
|
"""After the new member presses the button, set his permissions to
|
|
|
chat permissions, delete button message and join message
|
|
chat permissions, delete button message and join message
|
|
|
"""
|
|
"""
|
|
|
button_message = callback_query.message
|
|
button_message = callback_query.message
|
|
|
- pending_user = await app.get_users(int(callback_query.data.replace('pressed_button ', '')))
|
|
|
|
|
|
|
+ data = callback_query.data
|
|
|
|
|
+ answer = data.split(None, 2)[1]
|
|
|
|
|
+ pending_user = await app.get_users(int(data.split(None, 2)[2]))
|
|
|
pressed_user_id = callback_query.from_user.id
|
|
pressed_user_id = callback_query.from_user.id
|
|
|
pending_user_id = pending_user.id
|
|
pending_user_id = pending_user.id
|
|
|
|
|
+ for user in answers:
|
|
|
|
|
+ if user['user_id'] == pending_user_id:
|
|
|
|
|
+ if user['correct_answer'] != answer:
|
|
|
|
|
+ await callback_query.answer("That's Wrong, Learn Maths.")
|
|
|
|
|
+ return
|
|
|
|
|
+ break
|
|
|
if pending_user_id == pressed_user_id:
|
|
if pending_user_id == pressed_user_id:
|
|
|
await callback_query.answer("Captcha passed!, Have a nice stay.")
|
|
await callback_query.answer("Captcha passed!, Have a nice stay.")
|
|
|
await button_message.chat.unban_member(pending_user_id)
|
|
await button_message.chat.unban_member(pending_user_id)
|