mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-22 18:07:21 +00:00
Add new method get_media_group (#550)
* Update __init__.py Support for GetMediaGroup * Create get_media_group.py Added new method - get_media_group * Update get_media_group.py Add pyro stuff * Update get_media_group.py * Update compiler.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
This commit is contained in:
parent
503327c864
commit
e1dac6c0e2
@ -168,6 +168,7 @@ def pyrogram_api():
|
|||||||
send_chat_action
|
send_chat_action
|
||||||
delete_messages
|
delete_messages
|
||||||
get_messages
|
get_messages
|
||||||
|
get_media_group
|
||||||
get_history
|
get_history
|
||||||
get_history_count
|
get_history_count
|
||||||
read_history
|
read_history
|
||||||
|
@ -30,6 +30,7 @@ from .edit_message_text import EditMessageText
|
|||||||
from .forward_messages import ForwardMessages
|
from .forward_messages import ForwardMessages
|
||||||
from .get_history import GetHistory
|
from .get_history import GetHistory
|
||||||
from .get_history_count import GetHistoryCount
|
from .get_history_count import GetHistoryCount
|
||||||
|
from .get_media_group import GetMediaGroup
|
||||||
from .get_messages import GetMessages
|
from .get_messages import GetMessages
|
||||||
from .iter_history import IterHistory
|
from .iter_history import IterHistory
|
||||||
from .read_history import ReadHistory
|
from .read_history import ReadHistory
|
||||||
@ -65,6 +66,7 @@ class Messages(
|
|||||||
EditMessageText,
|
EditMessageText,
|
||||||
ForwardMessages,
|
ForwardMessages,
|
||||||
GetHistory,
|
GetHistory,
|
||||||
|
GetMediaGroup,
|
||||||
GetMessages,
|
GetMessages,
|
||||||
SendAudio,
|
SendAudio,
|
||||||
SendChatAction,
|
SendChatAction,
|
||||||
|
59
pyrogram/methods/messages/get_media_group.py
Normal file
59
pyrogram/methods/messages/get_media_group.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-2020 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/>.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from typing import Union, List
|
||||||
|
|
||||||
|
from pyrogram.scaffold import Scaffold
|
||||||
|
from pyrogram.types import list
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class GetMediaGroup(Scaffold):
|
||||||
|
async def get_media_group(
|
||||||
|
self,
|
||||||
|
chat_id: Union[int, str],
|
||||||
|
message_id: int
|
||||||
|
) -> List["types.Message"]:
|
||||||
|
"""Get the media group a message belongs to.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
chat_id (``int`` | ``str``):
|
||||||
|
Unique identifier (int) or username (str) of the target chat.
|
||||||
|
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
||||||
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
|
|
||||||
|
message_id (``int``):
|
||||||
|
The id of one of the messages that belong to the media group.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of :obj:`~pyrogram.types.Message`: On success, a list of messages of the media group is returned.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: In case the passed message id doesn't belong to a media group.
|
||||||
|
"""
|
||||||
|
# There can be maximum 10 items in a media group.
|
||||||
|
messages = await self.get_messages(chat_id, [msg_id for msg_id in range(message_id - 9, message_id + 10)], replies=0)
|
||||||
|
|
||||||
|
media_group_id = messages[9].media_group_id
|
||||||
|
|
||||||
|
if media_group_id is None:
|
||||||
|
raise ValueError("The message doesn't belong to a media group")
|
||||||
|
|
||||||
|
return list.List(msg for msg in messages if msg.media_group_id == media_group_id)
|
Loading…
x
Reference in New Issue
Block a user