Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.. code-block:: python
scores = app.get_game_high_scores(user_id, chat_id, message_id)
print(scores)
"""
# TODO: inline_message_id
r = self.send(
functions.messages.GetGameHighScores(
peer=self.resolve_peer(chat_id),
id=message_id,
user_id=self.resolve_peer(user_id)
)
)
return pyrogram.List(pyrogram.GameHighScore._parse(self, score, r.users) for score in r.scores)
def parse_messages(client, messages: types.messages.Messages, replies: int = 1) -> List["pyrogram.Message"]:
users = {i.id: i for i in messages.users}
chats = {i.id: i for i in messages.chats}
if not messages.messages:
return pyrogram.List()
parsed_messages = [
pyrogram.Message._parse(client, message, users, chats, replies=0)
for message in messages.messages
]
if replies:
messages_with_replies = {i.id: getattr(i, "reply_to_msg_id", None) for i in messages.messages}
reply_message_ids = [i[0] for i in filter(lambda x: x[1] is not None, messages_with_replies.items())]
if reply_message_ids:
reply_messages = client.get_messages(
parsed_messages[0].chat.id,
reply_to_message_ids=reply_message_ids,
replies=replies - 1
)
forwarded_messages = []
users = {i.id: i for i in r.users}
chats = {i.id: i for i in r.chats}
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
forwarded_messages.append(
pyrogram.Message._parse(
self, i.message,
users, chats
)
)
return pyrogram.List(forwarded_messages) if is_iterable else forwarded_messages[0]
if message.reply_to_msg_id and replies:
try:
parsed_message.reply_to_message = client.get_messages(
parsed_message.chat.id,
reply_to_message_ids=message.id,
replies=0
)
except MessageIdsEmpty:
pass
return parsed_message
if isinstance(message, types.Message):
entities = [MessageEntity._parse(client, entity, users) for entity in message.entities]
entities = pyrogram.List(filter(lambda x: x is not None, entities))
forward_from = None
forward_sender_name = None
forward_from_chat = None
forward_from_message_id = None
forward_signature = None
forward_date = None
forward_header = message.fwd_from # type: types.MessageFwdHeader
if forward_header:
forward_date = forward_header.date
if forward_header.from_id:
forward_from = User._parse(client, users[forward_header.from_id])
elif forward_header.from_name:
is_mutual_contact=user.mutual_contact,
is_deleted=user.deleted,
is_bot=user.bot,
is_verified=user.verified,
is_restricted=user.restricted,
is_scam=user.scam,
is_support=user.support,
first_name=user.first_name,
last_name=user.last_name,
**User._parse_status(user.status, user.bot),
username=user.username,
language_code=user.lang_code,
dc_id=getattr(user.photo, "dc_id", None),
phone_number=user.phone,
photo=ChatPhoto._parse(client, user.photo, user.id, user.access_hash),
restrictions=pyrogram.List([Restriction._parse(r) for r in user.restriction_reason]) or None,
client=client
)
parsed_messages = []
for message in messages:
parsed_messages.append(
pyrogram.Message(
message_id=message,
chat=pyrogram.Chat(
id=get_channel_id(channel_id),
type="channel",
client=client
) if channel_id is not None else None,
client=client
)
)
return pyrogram.List(parsed_messages)
print(chats)
"""
r = self.send(
functions.contacts.GetLocated(
geo_point=types.InputGeoPoint(
lat=latitude,
long=longitude
)
)
)
if not r.updates:
return []
chats = pyrogram.List([pyrogram.Chat._parse_chat(self, chat) for chat in r.chats])
peers = r.updates[0].peers
for peer in peers:
chat_id = utils.get_channel_id(peer.peer.channel_id)
for chat in chats:
if chat.id == chat_id:
chat.distance = peer.distance
break
return chats
app.get_users("haskell")
# Get information about multiple users at once
app.get_users([user1, user2, user3])
"""
is_iterable = not isinstance(user_ids, (int, str))
user_ids = list(user_ids) if is_iterable else [user_ids]
user_ids = [self.resolve_peer(i) for i in user_ids]
r = self.send(
functions.users.GetUsers(
id=user_ids
)
)
users = pyrogram.List()
for i in r:
users.append(pyrogram.User._parse(self, i))
return users if is_iterable else users[0]
def _parse_user_chat(client, user: types.User) -> "Chat":
peer_id = user.id
return Chat(
id=peer_id,
type="bot" if user.bot else "private",
is_verified=getattr(user, "verified", None),
is_restricted=getattr(user, "restricted", None),
is_scam=getattr(user, "scam", None),
is_support=getattr(user, "support", None),
username=user.username,
first_name=user.first_name,
last_name=user.last_name,
photo=ChatPhoto._parse(client, user.photo, peer_id, user.access_hash),
restrictions=pyrogram.List([Restriction._parse(r) for r in user.restriction_reason]) or None,
client=client
)