Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @without_search_user_default_commands.message(CommandRule(command=["прочитать", "read"]))
- async def read_chat_messages(message: Message):
- methods = APIMethod(message)
- if len(message.text.split()) <= 2:
- type_ = PeerType.ALL
- elif message.text.split()[2] == "все":
- type_ = PeerType.ALL
- elif message.text.split()[2] == "беседы":
- type_ = PeerType.CHAT
- elif message.text.split()[2] == "лс":
- type_ = PeerType.USER
- elif message.text.split()[2] == "группы":
- type_ = PeerType.GROUP
- else:
- await methods.edit_messages(f"{Icons.WARNING} Укажите тип чата.")
- return
- unread_peers = await message.ctx_api.messages.get_conversations(filter="unread")
- if not unread_peers.items:
- await methods.edit_messages(f"{Icons.NO} Непрочитанные чаты не найдены.")
- return
- send_message = ""
- if type_ == PeerType.ALL:
- groups = 0
- users = 0
- chats = 0
- for item in unread_peers.items:
- await message.ctx_api.messages.mark_as_read(
- peer_id=item.conversation.peer.id
- )
- if item.conversation.peer.type.value == PeerType.GROUP.value:
- groups += 1
- elif item.conversation.peer.type.value == PeerType.CHAT.value:
- chats += 1
- elif item.conversation.peer.type.value == PeerType.USER.value:
- users += 1
- send_message += (f"{Icons.YES} Все сообщения успешно прочитаны\n"
- f"{Icons.RIGHT} Всего групп: {groups}\n"
- f"{Icons.CLEVER} Всего бесед: {chats}\n"
- f"{Icons.USERS} Всего лс: {users}.")
- else:
- count = 0
- _type = None
- types = {
- PeerType.GROUP.value: "группах",
- PeerType.CHAT.value: "беседах",
- PeerType.USER.value: "лс"
- }
- for item in unread_peers.items:
- if type_.value == item.conversation.peer.type.value:
- _type = item.conversation.peer.type.value
- await message.ctx_api.messages.mark_as_read(
- peer_id=item.conversation.peer.id
- )
- count += 1
- send_message += (f"{Icons.YES} Успешно прочитал сообщения в {types[_type]}\n"
- f"{Icons.CLEVER} Всего сообщений: {count}.")
- await methods.edit_messages(send_message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement