async def admin_chats(user_id: int) -> dict:
    list_ = []
    try:
        user_ = await userge.get_users(user_id)
    except:
        raise
        return
    async for dialog in userge.iter_dialogs():
        if dialog.chat.type in ["group", "supergroup", "channel"]:
            try:
                check = await admin_or_creator(dialog.chat.id, user_.id)
                is_admin = check['is_admin']
                is_creator = check['is_creator']
            except UserNotParticipant:
                is_admin = False
                is_creator = False
            chat_ = dialog.chat
            if is_admin or is_creator:
                list_.append({
                    "chat_name": chat_.title,
                    "chat_id": chat_.id,
                    "chat_username": chat_.username,
                    "admin": is_admin,
                    "creator": is_creator,
                })
    return list_
Esempio n. 2
0
async def creator(m: Message):

    await m.edit("__This may take a while, please wait ...__")

    if "-c" in m.flags:
        status = "creator"
    elif "-a" in m.flags:
        status = "administrator"
    else:
        await m.err("Invalid flag!")
        return

    c_str = ""
    g_str = ""
    c_n = 0
    g_n = 0

    async for d in userge.iter_dialogs():
        if d.chat.type in ["group", "supergroup", "channel"]:
            try:
                if (await
                        userge.get_chat_member(d.chat.id,
                                               m.client.id)).status == status:
                    if d.chat.username:
                        c = (
                            f"[{d.chat.title}](https://t.me/{d.chat.username})\n"
                            + "  " + "**Privacy**: __public__" + " | " +
                            f"**Chat ID**: `{d.chat.id}`")
                    else:
                        i_l = (await userge.get_chat(d.chat.id)).invite_link
                        c = (f"[{d.chat.title}]({i_l})\n" + "  " +
                             "**Privacy**: __private__" + " | " +
                             f"**Chat ID**: `{d.chat.id}`")
                    if d.chat.type == "channel":
                        c_n += 1
                        c_str += f"{c_n}. {c}\n"
                    else:
                        g_n += 1
                        g_str += f"{g_n}. {c}\n"
            except (UserNotParticipant, ChannelPrivate):
                continue

    await m.edit(f"<u>**GROUPS**</u> __({status})__:\n" +
                 ("(__None__)" if not g_str else g_str) +
                 f"\n<u>**CHANNELS**</u> __({status})__:\n" +
                 ("(__None__)" if not c_str else c_str))
Esempio n. 3
0
async def get_stats_(message: Message):
    """get info about your TG account"""
    start = time.time()
    await message.edit("💁‍♂️ `Collecting your Telegram Stats ...`\n"
                       "<b>Please wait it will take some time</b>")
    owner = await userge.get_me()
    u_mention = mention_html(owner.id, owner.first_name)
    unread_mentions = 0
    unread_msg = 0
    private_chats = 0
    bots = 0
    users_ = 0
    groups = 0
    groups_admin = 0
    groups_creator = 0
    channels = 0
    channels_admin = 0
    channels_creator = 0
    try:
        async for dialog in userge.iter_dialogs():
            unread_mentions += dialog.unread_mentions_count
            unread_msg += dialog.unread_messages_count
            chat_type = dialog.chat.type
            if chat_type in ["bot", "private"]:
                private_chats += 1
                if chat_type == "bot":
                    bots += 1
                else:
                    users_ += 1
            else:
                try:
                    is_admin = await admin_check(dialog.chat.id, owner.id)
                    is_creator = dialog.chat.is_creator
                except UserNotParticipant:
                    is_admin = False
                    is_creator = False
                if chat_type in ["group", "supergroup"]:
                    groups += 1
                    if is_admin:
                        groups_admin += 1
                    if is_creator:
                        groups_creator += 1
                else:  # Channel
                    channels += 1
                    if is_admin:
                        channels_admin += 1
                    if is_creator:
                        channels_creator += 1
    except FloodWait as e:
        await asyncio.sleep(e.x + 5)

    results = f"""
📊 <b><u>Telegram Stats</u></b>
👤 User:  <b>{u_mention}</b>

<b>Private Chats:</b> <code>{private_chats}</code><code>
    • Users: {users_}
    • Bots: {bots}</code>
<b>Groups:</b> <code>{groups}</code>
<b>Channels:</b> <code>{channels}</code>
<b>Admin in Groups:</b> <code>{groups_admin}</code><code>
    ★ Creator: {groups_creator}
    • Admin Rights: {groups_admin - groups_creator}</code>
<b>Admin in Channels:</b> <code>{channels_admin}</code><code>
    ★ Creator: {channels_creator}
    • Admin Rights: {channels_admin - channels_creator}</code>
<b>Unread Messages:</b> <code>{unread_msg}</code>
<b>Unread Mentions:</b> <code>{unread_mentions}</code>
"""
    end = time.time()
    results += f"\n⏳ <i>Process took: {time_formatter(end - start)}.</i>"
    await message.edit(results)
