video-stream/program/userbotjoin.py

86 lines
2.7 KiB
Python
Raw Normal View History

2021-10-11 03:16:54 +00:00
import asyncio
from config import BOT_USERNAME, SUDO_USERS
2021-10-25 09:10:11 +00:00
from driver.decorators import authorized_users_only, sudo_users_only, errors
2021-10-28 05:30:52 +00:00
from driver.filters import command, other_filters
2021-10-26 12:48:43 +00:00
from driver.veez import user as USER
2021-10-25 09:10:11 +00:00
from pyrogram import Client, filters
2021-10-11 03:16:54 +00:00
from pyrogram.errors import UserAlreadyParticipant
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
@errors
2021-10-25 09:10:11 +00:00
async def join_group(client, message):
2021-10-11 03:16:54 +00:00
chid = message.chat.id
try:
invitelink = await client.export_chat_invite_link(chid)
2021-10-25 09:10:11 +00:00
except BaseException:
2021-10-11 03:16:54 +00:00
await message.reply_text(
2021-10-25 09:10:11 +00:00
"• **i'm not have permission:**\n\n» ❌ __Add Users__",
2021-10-11 03:16:54 +00:00
)
return
try:
user = await USER.get_me()
2021-10-25 09:10:11 +00:00
except BaseException:
2021-10-11 03:16:54 +00:00
user.first_name = "music assistant"
try:
await USER.join_chat(invitelink)
except UserAlreadyParticipant:
2021-10-25 09:10:11 +00:00
pass
2021-10-11 03:16:54 +00:00
except Exception as e:
print(e)
await message.reply_text(
2021-10-25 09:10:11 +00:00
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**",
2021-10-11 03:16:54 +00:00
)
return
await message.reply_text(
2021-10-25 09:10:11 +00:00
f"✅ **userbot succesfully entered chat**",
2021-10-11 03:16:54 +00:00
)
2021-10-25 09:10:11 +00:00
@Client.on_message(command(["userbotleave",
f"leave@{BOT_USERNAME}"]) & filters.group & ~filters.edited)
2021-10-11 03:16:54 +00:00
@authorized_users_only
2021-10-25 09:10:11 +00:00
async def leave_one(client, message):
2021-10-11 03:16:54 +00:00
try:
await USER.send_message(message.chat.id, "✅ userbot successfully left chat")
await USER.leave_chat(message.chat.id)
2021-10-25 09:10:11 +00:00
except BaseException:
2021-10-11 03:16:54 +00:00
await message.reply_text(
2021-10-25 09:10:11 +00:00
"❌ **userbot couldn't leave your group, may be floodwaits.**\n\n**» or manually kick userbot from your group**"
2021-10-11 03:16:54 +00:00
)
return
@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 !")
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."
)
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
)