Untitled
unknown
python
2 years ago
2.4 kB
3
Indexable
Never
from pyrogram import Client, filters from datetime import datetime, timedelta from apscheduler.schedulers.asyncio import AsyncIOScheduler api_id = "i've cencored it" api_hash = "i've cencored it" bot_token = "i've cencored it" app = Client("capthca", api_id, api_hash, bot_token) scheduler = AsyncIOScheduler() # The third params is bot message id async def kickMember(chat_id, user, message_id): await app.ban_chat_member(chat_id, user.id) await app.send_message(chat_id, f"**{user.mention()} has been banned!**") await app.delete_messages(chat_id, message_id) scheduler.remove_job(user.id) async def approveMember(chat_id, user, message_id, user_new_message_id): await app.send_message(chat_id, f"**{user.mention()} welcome!**") await app.delete_messages(chat_id, message_id) await app.send_message(f"{user_new_message_id}") @app.on_message(filters.new_chat_members) async def verifyMember(client, message): timeStart = datetime.now() timeKick = timeStart + timedelta(minutes=5) timeApprove = timeStart + timedelta(minutes=10) # Approval time is set longer than timeKick so it's not auto-approved bot_send_message = await app.send_message(message.chat.id, f"hi {message.new_chat_members[0].mention()}\n\ncepat ketik **I'm not robot** or you will be kicked on 5 minutes") scheduler.add_job(kickMember, "date", run_date=timeKick, args=(message.chat.id, message.new_chat_members[0], bot_send_message.message_id), id=f"{message.new_chat_members[0].id}") # Empty string on fourth params is to user message id on "I'm not robot" scheduler.add_job(approveMember, "date", run_date=timeApprove, args=(message.chat.id, message.new_chat_members[0], bot_send_message.message_id, ""), id=f"{message.new_chat_members[0].id}approve") @app.on_message(filters.text) async def filterMessage(client, message): if message.text == "I'm not robot": checkJobAvailable = scheduler.get_job(f"{message.from_user.id}") if checkJobAvailable != None: # remove kickMember job scheduler.remove_job(f"{message.from_user.id}") # run approveMember scheduler.modify_job(f"{message.from_user.id}approve", next_run_time=datetime.now(), args=(message.chat.id, message.new_chat_members[0], bot_send_message.message_id, message.message_id)) scheduler.start() app.run()