Changes for L119
This commit is contained in:
parent
5ee932b326
commit
4632879ee4
@ -539,7 +539,7 @@ class Client(Methods, Scaffold):
|
|||||||
getattr(
|
getattr(
|
||||||
getattr(
|
getattr(
|
||||||
update, "message", None
|
update, "message", None
|
||||||
), "to_id", None
|
), "peer_id", None
|
||||||
), "channel_id", None
|
), "channel_id", None
|
||||||
) or getattr(update, "channel_id", None)
|
) or getattr(update, "channel_id", None)
|
||||||
|
|
||||||
|
@ -89,15 +89,15 @@ class GetDialogs(Scaffold):
|
|||||||
messages = {}
|
messages = {}
|
||||||
|
|
||||||
for message in r.messages:
|
for message in r.messages:
|
||||||
to_id = message.to_id
|
peer_id = message.peer_id
|
||||||
|
|
||||||
if isinstance(to_id, raw.types.PeerUser):
|
if isinstance(peer_id, raw.types.PeerUser):
|
||||||
if message.out:
|
if message.out:
|
||||||
chat_id = to_id.user_id
|
chat_id = peer_id.user_id
|
||||||
else:
|
else:
|
||||||
chat_id = message.from_id
|
chat_id = utils.get_raw_peer_id(message.from_id)
|
||||||
else:
|
else:
|
||||||
chat_id = utils.get_peer_id(to_id)
|
chat_id = utils.get_peer_id(peer_id)
|
||||||
|
|
||||||
messages[chat_id] = await types.Message._parse(self, message, users, chats)
|
messages[chat_id] = await types.Message._parse(self, message, users, chats)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram import raw
|
from pyrogram import raw, utils
|
||||||
from pyrogram import types
|
from pyrogram import types
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ class GameHighScore(Object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_action(client, service: raw.types.MessageService, users: dict):
|
def _parse_action(client, service: raw.types.MessageService, users: dict):
|
||||||
return GameHighScore(
|
return GameHighScore(
|
||||||
user=types.User._parse(client, users[service.from_id]),
|
user=types.User._parse(client, users[utils.get_raw_peer_id(service.from_id)]),
|
||||||
score=service.action.score,
|
score=service.action.score,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
@ -422,7 +422,7 @@ class Message(Object, Update):
|
|||||||
if isinstance(action, raw.types.MessageActionChatAddUser):
|
if isinstance(action, raw.types.MessageActionChatAddUser):
|
||||||
new_chat_members = [types.User._parse(client, users[i]) for i in action.users]
|
new_chat_members = [types.User._parse(client, users[i]) for i in action.users]
|
||||||
elif isinstance(action, raw.types.MessageActionChatJoinedByLink):
|
elif isinstance(action, raw.types.MessageActionChatJoinedByLink):
|
||||||
new_chat_members = [types.User._parse(client, users[message.from_id])]
|
new_chat_members = [types.User._parse(client, users[utils.get_raw_peer_id(message.from_id)])]
|
||||||
elif isinstance(action, raw.types.MessageActionChatDeleteUser):
|
elif isinstance(action, raw.types.MessageActionChatDeleteUser):
|
||||||
left_chat_member = types.User._parse(client, users[action.user_id])
|
left_chat_member = types.User._parse(client, users[action.user_id])
|
||||||
elif isinstance(action, raw.types.MessageActionChatEditTitle):
|
elif isinstance(action, raw.types.MessageActionChatEditTitle):
|
||||||
@ -444,7 +444,7 @@ class Message(Object, Update):
|
|||||||
message_id=message.id,
|
message_id=message.id,
|
||||||
date=message.date,
|
date=message.date,
|
||||||
chat=types.Chat._parse(client, message, users, chats),
|
chat=types.Chat._parse(client, message, users, chats),
|
||||||
from_user=types.User._parse(client, users.get(message.from_id, None)),
|
from_user=types.User._parse(client, users.get(utils.get_raw_peer_id(message.from_id), None)),
|
||||||
service=True,
|
service=True,
|
||||||
new_chat_members=new_chat_members,
|
new_chat_members=new_chat_members,
|
||||||
left_chat_member=left_chat_member,
|
left_chat_member=left_chat_member,
|
||||||
@ -472,7 +472,7 @@ class Message(Object, Update):
|
|||||||
if isinstance(action, raw.types.MessageActionGameScore):
|
if isinstance(action, raw.types.MessageActionGameScore):
|
||||||
parsed_message.game_high_score = types.GameHighScore._parse_action(client, message, users)
|
parsed_message.game_high_score = types.GameHighScore._parse_action(client, message, users)
|
||||||
|
|
||||||
if message.reply_to_msg_id and replies:
|
if message.reply_to and replies:
|
||||||
try:
|
try:
|
||||||
parsed_message.reply_to_message = await client.get_messages(
|
parsed_message.reply_to_message = await client.get_messages(
|
||||||
parsed_message.chat.id,
|
parsed_message.chat.id,
|
||||||
@ -501,13 +501,17 @@ class Message(Object, Update):
|
|||||||
forward_date = forward_header.date
|
forward_date = forward_header.date
|
||||||
|
|
||||||
if forward_header.from_id:
|
if forward_header.from_id:
|
||||||
forward_from = types.User._parse(client, users[forward_header.from_id])
|
raw_peer_id = utils.get_raw_peer_id(forward_header.from_id)
|
||||||
|
peer_id = utils.get_peer_id(forward_header.from_id)
|
||||||
|
|
||||||
|
if peer_id > 0:
|
||||||
|
forward_from = types.User._parse(client, users[raw_peer_id])
|
||||||
|
else:
|
||||||
|
forward_from_chat = types.Chat._parse_channel_chat(client, chats[raw_peer_id])
|
||||||
|
forward_from_message_id = forward_header.channel_post
|
||||||
|
forward_signature = forward_header.post_author
|
||||||
elif forward_header.from_name:
|
elif forward_header.from_name:
|
||||||
forward_sender_name = forward_header.from_name
|
forward_sender_name = forward_header.from_name
|
||||||
else:
|
|
||||||
forward_from_chat = types.Chat._parse_channel_chat(client, chats[forward_header.channel_id])
|
|
||||||
forward_from_message_id = forward_header.channel_post
|
|
||||||
forward_signature = forward_header.post_author
|
|
||||||
|
|
||||||
photo = None
|
photo = None
|
||||||
location = None
|
location = None
|
||||||
@ -608,7 +612,7 @@ class Message(Object, Update):
|
|||||||
message_id=message.id,
|
message_id=message.id,
|
||||||
date=message.date,
|
date=message.date,
|
||||||
chat=types.Chat._parse(client, message, users, chats),
|
chat=types.Chat._parse(client, message, users, chats),
|
||||||
from_user=types.User._parse(client, users.get(message.from_id, None)),
|
from_user=types.User._parse(client, users.get(utils.get_raw_peer_id(message.from_id), None)),
|
||||||
text=(
|
text=(
|
||||||
Str(message.message).init(entities) or None
|
Str(message.message).init(entities) or None
|
||||||
if media is None or web_page is not None
|
if media is None or web_page is not None
|
||||||
@ -664,7 +668,7 @@ class Message(Object, Update):
|
|||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
if message.reply_to_msg_id and replies:
|
if message.reply_to and replies:
|
||||||
try:
|
try:
|
||||||
parsed_message.reply_to_message = await client.get_messages(
|
parsed_message.reply_to_message = await client.get_messages(
|
||||||
parsed_message.chat.id,
|
parsed_message.chat.id,
|
||||||
|
@ -224,13 +224,20 @@ class Chat(Object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(client, message: raw.types.Message or raw.types.MessageService, users: dict, chats: dict) -> "Chat":
|
def _parse(client, message: raw.types.Message or raw.types.MessageService, users: dict, chats: dict) -> "Chat":
|
||||||
if isinstance(message.to_id, raw.types.PeerUser):
|
if isinstance(message.peer_id, raw.types.PeerUser):
|
||||||
return Chat._parse_user_chat(client, users[message.to_id.user_id if message.out else message.from_id])
|
return Chat._parse_user_chat(
|
||||||
|
client,
|
||||||
|
users[
|
||||||
|
message.peer_id.user_id
|
||||||
|
if message.out
|
||||||
|
else utils.get_raw_peer_id(message.from_id)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
if isinstance(message.to_id, raw.types.PeerChat):
|
if isinstance(message.peer_id, raw.types.PeerChat):
|
||||||
return Chat._parse_chat_chat(client, chats[message.to_id.chat_id])
|
return Chat._parse_chat_chat(client, chats[message.peer_id.chat_id])
|
||||||
|
|
||||||
return Chat._parse_channel_chat(client, chats[message.to_id.channel_id])
|
return Chat._parse_channel_chat(client, chats[message.peer_id.channel_id])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_dialog(client, peer, users: dict, chats: dict):
|
def _parse_dialog(client, peer, users: dict, chats: dict):
|
||||||
|
@ -211,11 +211,10 @@ class ChatMember(Object):
|
|||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(member, (raw.types.ChannelParticipantCreator, raw.types.ChatParticipantCreator)):
|
if isinstance(member, raw.types.ChatParticipantCreator):
|
||||||
return ChatMember(
|
return ChatMember(
|
||||||
user=user,
|
user=user,
|
||||||
status="creator",
|
status="creator",
|
||||||
title=getattr(member, "rank", None),
|
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -228,6 +227,25 @@ class ChatMember(Object):
|
|||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if isinstance(member, raw.types.ChannelParticipantCreator):
|
||||||
|
permissions = member.admin_rights
|
||||||
|
|
||||||
|
return ChatMember(
|
||||||
|
user=user,
|
||||||
|
status="creator",
|
||||||
|
title=member.rank,
|
||||||
|
invited_by=invited_by,
|
||||||
|
can_change_info=permissions.change_info,
|
||||||
|
can_post_messages=permissions.post_messages,
|
||||||
|
can_edit_messages=permissions.edit_messages,
|
||||||
|
can_delete_messages=permissions.delete_messages,
|
||||||
|
can_restrict_members=permissions.ban_users,
|
||||||
|
can_invite_users=permissions.invite_users,
|
||||||
|
can_pin_messages=permissions.pin_messages,
|
||||||
|
can_promote_members=permissions.add_admins,
|
||||||
|
client=client
|
||||||
|
)
|
||||||
|
|
||||||
if isinstance(member, raw.types.ChannelParticipantAdmin):
|
if isinstance(member, raw.types.ChannelParticipantAdmin):
|
||||||
permissions = member.admin_rights
|
permissions = member.admin_rights
|
||||||
|
|
||||||
|
@ -231,7 +231,22 @@ MIN_CHAT_ID = -2147483647
|
|||||||
MAX_USER_ID = 2147483647
|
MAX_USER_ID = 2147483647
|
||||||
|
|
||||||
|
|
||||||
|
def get_raw_peer_id(peer: raw.base.Peer) -> Union[int, None]:
|
||||||
|
"""Get the raw peer id from a Peer object"""
|
||||||
|
if isinstance(peer, raw.types.PeerUser):
|
||||||
|
return peer.user_id
|
||||||
|
|
||||||
|
if isinstance(peer, raw.types.PeerChat):
|
||||||
|
return peer.chat_id
|
||||||
|
|
||||||
|
if isinstance(peer, raw.types.PeerChannel):
|
||||||
|
return peer.channel_id
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_peer_id(peer: raw.base.Peer) -> int:
|
def get_peer_id(peer: raw.base.Peer) -> int:
|
||||||
|
"""Get the non-raw peer id from a Peer object"""
|
||||||
if isinstance(peer, raw.types.PeerUser):
|
if isinstance(peer, raw.types.PeerUser):
|
||||||
return peer.user_id
|
return peer.user_id
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user