From 0e413e2ca33801b0c6fbbff5223cc72f06172e63 Mon Sep 17 00:00:00 2001
From: levina <82658782+levina-lab@users.noreply.github.com>
Date: Fri, 10 Sep 2021 21:03:50 +0700
Subject: [PATCH] added new admin command
- added userbot join command
- added userbot leave command
- added userbot leave from all group for sudo member
---
bot/userbotjoin.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
create mode 100644 bot/userbotjoin.py
diff --git a/bot/userbotjoin.py b/bot/userbotjoin.py
new file mode 100644
index 0000000..d006774
--- /dev/null
+++ b/bot/userbotjoin.py
@@ -0,0 +1,78 @@
+# Copyright (C) 2021 Veez Music Project
+
+import asyncio
+from pyrogram import Client, filters
+from pyrogram.errors import UserAlreadyParticipant
+from helpers.filters import command
+from helpers.decorators import authorized_users_only, errors
+from bot.videoplayer import app as USER
+from config import BOT_USERNAME, SUDO_USERS
+
+
+@Client.on_message(command(["vjoin", f"vjoin@{BOT_USERNAME}"]) & ~filters.private & ~filters.bot)
+@authorized_users_only
+@errors
+async def entergroup(client, message):
+ chid = message.chat.id
+ try:
+ invitelink = await client.export_chat_invite_link(chid)
+ except:
+ await message.reply_text(
+ "๐ก promote me as admin first to do that !",
+ )
+ return
+
+ try:
+ user = await USER.get_me()
+ except:
+ user.first_name = "assistant"
+
+ try:
+ await USER.join_chat(invitelink)
+ await USER.send_message(message.chat.id, "๐ค: i'm joined here for streaming video on video chat")
+ except UserAlreadyParticipant:
+ await message.reply_text(
+ "โ
assistant already entered this group",
+ )
+ except Exception as e:
+ print(e)
+ await message.reply_text(
+ f"๐ด FLOODWAIT ERROR ๐ด\n\n user {user.first_name} couldn't join your group due to heavy join requests for userbot! make sure assistant is not banned in this group."
+ )
+ return
+ await message.reply_text(
+ "โ
assistant userbot joined your chat",
+ )
+
+
+@Client.on_message(command(["vleave", f"vleave@{BOT_USERNAME}"]) & filters.group & ~filters.edited)
+@authorized_users_only
+async def leavegroup(client, message):
+ try:
+ await USER.leave_chat(message.chat.id)
+ except:
+ await message.reply_text(
+ "โ assistant can't leave from group because floodwaits.\n\nยป you can manually kick me from this group"
+ )
+
+ return
+
+
+@Client.on_message(command(["leaveall", f"leaveall@{BOT_USERNAME}"]))
+async def outall(client, message):
+ if message.from_user.id not in SUDO_USERS:
+ return
+
+ left=0
+ failed=0
+ lol = await message.reply("๐ assistant leaving all chats")
+ async for dialog in USER.iter_dialogs():
+ try:
+ await USER.leave_chat(dialog.chat.id)
+ left += 1
+ await lol.edit(f"๐ assistant leaving...\nโณ Left: {left} chats.\n\nโ Failed: {failed} chats.")
+ except:
+ failed += 1
+ await lol.edit(f"๐ assistant leaving...\nโณ Left: {left} chats.\n\nโ Failed: {failed} chats.")
+ await asyncio.sleep(0.7)
+ await client.send_message(message.chat.id, f"โ
Left {left} chats.\n\nโ Failed {failed} chats.")