Esempio n. 4
0
async def gban_new(message: Message):
    """gban in all groups and channels"""
    input_ = message.input_str
    reply_ = message.reply_to_message
    if not input_ and not reply_:
        return await message.edit("`Input not found.`", del_in=5)
    input_ = (input_).split(" ", 1)
    if len(input_) == 2:
        user_ = input_[0]
        try:
            user_ = await userge.get_users(user_)
            user_id = user_.id
            user_n = full_name(user_)
            reason_ = input_[1]
        except BaseException:
            if not reply_:
                return await message.edit("`Provided user is not valid.`", del_in=5)
            user_id = reply_.from_user.id
            user_n = " ".join(
                [reply_.from_user.first_name, reply_.from_user.last_name or ""]
            )
            reason_ = message.input_str
    elif len(input_) == 1:
        user_ = input_[0]
        try:
            user_ = await userge.get_users(user_)
            user_id = user_.id
            user_n = full_name(user_)
            reason_ = "Not specified"
        except BaseException:
            if not reply_:
                return await message.edit("`Provided user is not valid.`", del_in=5)
            user_id = reply_.from_user.id
            user_n = " ".join(
                [reply_.from_user.first_name, reply_.from_user.last_name or ""]
            )
            reason_ = message.input_str
    await message.edit(f"GBanning user {mention_html(user_id, user_n)}...")
    me_ = await userge.get_me()
    found = await GBAN_USER_BASE.find_one({"user_id": user_id})
    if found:
        gbanned_chats = found["chat_ids"]
    else:
        gbanned_chats = []
    failed = ""
    async for dia_ in userge.iter_dialogs():
        try:
            chat_ = dia_.chat
            try:
                me_status = (await userge.get_chat_member(chat_.id, me_.id)).status
                user_status = (await userge.get_chat_member(chat_.id, user_id)).status
            except BaseException:
                continue
            status_ = ["administrator", "creator"]
            if me_status not in status_ or user_status in status_:
                continue
            try:
                await userge.kick_chat_member(chat_.id, user_id)
                gbanned_chats.append[chat_.id]
            except BaseException:
                failed += f"• {chat_.title} - {chat_.type}\n"
        except BaseException:
            failed += f"• {chat_.title} - {chat_.type}\n"
    if found:
        await GBAN_USER_BASE.update_one(
            {"user_id": user_id}, {"$set": {"chat_ids": gbanned_chats}}, upsert=True
        )
    else:
        await GBAN_USER_BASE.insert_one(
            {
                "firstname": user_n,
                "user_id": user_id,
                "reason": reason_,
                "chat_ids": gbanned_chats,
            }
        )
    out_ = (
        "#GBANNED_USER\n\n"
        f"<b>User:</b> {mention_html(user_id, user_n)}\n"
        f"<b>User_ID:</b> `{user_id}` <b>Reason:</b> {reason_}\n"
        f"<b>GBanned in:</b> {len(gbanned_chats)}\n"
    )
    if failed:
        out_ += f"<b>Failed in:</b>\n{failed}"
    await message.edit(out_)
    await CHANNEL.log(
        r"\\**#Antispam_Log**//"
        f"\n**User:** {mention_html(user_id, firstname)}\n"
        f"**User ID:** `{user_id}`\n"
        f"**Chat:** {chat.title}\n"
        f"**Chat ID:** `{chat.id}`\n"
        f"**Reason:** `{reason}`\n\n$GBAN #id{user_id}"
    )