mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Make get_contacts return a list of User objects
This commit is contained in:
parent
712b390f77
commit
23a40a45ca
@ -19,7 +19,8 @@
|
|||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from pyrogram.api import functions, types
|
import pyrogram
|
||||||
|
from pyrogram.api import functions
|
||||||
from pyrogram.api.errors import FloodWait
|
from pyrogram.api.errors import FloodWait
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
@ -28,12 +29,10 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class GetContacts(BaseClient):
|
class GetContacts(BaseClient):
|
||||||
def get_contacts(self):
|
def get_contacts(self):
|
||||||
"""Use this method to get contacts from your Telegram address book
|
"""Use this method to get contacts from your Telegram address book.
|
||||||
|
|
||||||
Requires no parameters.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
On success, the user's contacts are returned
|
On success, a list of :obj:`User` objects is returned.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
||||||
@ -44,9 +43,6 @@ class GetContacts(BaseClient):
|
|||||||
except FloodWait as e:
|
except FloodWait as e:
|
||||||
log.warning("get_contacts flood: waiting {} seconds".format(e.x))
|
log.warning("get_contacts flood: waiting {} seconds".format(e.x))
|
||||||
time.sleep(e.x)
|
time.sleep(e.x)
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
if isinstance(contacts, types.contacts.Contacts):
|
log.info("Total contacts: {}".format(len(self.peers_by_phone)))
|
||||||
log.info("Total contacts: {}".format(len(self.peers_by_phone)))
|
return [pyrogram.User._parse(self, user) for user in contacts.users]
|
||||||
|
|
||||||
return contacts
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user