Exemplo n.º 1
0
def get_chats(bot: BOT, message: Message):
    total = 0
    private = 0
    channel = 0
    group = 0
    supergroup = 0
    bots = 0
    private_bots = []

    start = int(time())
    message.edit("Getting Chatlist...")
    for dialog in BOT.iter_dialogs():
        total += 1
        if dialog.chat.type == 'private':
            private_bots.append(dialog.chat.id)  # Save for later parsing.
        elif dialog.chat.type == 'channel':
            channel += 1
        elif dialog.chat.type == 'group':
            group += 1
        elif dialog.chat.type == 'supergroup':
            supergroup += 1

    message.edit("Checking for bots...")
    chunk_size = 200
    for i in range(0, len(private_bots), chunk_size):
        for priv in BOT.get_users(private_bots[i:i + chunk_size]):
            if priv.is_bot:
                bots += 1
            else:
                private += 1

    message.edit(
        CHAT_INFO.format(total, private, bots, group, supergroup, channel,
                         int(time()) - start))
Exemplo n.º 2
0
def get_unreads(bot: BOT, message: Message):
    total_messages_unread = 0
    total_chats_unread = 0
    unread_msg_priv = 0
    unread_chat_priv = 0
    unread_msg_bot = 0
    unread_chat_bot = 0
    unread_msg_group = 0
    unread_chat_group = 0
    unread_msg_super = 0
    unread_chat_super = 0
    unread_msg_channel = 0
    unread_chat_channel = 0
    # A fuckton of variables (:
    chunk_size = 200
    could_be_bot = []

    message.edit("Getting dialogs...")
    all_dialogs = BOT.iter_dialogs()
    message.edit("Formatting...")
    for dialog in all_dialogs:
        if dialog.unread_messages_count:
            total_messages_unread += dialog.unread_messages_count
            if dialog.chat.type == 'private':
                could_be_bot.append(dialog)
                total_chats_unread += 1
            elif dialog.chat.type == 'group':
                unread_msg_group += dialog.unread_messages_count
                unread_chat_group += 1
                total_chats_unread += 1
            elif dialog.chat.type == 'supergroup':
                unread_msg_super += dialog.unread_messages_count
                unread_chat_super += 1
                total_chats_unread += 1
            elif dialog.chat.type == 'channel':
                unread_msg_channel += dialog.unread_messages_count
                unread_chat_channel += 1
                total_chats_unread += 1

    for i in range(0, len(could_be_bot), chunk_size):
        for priv in BOT.get_users(
            [x.chat.id for x in could_be_bot[i:i + chunk_size]]):
            if priv.is_bot:
                unread_msg_bot += could_be_bot[i].unread_messages_count
                unread_chat_bot += 1
            elif not priv.is_bot:
                unread_msg_priv += could_be_bot[i].unread_messages_count
                unread_chat_priv += 1

    message.edit(
        UNREAD_INFO.format(total_msg=total_messages_unread,
                           total_chats=total_chats_unread,
                           msg_private=str(unread_msg_priv).rjust(6, " "),
                           chat_private=unread_chat_priv,
                           msg_bots=str(unread_msg_bot).rjust(6, " "),
                           chat_bots=unread_chat_bot,
                           msg_groups=str(unread_msg_group).rjust(6, " "),
                           chat_groups=unread_chat_group,
                           msg_super=str(unread_msg_super).rjust(6, " "),
                           chat_super=unread_chat_super,
                           msg_channel=str(unread_msg_channel).rjust(6, " "),
                           chat_channel=unread_chat_channel))