Advertisement
DimaDevelop

Untitled

Jan 7th, 2024
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.61 KB | Software | 0 0
  1. @without_search_user_default_commands.message(CommandRule(command=["прочитать", "read"]))
  2. async def read_chat_messages(message: Message):
  3.     methods = APIMethod(message)
  4.  
  5.     if len(message.text.split()) <= 2:
  6.         type_ = PeerType.ALL
  7.     elif message.text.split()[2] == "все":
  8.         type_ = PeerType.ALL
  9.     elif message.text.split()[2] == "беседы":
  10.         type_ = PeerType.CHAT
  11.     elif message.text.split()[2] == "лс":
  12.         type_ = PeerType.USER
  13.     elif message.text.split()[2] == "группы":
  14.         type_ = PeerType.GROUP
  15.     else:
  16.         await methods.edit_messages(f"{Icons.WARNING} Укажите тип чата.")
  17.         return
  18.  
  19.     unread_peers = await message.ctx_api.messages.get_conversations(filter="unread")
  20.  
  21.     if not unread_peers.items:
  22.         await methods.edit_messages(f"{Icons.NO} Непрочитанные чаты не найдены.")
  23.         return
  24.  
  25.     send_message = ""
  26.  
  27.     if type_ == PeerType.ALL:
  28.         groups = 0
  29.         users = 0
  30.         chats = 0
  31.  
  32.         for item in unread_peers.items:
  33.             await message.ctx_api.messages.mark_as_read(
  34.                 peer_id=item.conversation.peer.id
  35.             )
  36.             if item.conversation.peer.type.value == PeerType.GROUP.value:
  37.                 groups += 1
  38.             elif item.conversation.peer.type.value == PeerType.CHAT.value:
  39.                 chats += 1
  40.             elif item.conversation.peer.type.value == PeerType.USER.value:
  41.                 users += 1
  42.  
  43.         send_message += (f"{Icons.YES} Все сообщения успешно прочитаны\n"
  44.                          f"{Icons.RIGHT} Всего групп: {groups}\n"
  45.                          f"{Icons.CLEVER} Всего бесед: {chats}\n"
  46.                          f"{Icons.USERS} Всего лс: {users}.")
  47.     else:
  48.         count = 0
  49.         _type = None
  50.  
  51.         types = {
  52.             PeerType.GROUP.value: "группах",
  53.             PeerType.CHAT.value: "беседах",
  54.             PeerType.USER.value: "лс"
  55.         }
  56.  
  57.         for item in unread_peers.items:
  58.             if type_.value == item.conversation.peer.type.value:
  59.                 _type = item.conversation.peer.type.value
  60.                 await message.ctx_api.messages.mark_as_read(
  61.                     peer_id=item.conversation.peer.id
  62.                 )
  63.                 count += 1
  64.  
  65.         send_message += (f"{Icons.YES} Успешно прочитал сообщения в {types[_type]}\n"
  66.                          f"{Icons.CLEVER} Всего сообщений: {count}.")
  67.  
  68.     await methods.edit_messages(send_message)
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement