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))
def who_is(bot: BOT, message: Message): cmd = message.command if not message.reply_to_message and len(cmd) == 1: get_user = message.from_user.id elif message.reply_to_message and len(cmd) == 1: get_user = message.reply_to_message.from_user.id elif len(cmd) > 1: get_user = cmd[1] try: get_user = int(cmd[1]) except ValueError: pass try: user = BOT.get_users(get_user) except PeerIdInvalid: message.edit("I don't know that User.") sleep(2) message.delete() return desc = BOT.get_chat(get_user).description user_pic = BOT.get_user_profile_photos(user.id) common = GetCommon(user.id) if not user.photo: message.edit(WHOIS.format( full_name=FullName(user), user_id=user.id, first_name=user.first_name, last_name=user.last_name if user.last_name else "", username=user.username if user.username else "", last_online=LastOnline(user), common_groups=len(common.chats), bio=desc if desc else "`No bio set up.`"), disable_web_page_preview=True) elif user.photo: BOT.send_photo(message.chat.id, user_pic.photos[0].sizes[-1].file_id, WHOIS_PIC.format( full_name=FullName(user), user_id=user.id, first_name=user.first_name, last_name=user.last_name if user.last_name else "", username=user.username if user.username else "", last_online=LastOnline(user), profile_pics=user_pic.total_count, common_groups=len(common.chats), bio=desc if desc else "`No bio set up.`", profile_pic_update=ProfilePicUpdate(user_pic)), reply_to_message_id=ReplyCheck(message)) message.delete()
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))