2021-10-11 03:16:54 +00:00
|
|
|
import asyncio
|
2021-11-25 14:19:17 +00:00
|
|
|
from driver.veez import user
|
2021-11-25 15:07:02 +00:00
|
|
|
from pyrogram.types import Message
|
|
|
|
from pyrogram import Client, filters
|
2021-10-11 03:16:54 +00:00
|
|
|
from config import BOT_USERNAME, SUDO_USERS
|
2021-10-28 05:30:52 +00:00
|
|
|
from driver.filters import command, other_filters
|
2021-10-11 03:16:54 +00:00
|
|
|
from pyrogram.errors import UserAlreadyParticipant
|
2021-11-25 15:07:02 +00:00
|
|
|
from driver.decorators import authorized_users_only, sudo_users_only
|
2021-10-25 09:10:11 +00:00
|
|
|
|
2021-10-11 03:16:54 +00:00
|
|
|
|
|
|
|
@Client.on_message(
|
|
|
|
command(["userbotjoin", f"userbotjoin@{BOT_USERNAME}"]) & ~filters.private & ~filters.bot
|
|
|
|
)
|
|
|
|
@authorized_users_only
|
2021-11-25 14:19:17 +00:00
|
|
|
async def join_chat(c: Client, m: Message):
|
|
|
|
chat_id = m.chat.id
|
2021-10-11 03:16:54 +00:00
|
|
|
try:
|
2021-11-25 14:19:17 +00:00
|
|
|
invite_link = await m.chat.export_invite_link()
|
|
|
|
if "+" in invite_link:
|
|
|
|
link_hash = (invite_link.replace("+", "")).split("t.me/")[1]
|
|
|
|
await user.join_chat(f"https://t.me/joinchat/{link_hash}")
|
|
|
|
await m.chat.promote_member(
|
|
|
|
(await user.get_me()).id,
|
|
|
|
can_manage_voice_chats=True
|
2021-10-11 03:16:54 +00:00
|
|
|
)
|
2021-11-25 14:19:17 +00:00
|
|
|
return await user.send_message(chat_id, "✅ userbot entered chat")
|
2021-10-11 03:16:54 +00:00
|
|
|
except UserAlreadyParticipant:
|
2021-11-25 14:19:17 +00:00
|
|
|
admin = await m.chat.get_member((await user.get_me()).id)
|
|
|
|
if not admin.can_manage_voice_chats:
|
|
|
|
await m.chat.promote_member(
|
|
|
|
(await user.get_me()).id,
|
|
|
|
can_manage_voice_chats=True
|
|
|
|
)
|
|
|
|
return await user.send_message(chat_id, "✅ userbot already in chat")
|
|
|
|
return await user.send_message(chat_id, "✅ userbot already in chat")
|
2021-10-11 03:16:54 +00:00
|
|
|
|
|
|
|
|
2021-10-25 09:10:11 +00:00
|
|
|
@Client.on_message(command(["userbotleave",
|
2021-11-25 14:19:17 +00:00
|
|
|
f"leave@{BOT_USERNAME}"]) & filters.group & ~filters.edited
|
|
|
|
)
|
2021-10-11 03:16:54 +00:00
|
|
|
@authorized_users_only
|
2021-11-25 14:19:17 +00:00
|
|
|
async def leave_chat(_, m: Message):
|
|
|
|
chat_id = m.chat.id
|
2021-10-11 03:16:54 +00:00
|
|
|
try:
|
2021-11-25 14:19:17 +00:00
|
|
|
await user.leave_chat(chat_id)
|
|
|
|
return await _.send_message(
|
|
|
|
chat_id,
|
|
|
|
"✅ userbot leaved chat",
|
|
|
|
)
|
|
|
|
except UserNotParticipant:
|
|
|
|
return await _.send_message(
|
|
|
|
chat_id,
|
|
|
|
"❌ userbot already leave chat",
|
2021-10-11 03:16:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@Client.on_message(command(["leaveall", f"leaveall@{BOT_USERNAME}"]))
|
2021-10-25 09:10:11 +00:00
|
|
|
@sudo_users_only
|
|
|
|
async def leave_all(client, message):
|
2021-10-11 03:16:54 +00:00
|
|
|
if message.from_user.id not in SUDO_USERS:
|
|
|
|
return
|
|
|
|
|
|
|
|
left = 0
|
|
|
|
failed = 0
|
|
|
|
lol = await message.reply("🔄 **userbot** leaving all chats !")
|
2021-12-11 06:38:08 +00:00
|
|
|
async for dialog in user.iter_dialogs():
|
2021-10-11 03:16:54 +00:00
|
|
|
try:
|
2021-12-11 06:38:08 +00:00
|
|
|
await user.leave_chat(dialog.chat.id)
|
2021-10-11 03:16:54 +00:00
|
|
|
left += 1
|
|
|
|
await lol.edit(
|
|
|
|
f"Userbot leaving all group...\n\nLeft: {left} chats.\nFailed: {failed} chats."
|
|
|
|
)
|
2021-10-25 09:10:11 +00:00
|
|
|
except BaseException:
|
2021-10-11 03:16:54 +00:00
|
|
|
failed += 1
|
|
|
|
await lol.edit(
|
|
|
|
f"Userbot leaving...\n\nLeft: {left} chats.\nFailed: {failed} chats."
|
|
|
|
)
|
|
|
|
await asyncio.sleep(0.7)
|
|
|
|
await client.send_message(
|
2021-10-25 09:10:11 +00:00
|
|
|
message.chat.id, f"✅ Left from: {left} chats.\n❌ Failed in: {failed} chats."
|
2021-10-11 03:16:54 +00:00
|
|
|
)
|
2021-11-26 06:44:44 +00:00
|
|
|
|
|
|
|
|
2021-11-26 06:55:23 +00:00
|
|
|
@Client.on_message(filters.left_chat_member)
|
2021-11-26 06:44:44 +00:00
|
|
|
async def ubot_leave(c: Client, m: Message):
|
|
|
|
ass_id = (await user.get_me()).id
|
|
|
|
bot_id = (await c.get_me()).id
|
|
|
|
chat_id = m.chat.id
|
|
|
|
left_member = m.left_chat_member
|
|
|
|
if left_member.id == bot_id:
|
|
|
|
await user.leave_chat(chat_id)
|
|
|
|
elif left_member.id == ass_id:
|
|
|
|
await c.leave_chat(chat_id)
|