mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add increment_message_views method
This commit is contained in:
parent
a5d8737426
commit
53ab40fef9
@ -178,6 +178,7 @@ def pyrogram_api():
|
|||||||
get_messages
|
get_messages
|
||||||
get_scheduled_messages
|
get_scheduled_messages
|
||||||
get_stickers
|
get_stickers
|
||||||
|
increment_message_views
|
||||||
get_media_group
|
get_media_group
|
||||||
get_chat_history
|
get_chat_history
|
||||||
get_chat_history_count
|
get_chat_history_count
|
||||||
@ -651,6 +652,8 @@ def pyrogram_api():
|
|||||||
Message.reply_web_page
|
Message.reply_web_page
|
||||||
Message.get_media_group
|
Message.get_media_group
|
||||||
Message.react
|
Message.react
|
||||||
|
Message.read
|
||||||
|
Message.view
|
||||||
""",
|
""",
|
||||||
chat="""
|
chat="""
|
||||||
Chat
|
Chat
|
||||||
|
@ -39,6 +39,7 @@ from .get_media_group import GetMediaGroup
|
|||||||
from .get_messages import GetMessages
|
from .get_messages import GetMessages
|
||||||
from .get_scheduled_messages import GetScheduledMessages
|
from .get_scheduled_messages import GetScheduledMessages
|
||||||
from .get_stickers import GetStickers
|
from .get_stickers import GetStickers
|
||||||
|
from .increment_message_views import IncrementMessageViews
|
||||||
from .read_chat_history import ReadChatHistory
|
from .read_chat_history import ReadChatHistory
|
||||||
from .read_mentions import ReadMentions
|
from .read_mentions import ReadMentions
|
||||||
from .read_reactions import ReadReactions
|
from .read_reactions import ReadReactions
|
||||||
@ -107,6 +108,7 @@ class Messages(
|
|||||||
GetChatHistory,
|
GetChatHistory,
|
||||||
SendCachedMedia,
|
SendCachedMedia,
|
||||||
GetChatHistoryCount,
|
GetChatHistoryCount,
|
||||||
|
IncrementMessageViews,
|
||||||
ReadChatHistory,
|
ReadChatHistory,
|
||||||
ReadMentions,
|
ReadMentions,
|
||||||
ReadReactions,
|
ReadReactions,
|
||||||
|
61
pyrogram/methods/messages/increment_message_views.py
Normal file
61
pyrogram/methods/messages/increment_message_views.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from typing import Union, List
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw
|
||||||
|
|
||||||
|
|
||||||
|
class IncrementMessageViews:
|
||||||
|
async def increment_message_views(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
chat_id: Union[int, str],
|
||||||
|
message_id: Union[int, List[int]],
|
||||||
|
) -> bool:
|
||||||
|
"""Increment message views.
|
||||||
|
|
||||||
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
chat_id (``int`` | ``str``):
|
||||||
|
Unique identifier (int) or username (str) of the target chat.
|
||||||
|
|
||||||
|
message_id (``int`` | List of ``int``):
|
||||||
|
Identifier or list of message identifiers of the target message.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: On success, True is returned.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Increment message views
|
||||||
|
await app.increment_message_views(chat_id, 1)
|
||||||
|
"""
|
||||||
|
ids = [message_id] if not isinstance(message_id, list) else message_id
|
||||||
|
|
||||||
|
r = await self.invoke(
|
||||||
|
raw.functions.messages.GetMessagesViews(
|
||||||
|
peer=await self.resolve_peer(chat_id),
|
||||||
|
id=ids,
|
||||||
|
increment=True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return bool(r)
|
@ -4664,3 +4664,59 @@ class Message(Object, Update):
|
|||||||
chat_id=self.chat.id,
|
chat_id=self.chat.id,
|
||||||
message_id=self.id
|
message_id=self.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def read(self) -> bool:
|
||||||
|
"""Bound method *read* of :obj:`~pyrogram.types.Message`.
|
||||||
|
|
||||||
|
Use as a shortcut for:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
await client.read_chat_history(
|
||||||
|
chat_id=message.chat.id,
|
||||||
|
max_id=message_id
|
||||||
|
)
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
await message.read()
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True on success.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
RPCError: In case of a Telegram RPC error.
|
||||||
|
"""
|
||||||
|
return await self._client.read_chat_history(
|
||||||
|
chat_id=self.chat.id,
|
||||||
|
max_id=self.id
|
||||||
|
)
|
||||||
|
|
||||||
|
async def view(self) -> bool:
|
||||||
|
"""Bound method *view* of :obj:`~pyrogram.types.Message`.
|
||||||
|
|
||||||
|
Use as a shortcut for:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
await client.increment_message_views(
|
||||||
|
chat_id=message.chat.id,
|
||||||
|
message_id=message_id
|
||||||
|
)
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
await message.view()
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True on success.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
RPCError: In case of a Telegram RPC error.
|
||||||
|
"""
|
||||||
|
return await self._client.increment_message_views(
|
||||||
|
chat_id=self.chat.id,
|
||||||
|
message_id=self.id
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user