import asyncio from config import BOT_USERNAME, SUDO_USERS from driver.decorators import authorized_users_only, sudo_users_only, errors from driver.filters import command from driver.veez import bot as USER from pyrogram import Client, filters from pyrogram.errors import UserAlreadyParticipant @Client.on_message( command(["userbotjoin", f"userbotjoin@{BOT_USERNAME}"]) & ~filters.private & ~filters.bot ) @authorized_users_only @errors async def join_group(client, message): chid = message.chat.id try: invitelink = await client.export_chat_invite_link(chid) except BaseException: await message.reply_text( "โ€ข **i'm not have permission:**\n\nยป โŒ __Add Users__", ) return try: user = await USER.get_me() except BaseException: user.first_name = "music assistant" try: await USER.join_chat(invitelink) except UserAlreadyParticipant: pass except Exception as e: print(e) await message.reply_text( f"๐Ÿ›‘ Flood Wait Error ๐Ÿ›‘ \n\n**userbot couldn't join your group due to heavy join requests for userbot**" "\n\n**or add assistant manually to your Group and try again**", ) return await message.reply_text( f"โœ… **userbot succesfully entered chat**", ) @Client.on_message(command(["userbotleave", f"leave@{BOT_USERNAME}"]) & filters.group & ~filters.edited) @authorized_users_only async def leave_one(client, message): try: await USER.send_message(message.chat.id, "โœ… userbot successfully left chat") await USER.leave_chat(message.chat.id) except BaseException: await message.reply_text( "โŒ **userbot couldn't leave your group, may be floodwaits.**\n\n**ยป or manually kick userbot from your group**" ) return @Client.on_message(command(["leaveall", f"leaveall@{BOT_USERNAME}"])) @sudo_users_only async def leave_all(client, message): if message.from_user.id not in SUDO_USERS: return left = 0 failed = 0 lol = await message.reply("๐Ÿ”„ **userbot** leaving all chats !") async for dialog in USER.iter_dialogs(): try: await USER.leave_chat(dialog.chat.id) left += 1 await lol.edit( f"Userbot leaving all group...\n\nLeft: {left} chats.\nFailed: {failed} chats." ) except BaseException: failed += 1 await lol.edit( f"Userbot leaving...\n\nLeft: {left} chats.\nFailed: {failed} chats." ) await asyncio.sleep(0.7) await client.send_message( message.chat.id, f"โœ… Left from: {left} chats.\nโŒ Failed in: {failed} chats." )