2022-01-31 12:41:47 +00:00
|
|
|
import asyncio
|
2022-02-11 15:40:15 +00:00
|
|
|
|
2022-01-31 12:41:47 +00:00
|
|
|
from config import BOT_USERNAME, SUDO_USERS
|
2022-02-12 04:40:23 +00:00
|
|
|
|
2022-02-15 04:44:58 +00:00
|
|
|
from driver.core import user, me_bot
|
2022-01-31 12:41:47 +00:00
|
|
|
from driver.filters import command, other_filters
|
2022-02-06 05:51:38 +00:00
|
|
|
from driver.database.dbchat import remove_served_chat
|
2022-02-10 22:39:38 +00:00
|
|
|
from driver.database.dbqueue import remove_active_chat
|
2022-02-14 05:38:16 +00:00
|
|
|
from driver.decorators import authorized_users_only, bot_creator, check_blacklist
|
2022-01-31 12:41:47 +00:00
|
|
|
|
2022-02-12 04:40:23 +00:00
|
|
|
from pyrogram.types import Message
|
|
|
|
from pyrogram import Client, filters
|
|
|
|
from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant
|
|
|
|
|
|
|
|
|
2022-01-31 12:41:47 +00:00
|
|
|
|
|
|
|
@Client.on_message(
|
|
|
|
command(["userbotjoin", f"userbotjoin@{BOT_USERNAME}"]) & other_filters
|
|
|
|
)
|
2022-02-14 05:38:16 +00:00
|
|
|
@check_blacklist()
|
2022-01-31 12:41:47 +00:00
|
|
|
@authorized_users_only
|
|
|
|
async def join_chat(c: Client, m: Message):
|
|
|
|
chat_id = m.chat.id
|
|
|
|
try:
|
2022-02-12 04:05:44 +00:00
|
|
|
invitelink = (await c.get_chat(chat_id)).invite_link
|
|
|
|
if not invitelink:
|
|
|
|
await c.export_chat_invite_link(chat_id)
|
|
|
|
invitelink = (await c.get_chat(chat_id)).invite_link
|
2022-01-31 12:41:47 +00:00
|
|
|
if invitelink.startswith("https://t.me/+"):
|
|
|
|
invitelink = invitelink.replace(
|
|
|
|
"https://t.me/+", "https://t.me/joinchat/"
|
|
|
|
)
|
2022-02-12 04:05:44 +00:00
|
|
|
await user.join_chat(invitelink)
|
|
|
|
await remove_active_chat(chat_id)
|
|
|
|
return await user.send_message(chat_id, "✅ userbot joined chat")
|
2022-01-31 12:41:47 +00:00
|
|
|
except UserAlreadyParticipant:
|
|
|
|
return await user.send_message(chat_id, "✅ userbot already in chat")
|
|
|
|
|
|
|
|
|
|
|
|
@Client.on_message(
|
|
|
|
command(["userbotleave", f"userbotleave@{BOT_USERNAME}"]) & other_filters
|
|
|
|
)
|
2022-02-14 05:38:16 +00:00
|
|
|
@check_blacklist()
|
2022-01-31 12:41:47 +00:00
|
|
|
@authorized_users_only
|
|
|
|
async def leave_chat(_, m: Message):
|
|
|
|
chat_id = m.chat.id
|
|
|
|
try:
|
|
|
|
await user.leave_chat(chat_id)
|
2022-02-10 22:39:38 +00:00
|
|
|
await remove_active_chat(chat_id)
|
2022-01-31 12:41:47 +00:00
|
|
|
return await _.send_message(
|
|
|
|
chat_id,
|
|
|
|
"✅ userbot leaved chat",
|
|
|
|
)
|
|
|
|
except UserNotParticipant:
|
|
|
|
return await _.send_message(
|
|
|
|
chat_id,
|
|
|
|
"❌ userbot already leave chat",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-02-21 04:01:48 +00:00
|
|
|
@Client.on_message(command(["leaveall", f"leaveall@{BOT_USERNAME}"]) & ~filters.edited)
|
2022-02-10 04:16:41 +00:00
|
|
|
@bot_creator
|
2022-01-31 12:41:47 +00:00
|
|
|
async def leave_all(client, message):
|
|
|
|
if message.from_user.id not in SUDO_USERS:
|
|
|
|
return
|
|
|
|
|
|
|
|
left = 0
|
|
|
|
failed = 0
|
|
|
|
|
|
|
|
msg = await message.reply("🔄 Userbot leaving all Group !")
|
|
|
|
async for dialog in user.iter_dialogs():
|
|
|
|
try:
|
|
|
|
await user.leave_chat(dialog.chat.id)
|
2022-02-10 22:39:38 +00:00
|
|
|
await remove_active_chat(dialog.chat.id)
|
2022-01-31 12:41:47 +00:00
|
|
|
left += 1
|
|
|
|
await msg.edit(
|
|
|
|
f"Userbot leaving all Group...\n\nLeft: {left} chats.\nFailed: {failed} chats."
|
|
|
|
)
|
|
|
|
except BaseException:
|
|
|
|
failed += 1
|
|
|
|
await msg.edit(
|
|
|
|
f"Userbot leaving...\n\nLeft: {left} chats.\nFailed: {failed} chats."
|
|
|
|
)
|
|
|
|
await asyncio.sleep(0.7)
|
|
|
|
await msg.delete()
|
|
|
|
await client.send_message(
|
|
|
|
message.chat.id, f"✅ Left from: {left} chats.\n❌ Failed in: {failed} chats."
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-02-21 04:01:48 +00:00
|
|
|
@Client.on_message(command(["startvc", f"startvc@{BOT_USERNAME}"]) & other_filters)
|
|
|
|
@check_blacklist()
|
|
|
|
@authorized_users_only
|
|
|
|
async def start_group_call(c: Client, m: Message):
|
|
|
|
chat_id = m.chat.id
|
|
|
|
try:
|
|
|
|
peer = await user.resolve_peer(chat_id)
|
|
|
|
await user.send(
|
|
|
|
CreateGroupCall(
|
|
|
|
peer=InputPeerChannel(
|
|
|
|
channel_id=peer.channel_id,
|
|
|
|
access_hash=peer.access_hash,
|
|
|
|
),
|
|
|
|
random_id=user.rnd_id() // 9000000000,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
msg = await c.send_message(
|
|
|
|
chat_id, "✅ Group call started !"
|
|
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
await msg.edit(f"🚫 error: `{e}`")
|
|
|
|
|
|
|
|
|
2022-01-31 12:41:47 +00:00
|
|
|
@Client.on_message(filters.left_chat_member)
|
2022-02-06 05:51:38 +00:00
|
|
|
async def bot_kicked(c: Client, m: Message):
|
2022-02-15 04:44:58 +00:00
|
|
|
bot_id = me_bot.id
|
2022-01-31 12:41:47 +00:00
|
|
|
chat_id = m.chat.id
|
|
|
|
left_member = m.left_chat_member
|
|
|
|
if left_member.id == bot_id:
|
|
|
|
await user.leave_chat(chat_id)
|
2022-02-10 04:16:41 +00:00
|
|
|
await remove_served_chat(chat_id)
|
2022-02-10 22:39:38 +00:00
|
|
|
await remove_active_chat(chat_id)
|