async def chats(c: Alita, m: Message): exmsg = await m.reply_text("`Exporting Chatlist...`") await c.send_message( MESSAGE_DUMP, f"#CHATLIST\n\n**User:** {mention_markdown(m.from_user.first_name, m.from_user.id)}", ) all_chats = userdb.get_all_chats() or [] chatfile = "List of chats.\n\nChat name | Chat ID | Members count\n" P = 1 for chat in all_chats: try: chat_info = await c.get_chat(chat.chat_id) chat_members = chat_info.members_count try: invitelink = chat_info.invite_link except KeyError: invitelink = "No Link!" chatfile += "{}. {} | {} | {} | {}\n".format( P, chat.chat_name, chat.chat_id, chat_members, invitelink) P += 1 except errors.ChatAdminRequired: pass except errors.ChannelPrivate: userdb.rem_chat(chat.chat_id) except Exception as ef: await m.reply_text(f"**Error:**\n{ef}") with io.BytesIO(str.encode(chatfile)) as output: output.name = "chatlist.txt" await m.reply_document( document=output, caption="Here is the list of chats in my Database.") await exmsg.delete() return
async def get_muted_chats(c: Alita, m: Message, leave: bool = False): chat_id = m.chat.id chats = user_db.get_all_chats() muted_chats, progress = 0, 0 chat_list = [] progress_message = m for chat in chats: if ((100 * chats.index(chat)) / len(chats)) > progress: progress_bar = f"{progress}% completed in getting muted chats." if progress_message: try: bot.editMessageText(progress_bar, chat_id, progress_message.message_id) except Exception: pass else: progress_message = await m.edit_text(progress_bar) progress += 5 cid = chat.chat_id sleep(0.1) try: await c.send_chat_action(cid, "typing") except (BadRequest, Unauthorized): muted_chats += 1 chat_list.append(cid) except Exception: pass try: await progress_message.delete() except Exception: pass if not leave: return muted_chats else: for muted_chat in chat_list: sleep(0.1) try: await c.leave_chat(muted_chat) except Exception: pass user_db.rem_chat(muted_chat) return muted_chats
async def chats(c: Alita, m: Message): exmsg = await m.reply_text("`Exporting Chatlist...`") await c.send_message( MESSAGE_DUMP, f"#CHATLIST\n\n**User:** {(await mention_markdown(m.from_user.first_name, m.from_user.id))}", ) all_chats = userdb.get_all_chats() or [] chatfile = "List of chats.\n\nChat name | Chat ID | Members count\n" P = 1 for chat in all_chats: try: chat_info = await c.get_chat(chat.chat_id) chat_members = chat_info.members_count try: invitelink = chat_info.invite_link except KeyError: invitelink = "No Link!" chatfile += "{}. {} | {} | {} | {}\n".format( P, chat.chat_name, chat.chat_id, chat_members, invitelink, ) P += 1 except ChatAdminRequired: pass except ChannelPrivate: userdb.rem_chat(chat.chat_id) except PeerIdInvalid: LOGGER.warning(f"Group not loaded {chat.chat_id}") except RPCError as ef: LOGGER.error(ef) await m.reply_text(f"**Error:**\n{ef}") with BytesIO(str.encode(chatfile)) as f: f.name = "chatlist.txt" await m.reply_document( document=f, caption=tlang(m, "dev.chats_in_db"), ) await exmsg.delete() return
async def get_invalid_chats(c: Alita, m: Message, remove: bool = False): chats = user_db.get_all_chats() kicked_chats, progress = 0, 0 chat_list = [] progress_message = m for chat in chats: if ((100 * chats.index(chat)) / len(chats)) > progress: progress_bar = f"{progress}% completed in getting invalid chats." if progress_message: try: await m.edit_text(progress_bar) except RPCError: pass else: progress_message = await m.reply_text(progress_bar) progress += 5 cid = chat.chat_id await sleep(0.1) try: await c.get_chat(cid) except (BadRequest, Unauthorized): kicked_chats += 1 chat_list.append(cid) except RPCError: pass try: await progress_message.delete() except RPCError: pass if not remove: return kicked_chats for muted_chat in chat_list: try: await sleep(0.1) user_db.rem_chat(muted_chat) except RPCError: pass return kicked_chats