Update check_username method

This commit is contained in:
KurimuzonAkuma 2024-03-06 15:21:17 +03:00
parent f6ca25af72
commit befab2f1b5

View File

@ -16,6 +16,8 @@
# 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 Union
import pyrogram
from pyrogram import raw
@ -23,6 +25,7 @@ from pyrogram import raw
class CheckUsername:
async def check_username(
self: "pyrogram.Client",
chat_id: Union[int, str],
username: str
) -> bool:
"""Check if a username is available.
@ -30,6 +33,9 @@ class CheckUsername:
.. include:: /_includes/usable-by/users.rst
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
username (``str``):
Username to check.
@ -39,13 +45,22 @@ class CheckUsername:
Example:
.. code-block:: python
await app.check_username("username")
await app.check_username("me", "username")
"""
peer = await self.resolve_peer(chat_id)
return bool(
await self.invoke(
if isinstance(peer, raw.types.InputPeerChannel):
r = await self.invoke(
raw.functions.channels.CheckUsername(
channel=peer,
username=username
)
)
else:
r = await self.invoke(
raw.functions.account.CheckUsername(
username=username
)
)
)
return bool(r)