Request GetChannels as required

This commit is contained in:
KurimuzonAkuma 2023-11-09 11:39:24 +03:00
parent 01290e882f
commit dcdf65ebf3
2 changed files with 17 additions and 5 deletions

View File

@ -21,6 +21,7 @@ from typing import AsyncGenerator, Union, Optional
import pyrogram import pyrogram
from pyrogram import raw from pyrogram import raw
from pyrogram import types from pyrogram import types
from pyrogram import utils
class GetPinnedStories: class GetPinnedStories:
@ -60,8 +61,9 @@ class GetPinnedStories:
total = abs(limit) or (1 << 31) total = abs(limit) or (1 << 31)
limit = min(100, total) limit = min(100, total)
peer = await self.resolve_peer(chat_id)
while True: while True:
peer = await self.resolve_peer(chat_id)
r = await self.invoke( r = await self.invoke(
raw.functions.stories.GetPinnedStories( raw.functions.stories.GetPinnedStories(
peer=peer, peer=peer,
@ -73,6 +75,15 @@ class GetPinnedStories:
if not r.stories: if not r.stories:
return return
users = {i.id: i for i in r.users}
chats = {i.id: i for i in r.chats}
if isinstance(peer, raw.types.InputPeerChannel):
peer_id = utils.get_input_peer_id(peer)
if peer_id not in r.chats:
channel = await self.invoke(raw.functions.channels.GetChannels(id=[peer]))
chats.update({peer_id: channel.chats[0]})
last = r.stories[-1] last = r.stories[-1]
offset_id = last.id offset_id = last.id
@ -80,8 +91,8 @@ class GetPinnedStories:
yield await types.Story._parse( yield await types.Story._parse(
self, self,
story, story,
{i.id: i for i in r.users}, users,
{i.id: i for i in r.chats}, chats,
peer peer
) )

View File

@ -196,8 +196,9 @@ class Story(Object, Update):
peer_id = utils.get_input_peer_id(peer) peer_id = utils.get_input_peer_id(peer)
elif isinstance(peer, raw.types.InputPeerChannel): elif isinstance(peer, raw.types.InputPeerChannel):
peer_id = utils.get_input_peer_id(peer) peer_id = utils.get_input_peer_id(peer)
r = await client.invoke(raw.functions.channels.GetChannels(id=[peer])) if peer_id not in chats:
chats.update({peer_id: r.chats[0]}) r = await client.invoke(raw.functions.channels.GetChannels(id=[peer]))
chats.update({peer_id: r.chats[0]})
else: else:
peer_id = utils.get_raw_peer_id(peer) peer_id = utils.get_raw_peer_id(peer)