Add raw attribute to Message class

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
KurimuzonAkuma 2024-02-23 11:55:23 +03:00 committed by wulan17
parent 1e7c906342
commit 26654b1945
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
2 changed files with 23 additions and 10 deletions

View file

@ -374,6 +374,9 @@ class Message(Object, Update):
reactions (List of :obj:`~pyrogram.types.Reaction`):
List of the reactions to this message.
raw (``pyrogram.raw.types.Message``, *optional*):
The raw message object, as received from the Telegram API.
link (``str``, *property*):
Generate a link to this message, only for groups and channels.
@ -486,7 +489,8 @@ class Message(Object, Update):
"types.ReplyKeyboardRemove",
"types.ForceReply"
] = None,
reactions: List["types.Reaction"] = None
reactions: List["types.Reaction"] = None,
raw: "raw.types.Message" = None
):
super().__init__(client)
@ -582,6 +586,7 @@ class Message(Object, Update):
self.video_chat_members_invited = video_chat_members_invited
self.web_app_data = web_app_data
self.reactions = reactions
self.raw = raw
async def wait_for_click(
self,
@ -631,7 +636,7 @@ class Message(Object, Update):
replies: int = 1
):
if isinstance(message, raw.types.MessageEmpty):
return Message(id=message.id, empty=True, client=client)
return Message(id=message.id, empty=True, client=client, raw=message)
from_id = utils.get_raw_peer_id(message.from_id)
peer_id = utils.get_raw_peer_id(message.peer_id)
@ -812,6 +817,7 @@ class Message(Object, Update):
web_app_data=web_app_data,
giveaway_launched=giveaway_launched,
giveaway_result=giveaway_result,
raw=message,
client=client
# TODO: supergroup_chat_created
)
@ -1080,6 +1086,7 @@ class Message(Object, Update):
outgoing=message.out,
reply_markup=reply_markup,
reactions=reactions,
raw=message,
client=client
)

View file

@ -61,16 +61,22 @@ class Object:
if isinstance(obj, datetime):
return str(obj)
attributes_to_hide = [
"raw"
]
filtered_attributes = {
attr: ("*" * 9 if attr == "phone_number" else getattr(obj, attr))
for attr in filter(
lambda x: not x.startswith("_") and x not in attributes_to_hide,
obj.__dict__,
)
if getattr(obj, attr) is not None
}
return {
"_": obj.__class__.__name__,
**{
attr: (
"*" * 9 if attr == "phone_number" else
getattr(obj, attr)
)
for attr in filter(lambda x: not x.startswith("_"), obj.__dict__)
if getattr(obj, attr) is not None
}
**filtered_attributes
}
def __str__(self) -> str: