From fe95837c7f1ee1fe56c9a21712154afe22b19e4f Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Fri, 21 Jan 2022 01:01:52 +0700 Subject: [PATCH] some fixes --- program/userbot_tools.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/program/userbot_tools.py b/program/userbot_tools.py index e8f565c..2091eb1 100644 --- a/program/userbot_tools.py +++ b/program/userbot_tools.py @@ -9,34 +9,25 @@ from driver.decorators import authorized_users_only, sudo_users_only @Client.on_message( - command(["userbotjoin", f"userbotjoin@{BOT_USERNAME}"]) & ~filters.private & ~filters.bot + command(["userbotjoin", f"userbotjoin@{BOT_USERNAME}"]) & ~filters.group & ~filters.edited ) @authorized_users_only async def join_chat(c: Client, m: Message): chat_id = m.chat.id try: - 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 - ) - return await user.send_message(chat_id, "✅ userbot entered chat") - except UserAlreadyParticipant: - 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 + invitelink = await c.export_chat_invite_link(chat_id) + if invitelink.startswith("https://t.me/+"): + invitelink = invitelink.replace( + "https://t.me/+", "https://t.me/joinchat/" ) - return await user.send_message(chat_id, "✅ userbot already in chat") + await user.join_chat(invitelink) + await user.send_message(chat_id, "✅ userbot entered chat") + except UserAlreadyParticipant: return await user.send_message(chat_id, "✅ userbot already in chat") -@Client.on_message(command(["userbotleave", - f"leave@{BOT_USERNAME}"]) & filters.group & ~filters.edited +@Client.on_message( + command(["userbotleave", f"userbotleave@{BOT_USERNAME}"]) & filters.group & ~filters.edited ) @authorized_users_only async def leave_chat(_, m: Message):