Skip to content

Commit d0aad9d

Browse files
authored
add update_status, delete_account methods (#51)
1 parent 3e33eec commit d0aad9d

File tree

5 files changed

+111
-1
lines changed

5 files changed

+111
-1
lines changed

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ def get_title_list(s: str) -> list:
382382
set_emoji_status
383383
set_birthdate
384384
set_personal_chat
385+
delete_account
386+
update_status
385387
""",
386388
business="""
387389
Telegram Business & Fragment

docs/source/releases/changes-in-this-fork.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If you found any issue or have any suggestions, feel free to make `an issue <htt
1414
| Scheme layer used: 184 |
1515
+------------------------+
1616

17-
- Added the :meth:`~pyrogram.Client.transfer_chat_ownership` (`#49 <https://github.com/TelegramPlayGround/pyrogram/pull/49>`__)
17+
- Added the :meth:`~pyrogram.Client.delete_account`, :meth:`~pyrogram.Client.transfer_chat_ownership`, :meth:`~pyrogram.Client.update_status` (`#49 <https://github.com/TelegramPlayGround/pyrogram/pull/49>`__, `#51 <https://github.com/TelegramPlayGround/pyrogram/pull/51>`__)
1818
- Added the class :obj:`~pyrogram.types.RefundedPayment`, containing information about a refunded payment.
1919
- Added the field ``refunded_payment`` to the class :obj:`~pyrogram.types.Message`, describing a service message about a refunded payment.
2020
- `View new and changed raw API methods <https://telegramplayground.github.io/TG-APIs/TL/diff/tdesktop.html?from=183&to=184>`__.

pyrogram/methods/users/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from .update_profile import UpdateProfile
3232
from .set_birthdate import SetBirthdate
3333
from .set_personal_chat import SetPersonalChat
34+
from .update_status import UpdateStatus
35+
from .delete_account import DeleteAccount
3436

3537

3638
class Users(
@@ -49,5 +51,7 @@ class Users(
4951
SetUsername,
5052
UnblockUser,
5153
UpdateProfile,
54+
UpdateStatus,
55+
DeleteAccount,
5256
):
5357
pass
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
import pyrogram
20+
from pyrogram import raw
21+
from pyrogram.utils import compute_password_check
22+
23+
24+
class DeleteAccount:
25+
async def delete_account(
26+
self: "pyrogram.Client", reason: str = "", password: str = None
27+
) -> bool:
28+
"""Deletes the account of the current user, deleting all information associated with the user from the server.
29+
30+
.. include:: /_includes/usable-by/users.rst
31+
32+
Parameters:
33+
reason (``str``, *optional*):
34+
The reason why the account was deleted.
35+
36+
password (``str``, *optional*):
37+
The 2-step verification password of the current user. If the current user isn't authorized, then an empty string can be passed and account deletion can be canceled within one week.
38+
39+
Returns:
40+
`bool`: True On success.
41+
42+
Example:
43+
.. code-block:: python
44+
45+
await app.delete_account(reason, password)
46+
"""
47+
r = await self.invoke(
48+
raw.functions.account.DeleteAccount(
49+
reason=reason,
50+
password=compute_password_check(
51+
await self.invoke(raw.functions.account.GetPassword()), password
52+
)
53+
if password
54+
else None,
55+
)
56+
)
57+
58+
return bool(r)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
import pyrogram
20+
from pyrogram import raw
21+
22+
23+
class UpdateStatus:
24+
async def update_status(
25+
self: "pyrogram.Client",
26+
offline: bool = False,
27+
) -> bool:
28+
"""Updates online user status.
29+
30+
.. include:: /_includes/usable-by/users.rst
31+
32+
Parameters:
33+
offline (``bool``):
34+
If (True) is transmitted, user status will change to (UserStatusOffline), Otherwise user status will change to (UserStatusOnline).
35+
36+
Returns:
37+
`bool`: True On success.
38+
39+
Example:
40+
.. code-block:: python
41+
42+
await app.update_status()
43+
"""
44+
r = await self.invoke(raw.functions.account.UpdateStatus(offline=offline))
45+
46+
return bool(r)

0 commit comments

Comments
 (0)