mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-27 08:36:27 +00:00
Update check_username method
This commit is contained in:
parent
f6ca25af72
commit
befab2f1b5
@ -16,6 +16,8 @@
|
|||||||
# 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
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram import raw
|
from pyrogram import raw
|
||||||
|
|
||||||
@ -23,6 +25,7 @@ from pyrogram import raw
|
|||||||
class CheckUsername:
|
class CheckUsername:
|
||||||
async def check_username(
|
async def check_username(
|
||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
|
chat_id: Union[int, str],
|
||||||
username: str
|
username: str
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Check if a username is available.
|
"""Check if a username is available.
|
||||||
@ -30,6 +33,9 @@ class CheckUsername:
|
|||||||
.. include:: /_includes/usable-by/users.rst
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
chat_id (``int`` | ``str``):
|
||||||
|
Unique identifier (int) or username (str) of the target chat.
|
||||||
|
|
||||||
username (``str``):
|
username (``str``):
|
||||||
Username to check.
|
Username to check.
|
||||||
|
|
||||||
@ -39,13 +45,22 @@ class CheckUsername:
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
await app.check_username("username")
|
await app.check_username("me", "username")
|
||||||
"""
|
"""
|
||||||
|
peer = await self.resolve_peer(chat_id)
|
||||||
|
|
||||||
return bool(
|
if isinstance(peer, raw.types.InputPeerChannel):
|
||||||
await self.invoke(
|
r = await self.invoke(
|
||||||
|
raw.functions.channels.CheckUsername(
|
||||||
|
channel=peer,
|
||||||
|
username=username
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
r = await self.invoke(
|
||||||
raw.functions.account.CheckUsername(
|
raw.functions.account.CheckUsername(
|
||||||
username=username
|
username=username
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
return bool(r)
|
||||||
|
Loading…
Reference in New Issue
Block a user