Skip to content

Commit

Permalink
pyrofork: Fix star_gift parser
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirarism authored Jan 4, 2025
1 parent 9efa6dc commit 51a0520
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 2 additions & 3 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def get_title_list(s: str) -> list:
GiftCode
GiftedPremium
Gift
UserGift
StarGift
InputStarsTransaction
Invoice
LabeledPrice
Expand All @@ -600,7 +600,6 @@ def get_title_list(s: str) -> list:
StarsStatus
StarsTransaction
SuccessfulPayment
UserStarGift
""",
pyromod="""
Pyromod
Expand Down Expand Up @@ -928,4 +927,4 @@ def start():
DESTINATION = "../../docs/source/telegram"
PYROGRAM_API_DEST = "../../docs/source/api"

start()
start()
4 changes: 2 additions & 2 deletions pyrogram/types/payments/star_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ async def _parse_user_star_gift(
users: dict
) -> "StarGift":
caption, caption_entities = (
utils.parse_text_entities(
utils.parse_text_with_entities(
client, getattr(user_star_gift, "message", None), users
)
).values()
Expand Down Expand Up @@ -320,7 +320,7 @@ async def _parse_action(
action = message.action # type: raw.types.MessageActionStarGift

caption, caption_entities = (
utils.parse_text_entities(
utils.parse_text_with_entities(
client, getattr(action, "message", None), users
)
).values()
Expand Down
20 changes: 18 additions & 2 deletions pyrogram/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
from types import SimpleNamespace

import pyrogram
from pyrogram import raw, enums
from pyrogram import types
from pyrogram import raw, enums, types
from pyrogram.types.messages_and_media.message import Str
from pyrogram.file_id import FileId, FileType, PHOTO_TYPES, DOCUMENT_TYPES


Expand Down Expand Up @@ -477,6 +477,22 @@ async def run_sync(func: Callable[..., TypeVar("Result")], *args: Any, **kwargs:
loop = asyncio.get_event_loop()
return await loop.run_in_executor(None, functools.partial(func, *args, **kwargs))

def parse_text_with_entities(client, message: "raw.types.TextWithEntities", users):
entities = types.List(
filter(
lambda x: x is not None,
[
types.MessageEntity._parse(client, entity, users)
for entity in getattr(message, "entities", [])
]
)
)

return {
"text": Str(getattr(message, "text", "")).init(entities) or None,
"entities": entities or None
}

async def get_reply_to(
client: "pyrogram.Client",
chat_id: Union[int,str] = None,
Expand Down

0 comments on commit 51a0520

Please sign in to comment.