mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add search_contacts, set_account_ttl and get_account_ttl method
This commit is contained in:
parent
151bbd7139
commit
438e9d2f0e
@ -314,6 +314,7 @@ def pyrogram_api():
|
|||||||
import_contacts
|
import_contacts
|
||||||
get_contacts
|
get_contacts
|
||||||
get_contacts_count
|
get_contacts_count
|
||||||
|
search_contacts
|
||||||
""",
|
""",
|
||||||
payments="""
|
payments="""
|
||||||
Payments
|
Payments
|
||||||
@ -406,6 +407,11 @@ def pyrogram_api():
|
|||||||
apply_boost
|
apply_boost
|
||||||
get_boosts
|
get_boosts
|
||||||
get_boosts_status
|
get_boosts_status
|
||||||
|
""",
|
||||||
|
account="""
|
||||||
|
Account
|
||||||
|
get_account_ttl
|
||||||
|
set_account_ttl
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -475,6 +481,7 @@ def pyrogram_api():
|
|||||||
Folder
|
Folder
|
||||||
GroupCallMember
|
GroupCallMember
|
||||||
ChatColor
|
ChatColor
|
||||||
|
FoundContacts
|
||||||
""",
|
""",
|
||||||
messages_media="""
|
messages_media="""
|
||||||
Messages & Media
|
Messages & Media
|
||||||
|
13
compiler/docs/template/methods.rst
vendored
13
compiler/docs/template/methods.rst
vendored
@ -216,6 +216,19 @@ Payments
|
|||||||
|
|
||||||
{payments}
|
{payments}
|
||||||
|
|
||||||
|
Account
|
||||||
|
-------
|
||||||
|
|
||||||
|
.. autosummary::
|
||||||
|
:nosignatures:
|
||||||
|
|
||||||
|
{account}
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:hidden:
|
||||||
|
|
||||||
|
{account}
|
||||||
|
|
||||||
Advanced
|
Advanced
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
# 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 .account import Account
|
||||||
from .advanced import Advanced
|
from .advanced import Advanced
|
||||||
from .auth import Auth
|
from .auth import Auth
|
||||||
from .business import Business
|
from .business import Business
|
||||||
@ -35,6 +36,7 @@ from .utilities import Utilities
|
|||||||
|
|
||||||
|
|
||||||
class Methods(
|
class Methods(
|
||||||
|
Account,
|
||||||
Advanced,
|
Advanced,
|
||||||
Auth,
|
Auth,
|
||||||
Business,
|
Business,
|
||||||
|
27
pyrogram/methods/account/__init__.py
Normal file
27
pyrogram/methods/account/__init__.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from .get_account_ttl import GetAccountTTL
|
||||||
|
from .set_account_ttl import SetAccountTTL
|
||||||
|
|
||||||
|
|
||||||
|
class Account(
|
||||||
|
GetAccountTTL,
|
||||||
|
SetAccountTTL
|
||||||
|
):
|
||||||
|
pass
|
44
pyrogram/methods/account/get_account_ttl.py
Normal file
44
pyrogram/methods/account/get_account_ttl.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw
|
||||||
|
|
||||||
|
|
||||||
|
class GetAccountTTL:
|
||||||
|
async def get_account_ttl(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
):
|
||||||
|
"""Get days to live of account.
|
||||||
|
|
||||||
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``int``: Time to live in days of the current account.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Get ttl in days
|
||||||
|
await app.get_account_ttl()
|
||||||
|
"""
|
||||||
|
r = await self.invoke(
|
||||||
|
raw.functions.account.GetAccountTTL()
|
||||||
|
)
|
||||||
|
|
||||||
|
return r.days
|
51
pyrogram/methods/account/set_account_ttl.py
Normal file
51
pyrogram/methods/account/set_account_ttl.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw
|
||||||
|
|
||||||
|
|
||||||
|
class SetAccountTTL:
|
||||||
|
async def set_account_ttl(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
days: int
|
||||||
|
):
|
||||||
|
"""Set days to live of account.
|
||||||
|
|
||||||
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
days (``int``):
|
||||||
|
Time to live in days.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: On success, True is returned.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Set ttl in days
|
||||||
|
await app.set_account_ttl(365)
|
||||||
|
"""
|
||||||
|
r = await self.invoke(
|
||||||
|
raw.functions.account.SetAccountTTL(
|
||||||
|
ttl=raw.types.AccountDaysTTL(days=days)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return r
|
@ -21,6 +21,7 @@ from .delete_contacts import DeleteContacts
|
|||||||
from .get_contacts import GetContacts
|
from .get_contacts import GetContacts
|
||||||
from .get_contacts_count import GetContactsCount
|
from .get_contacts_count import GetContactsCount
|
||||||
from .import_contacts import ImportContacts
|
from .import_contacts import ImportContacts
|
||||||
|
from .search_contacts import SearchContacts
|
||||||
|
|
||||||
|
|
||||||
class Contacts(
|
class Contacts(
|
||||||
@ -28,6 +29,7 @@ class Contacts(
|
|||||||
DeleteContacts,
|
DeleteContacts,
|
||||||
ImportContacts,
|
ImportContacts,
|
||||||
GetContactsCount,
|
GetContactsCount,
|
||||||
AddContact
|
AddContact,
|
||||||
|
SearchContacts
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
59
pyrogram/methods/contacts/search_contacts.py
Normal file
59
pyrogram/methods/contacts/search_contacts.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw
|
||||||
|
from pyrogram import types
|
||||||
|
|
||||||
|
|
||||||
|
class SearchContacts:
|
||||||
|
async def search_contacts(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
query: str,
|
||||||
|
limit: int = 0
|
||||||
|
):
|
||||||
|
"""Returns users or channels found by name substring and auxiliary data.
|
||||||
|
|
||||||
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
query (``str``):
|
||||||
|
Target substring.
|
||||||
|
|
||||||
|
limit (``int``, *optional*):
|
||||||
|
Maximum number of users to be returned.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
:obj:`~pyrogram.types.FoundContacts`: On success, a list of chats is returned.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
await app.search_contacts("pyrogram")
|
||||||
|
"""
|
||||||
|
total = limit or (1 << 31) - 1
|
||||||
|
limit = min(100, total)
|
||||||
|
|
||||||
|
r = await self.invoke(
|
||||||
|
raw.functions.contacts.Search(
|
||||||
|
q=query,
|
||||||
|
limit=limit
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return types.FoundContacts._parse(self, r)
|
@ -40,6 +40,7 @@ from .chat_reactions import ChatReactions
|
|||||||
from .dialog import Dialog
|
from .dialog import Dialog
|
||||||
from .emoji_status import EmojiStatus
|
from .emoji_status import EmojiStatus
|
||||||
from .folder import Folder
|
from .folder import Folder
|
||||||
|
from .found_contacts import FoundContacts
|
||||||
from .group_call_member import GroupCallMember
|
from .group_call_member import GroupCallMember
|
||||||
from .invite_link_importer import InviteLinkImporter
|
from .invite_link_importer import InviteLinkImporter
|
||||||
from .restriction import Restriction
|
from .restriction import Restriction
|
||||||
@ -82,6 +83,7 @@ __all__ = [
|
|||||||
"ChatJoiner",
|
"ChatJoiner",
|
||||||
"EmojiStatus",
|
"EmojiStatus",
|
||||||
"Folder",
|
"Folder",
|
||||||
|
"FoundContacts",
|
||||||
"GroupCallMember",
|
"GroupCallMember",
|
||||||
"ChatReactions"
|
"ChatReactions"
|
||||||
]
|
]
|
||||||
|
75
pyrogram/types/user_and_chats/found_contacts.py
Normal file
75
pyrogram/types/user_and_chats/found_contacts.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw
|
||||||
|
from pyrogram import utils
|
||||||
|
from pyrogram import types
|
||||||
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
class FoundContacts(Object):
|
||||||
|
"""Chats found by name substring and auxiliary data.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
my_results (List of :obj:`~pyrogram.types.Chat`, *optional*):
|
||||||
|
Personalized results.
|
||||||
|
|
||||||
|
global_results (List of :obj:`~pyrogram.types.Chat`, *optional*):
|
||||||
|
List of found chats in global search.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
client: "pyrogram.Client" = None,
|
||||||
|
my_results: Optional["types.Chat"] = None,
|
||||||
|
global_results: Optional["types.Chat"] = None
|
||||||
|
):
|
||||||
|
super().__init__(client)
|
||||||
|
|
||||||
|
self.my_results = my_results
|
||||||
|
self.global_results = global_results
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _parse(client, found: "raw.types.contacts.Found") -> "FoundContacts":
|
||||||
|
users = {u.id: u for u in found.users}
|
||||||
|
chats = {c.id: c for c in found.chats}
|
||||||
|
|
||||||
|
my_results = []
|
||||||
|
global_results = []
|
||||||
|
|
||||||
|
for result in found.my_results:
|
||||||
|
peer_id = utils.get_raw_peer_id(result)
|
||||||
|
peer = users.get(peer_id) or chats.get(peer_id)
|
||||||
|
|
||||||
|
my_results.append(types.Chat._parse_chat(client, peer))
|
||||||
|
|
||||||
|
for result in found.results:
|
||||||
|
peer_id = utils.get_raw_peer_id(result)
|
||||||
|
peer = users.get(peer_id) or chats.get(peer_id)
|
||||||
|
|
||||||
|
global_results.append(types.Chat._parse_chat(client, peer))
|
||||||
|
|
||||||
|
return FoundContacts(
|
||||||
|
my_results=types.List(my_results) or None,
|
||||||
|
global_results=types.List(global_results) or None,
|
||||||
|
client=client
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user