Add new Messages object and make get_history return it

This commit is contained in:
Dan 2018-05-11 18:00:16 +02:00
parent f7aca803b1
commit ef93fee7aa
6 changed files with 55 additions and 3 deletions

View File

@ -495,6 +495,7 @@ def start():
f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",") f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",")
f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",") f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",")
f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",")
f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",")
f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",") f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",")
f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",") f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",")

View File

@ -30,7 +30,7 @@ from .client.types import (
Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto, Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto,
InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity,
PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video,
VideoNote, Voice, CallbackQuery VideoNote, Voice, CallbackQuery, Messages
) )
from .client.types.reply_markup import ( from .client.types.reply_markup import (
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,

View File

@ -253,7 +253,7 @@ def parse_messages(
users: dict, users: dict,
chats: dict, chats: dict,
replies: int = 1 replies: int = 1
) -> pyrogram_types.Message: ) -> pyrogram_types.Message or list:
is_list = isinstance(messages, list) is_list = isinstance(messages, list)
messages = messages if is_list else [messages] messages = messages if is_list else [messages]
parsed_messages = [] parsed_messages = []

View File

@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import pyrogram
from pyrogram.api import functions from pyrogram.api import functions
from ...ext import BaseClient, utils from ...ext import BaseClient, utils
@ -51,6 +52,12 @@ class GetHistory(BaseClient):
offset_date (``int``, *optional*): offset_date (``int``, *optional*):
Pass a date in Unix time as offset to retrieve only older messages starting from that date. Pass a date in Unix time as offset to retrieve only older messages starting from that date.
Returns:
On success, a :obj:`Messages <pyrogram.Messages>` object is returned.
Raises:
:class:`Error <pyrogram.Error>`
""" """
r = self.send( r = self.send(
@ -98,4 +105,7 @@ class GetHistory(BaseClient):
if r.messages[i].reply_to_msg_id: if r.messages[i].reply_to_msg_id:
messages[i].reply_to_message = reply_to_messages[r.messages[i].reply_to_msg_id] messages[i].reply_to_message = reply_to_messages[r.messages[i].reply_to_msg_id]
return messages return pyrogram.Messages(
total_count=r.count,
messages=messages
)

View File

@ -43,3 +43,4 @@ from .venue import Venue
from .video import Video from .video import Video
from .video_note import VideoNote from .video_note import VideoNote
from .voice import Voice from .voice import Voice
from .messages import Messages

View File

@ -0,0 +1,40 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <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 pyrogram.api.core import Object
class Messages(Object):
"""This object represent a chat's messages.
Attributes:
ID: ``0xb0700026``
Args:
total_count (``int``):
Total number of messages the target chat has.
messages (List of :obj:`Message <pyrogram.Message>`):
Requested messages.
"""
ID = 0xb0700026
def __init__(self, total_count: int, messages: list):
self.total_count = total_count # int
self.messages = messages # Vector<Vector<PhotoSize>>