From 662d49d885475a95b671b34fca264e1f44864a57 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 9 May 2018 13:06:32 +0200 Subject: [PATCH] Add get_history.py --- .../client/methods/messages/get_history.py | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 pyrogram/client/methods/messages/get_history.py diff --git a/pyrogram/client/methods/messages/get_history.py b/pyrogram/client/methods/messages/get_history.py new file mode 100644 index 00000000..7c03f854 --- /dev/null +++ b/pyrogram/client/methods/messages/get_history.py @@ -0,0 +1,72 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# 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 . + +from pyrogram.api import functions, types +from ...ext import BaseClient, utils + + +class GetHistory(BaseClient): + def get_history(self, + chat_id: int or str, + offset: int, + limit: int, + offset_id: int = 0, + offset_date: int = 0, + max_id: int = 0, + min_id: int = 0): + # TODO: Documentation + + r = self.send( + functions.messages.GetHistory( + peer=self.resolve_peer(chat_id), + offset_id=offset_id, + offset_date=offset_date, + add_offset=offset, + limit=limit, + max_id=max_id, + min_id=min_id, + hash=0 + ) + ) + + users = {i.id: i for i in r.users} + chats = {i.id: i for i in r.chats} + + messages = [] + + for i in r.messages: + if isinstance(i, types.Message): + messages.append( + utils.parse_message( + self, i, users, chats + ) + ) + elif isinstance(i, types.MessageService): + messages.append( + utils.parse_message_service( + self, i, users, chats + ) + ) + else: + messages.append( + utils.parse_message_empty( + self, i + ) + ) + + return messages