mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-08 07:54:52 +00:00
Fix asyncio merge issues
This commit is contained in:
parent
4d8c76463c
commit
0bae143d5d
7 changed files with 48 additions and 39 deletions
|
|
@ -321,7 +321,7 @@ class Client(Methods, BaseClient):
|
||||||
raise ConnectionError("Client is already stopped")
|
raise ConnectionError("Client is already stopped")
|
||||||
|
|
||||||
if self.takeout_id:
|
if self.takeout_id:
|
||||||
self.send(functions.account.FinishTakeoutSession())
|
await self.send(functions.account.FinishTakeoutSession())
|
||||||
log.warning("Takeout session {} finished".format(self.takeout_id))
|
log.warning("Takeout session {} finished".format(self.takeout_id))
|
||||||
|
|
||||||
await Syncer.remove(self)
|
await Syncer.remove(self)
|
||||||
|
|
|
||||||
|
|
@ -78,4 +78,4 @@ class GetDialogs(BaseClient):
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
return pyrogram.Dialogs._parse(self, r)
|
return await pyrogram.Dialogs._parse(self, r)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from string import ascii_lowercase
|
from string import ascii_lowercase
|
||||||
from typing import Union, Generator
|
from typing import Union, AsyncGenerator, Optional
|
||||||
|
|
||||||
|
from async_generator import async_generator, yield_
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
@ -37,11 +39,12 @@ QUERYABLE_FILTERS = (Filters.ALL, Filters.KICKED, Filters.RESTRICTED)
|
||||||
|
|
||||||
|
|
||||||
class IterChatMembers(BaseClient):
|
class IterChatMembers(BaseClient):
|
||||||
def iter_chat_members(self,
|
@async_generator
|
||||||
chat_id: Union[int, str],
|
async def iter_chat_members(self,
|
||||||
limit: int = 0,
|
chat_id: Union[int, str],
|
||||||
query: str = "",
|
limit: int = 0,
|
||||||
filter: str = Filters.ALL) -> Generator["pyrogram.ChatMember", None, None]:
|
query: str = "",
|
||||||
|
filter: str = Filters.ALL) -> Optional[AsyncGenerator["pyrogram.ChatMember", None]]:
|
||||||
"""Use this method to iterate through the members of a chat sequentially.
|
"""Use this method to iterate through the members of a chat sequentially.
|
||||||
|
|
||||||
This convenience method does the same as repeatedly calling :meth:`get_chat_members` in a loop, thus saving you
|
This convenience method does the same as repeatedly calling :meth:`get_chat_members` in a loop, thus saving you
|
||||||
|
|
@ -95,13 +98,13 @@ class IterChatMembers(BaseClient):
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
chat_members = self.get_chat_members(
|
chat_members = (await self.get_chat_members(
|
||||||
chat_id=chat_id,
|
chat_id=chat_id,
|
||||||
offset=offset,
|
offset=offset,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
query=q,
|
query=q,
|
||||||
filter=filter
|
filter=filter
|
||||||
).chat_members
|
)).chat_members
|
||||||
|
|
||||||
if not chat_members:
|
if not chat_members:
|
||||||
break
|
break
|
||||||
|
|
@ -114,7 +117,7 @@ class IterChatMembers(BaseClient):
|
||||||
if user_id in yielded:
|
if user_id in yielded:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
yield chat_member
|
await yield_(chat_member)
|
||||||
|
|
||||||
yielded.add(chat_member.user.id)
|
yielded.add(chat_member.user.id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,30 +16,33 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from typing import Generator
|
from typing import AsyncGenerator, Optional
|
||||||
|
|
||||||
|
from async_generator import async_generator, yield_
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
class IterDialogs(BaseClient):
|
class IterDialogs(BaseClient):
|
||||||
def iter_dialogs(self,
|
@async_generator
|
||||||
offset_date: int = 0,
|
async def iter_dialogs(self,
|
||||||
limit: int = 0) -> Generator["pyrogram.Dialog", None, None]:
|
limit: int = 0,
|
||||||
|
offset_date: int = 0) -> Optional[AsyncGenerator["pyrogram.Dialog", None]]:
|
||||||
"""Use this method to iterate through a user's dialogs sequentially.
|
"""Use this method to iterate through a user's dialogs sequentially.
|
||||||
|
|
||||||
This convenience method does the same as repeatedly calling :meth:`get_dialogs` in a loop, thus saving you from
|
This convenience method does the same as repeatedly calling :meth:`get_dialogs` in a loop, thus saving you from
|
||||||
the hassle of setting up boilerplate code. It is useful for getting the whole dialogs list with a single call.
|
the hassle of setting up boilerplate code. It is useful for getting the whole dialogs list with a single call.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
offset_date (``int``):
|
|
||||||
The offset date in Unix time taken from the top message of a :obj:`Dialog`.
|
|
||||||
Defaults to 0 (most recent dialog).
|
|
||||||
|
|
||||||
limit (``str``, *optional*):
|
limit (``str``, *optional*):
|
||||||
Limits the number of dialogs to be retrieved.
|
Limits the number of dialogs to be retrieved.
|
||||||
By default, no limit is applied and all dialogs are returned.
|
By default, no limit is applied and all dialogs are returned.
|
||||||
|
|
||||||
|
offset_date (``int``):
|
||||||
|
The offset date in Unix time taken from the top message of a :obj:`Dialog`.
|
||||||
|
Defaults to 0 (most recent dialog).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A generator yielding :obj:`Dialog <pyrogram.Dialog>` objects.
|
A generator yielding :obj:`Dialog <pyrogram.Dialog>` objects.
|
||||||
|
|
||||||
|
|
@ -50,12 +53,12 @@ class IterDialogs(BaseClient):
|
||||||
total = limit or (1 << 31) - 1
|
total = limit or (1 << 31) - 1
|
||||||
limit = min(100, total)
|
limit = min(100, total)
|
||||||
|
|
||||||
pinned_dialogs = self.get_dialogs(
|
pinned_dialogs = (await self.get_dialogs(
|
||||||
pinned_only=True
|
pinned_only=True
|
||||||
).dialogs
|
)).dialogs
|
||||||
|
|
||||||
for dialog in pinned_dialogs:
|
for dialog in pinned_dialogs:
|
||||||
yield dialog
|
await yield_(dialog)
|
||||||
|
|
||||||
current += 1
|
current += 1
|
||||||
|
|
||||||
|
|
@ -63,10 +66,10 @@ class IterDialogs(BaseClient):
|
||||||
return
|
return
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
dialogs = self.get_dialogs(
|
dialogs = (await self.get_dialogs(
|
||||||
offset_date=offset_date,
|
offset_date=offset_date,
|
||||||
limit=limit
|
limit=limit
|
||||||
).dialogs
|
)).dialogs
|
||||||
|
|
||||||
if not dialogs:
|
if not dialogs:
|
||||||
return
|
return
|
||||||
|
|
@ -74,7 +77,7 @@ class IterDialogs(BaseClient):
|
||||||
offset_date = dialogs[-1].top_message.date
|
offset_date = dialogs[-1].top_message.date
|
||||||
|
|
||||||
for dialog in dialogs:
|
for dialog in dialogs:
|
||||||
yield dialog
|
await yield_(dialog)
|
||||||
|
|
||||||
current += 1
|
current += 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,20 +16,23 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from typing import Union, Generator
|
from typing import Union, Optional, AsyncGenerator
|
||||||
|
|
||||||
|
from async_generator import async_generator, yield_
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
class IterHistory(BaseClient):
|
class IterHistory(BaseClient):
|
||||||
def iter_history(self,
|
@async_generator
|
||||||
chat_id: Union[int, str],
|
async def iter_history(self,
|
||||||
limit: int = 0,
|
chat_id: Union[int, str],
|
||||||
offset: int = 0,
|
limit: int = 0,
|
||||||
offset_id: int = 0,
|
offset: int = 0,
|
||||||
offset_date: int = 0,
|
offset_id: int = 0,
|
||||||
reverse: bool = False) -> Generator["pyrogram.Message", None, None]:
|
offset_date: int = 0,
|
||||||
|
reverse: bool = False) -> Optional[AsyncGenerator["pyrogram.Message", None]]:
|
||||||
"""Use this method to iterate through a chat history sequentially.
|
"""Use this method to iterate through a chat history sequentially.
|
||||||
|
|
||||||
This convenience method does the same as repeatedly calling :meth:`get_history` in a loop, thus saving you from
|
This convenience method does the same as repeatedly calling :meth:`get_history` in a loop, thus saving you from
|
||||||
|
|
@ -70,14 +73,14 @@ class IterHistory(BaseClient):
|
||||||
limit = min(100, total)
|
limit = min(100, total)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
messages = self.get_history(
|
messages = (await self.get_history(
|
||||||
chat_id=chat_id,
|
chat_id=chat_id,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
offset=offset,
|
offset=offset,
|
||||||
offset_id=offset_id,
|
offset_id=offset_id,
|
||||||
offset_date=offset_date,
|
offset_date=offset_date,
|
||||||
reverse=reverse
|
reverse=reverse
|
||||||
).messages
|
)).messages
|
||||||
|
|
||||||
if not messages:
|
if not messages:
|
||||||
return
|
return
|
||||||
|
|
@ -85,7 +88,7 @@ class IterHistory(BaseClient):
|
||||||
offset_id = messages[-1].message_id + (1 if reverse else 0)
|
offset_id = messages[-1].message_id + (1 if reverse else 0)
|
||||||
|
|
||||||
for message in messages:
|
for message in messages:
|
||||||
yield message
|
await yield_(message)
|
||||||
|
|
||||||
current += 1
|
current += 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class Messages(PyrogramType, Update):
|
||||||
parsed_messages = []
|
parsed_messages = []
|
||||||
|
|
||||||
for message in messages.messages:
|
for message in messages.messages:
|
||||||
parsed_messages.appen(await Message._parse(client, message, users, chats, replies=0))
|
parsed_messages.append(await Message._parse(client, message, users, chats, replies=0))
|
||||||
|
|
||||||
if replies:
|
if replies:
|
||||||
messages_with_replies = {i.id: getattr(i, "reply_to_msg_id", None) for i in messages.messages}
|
messages_with_replies = {i.id: getattr(i, "reply_to_msg_id", None) for i in messages.messages}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class Dialogs(PyrogramType):
|
||||||
self.dialogs = dialogs
|
self.dialogs = dialogs
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(client, dialogs) -> "Dialogs":
|
async def _parse(client, dialogs) -> "Dialogs":
|
||||||
users = {i.id: i for i in dialogs.users}
|
users = {i.id: i for i in dialogs.users}
|
||||||
chats = {i.id: i for i in dialogs.chats}
|
chats = {i.id: i for i in dialogs.chats}
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ class Dialogs(PyrogramType):
|
||||||
else:
|
else:
|
||||||
chat_id = int("-100" + str(to_id.channel_id))
|
chat_id = int("-100" + str(to_id.channel_id))
|
||||||
|
|
||||||
messages[chat_id] = Message._parse(client, message, users, chats)
|
messages[chat_id] = await Message._parse(client, message, users, chats)
|
||||||
|
|
||||||
return Dialogs(
|
return Dialogs(
|
||||||
total_count=getattr(dialogs, "count", len(dialogs.dialogs)),
|
total_count=getattr(dialogs, "count", len(dialogs.dialogs)),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue