mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Add methods {get,set}_bot_default_privileges.py
This commit is contained in:
parent
c54be38696
commit
7654dc82e8
@ -295,6 +295,8 @@ def pyrogram_api():
|
|||||||
set_bot_commands
|
set_bot_commands
|
||||||
get_bot_commands
|
get_bot_commands
|
||||||
delete_bot_commands
|
delete_bot_commands
|
||||||
|
set_bot_default_privileges
|
||||||
|
get_bot_default_privileges
|
||||||
""",
|
""",
|
||||||
authorization="""
|
authorization="""
|
||||||
Authorization
|
Authorization
|
||||||
|
@ -20,12 +20,14 @@ from .answer_callback_query import AnswerCallbackQuery
|
|||||||
from .answer_inline_query import AnswerInlineQuery
|
from .answer_inline_query import AnswerInlineQuery
|
||||||
from .delete_bot_commands import DeleteBotCommands
|
from .delete_bot_commands import DeleteBotCommands
|
||||||
from .get_bot_commands import GetBotCommands
|
from .get_bot_commands import GetBotCommands
|
||||||
|
from .get_bot_default_privileges import GetBotDefaultPrivileges
|
||||||
from .get_game_high_scores import GetGameHighScores
|
from .get_game_high_scores import GetGameHighScores
|
||||||
from .get_inline_bot_results import GetInlineBotResults
|
from .get_inline_bot_results import GetInlineBotResults
|
||||||
from .request_callback_answer import RequestCallbackAnswer
|
from .request_callback_answer import RequestCallbackAnswer
|
||||||
from .send_game import SendGame
|
from .send_game import SendGame
|
||||||
from .send_inline_bot_result import SendInlineBotResult
|
from .send_inline_bot_result import SendInlineBotResult
|
||||||
from .set_bot_commands import SetBotCommands
|
from .set_bot_commands import SetBotCommands
|
||||||
|
from .set_bot_default_privileges import SetBotDefaultPrivileges
|
||||||
from .set_game_score import SetGameScore
|
from .set_game_score import SetGameScore
|
||||||
|
|
||||||
|
|
||||||
@ -40,6 +42,8 @@ class Bots(
|
|||||||
GetGameHighScores,
|
GetGameHighScores,
|
||||||
SetBotCommands,
|
SetBotCommands,
|
||||||
GetBotCommands,
|
GetBotCommands,
|
||||||
DeleteBotCommands
|
DeleteBotCommands,
|
||||||
|
SetBotDefaultPrivileges,
|
||||||
|
GetBotDefaultPrivileges
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
57
pyrogram/methods/bots/get_bot_default_privileges.py
Normal file
57
pyrogram/methods/bots/get_bot_default_privileges.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# 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 types
|
||||||
|
|
||||||
|
|
||||||
|
class GetBotDefaultPrivileges:
|
||||||
|
async def get_bot_default_privileges(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
for_channels: bool = None
|
||||||
|
) -> Optional["types.ChatPrivileges"]:
|
||||||
|
"""Get the current default privileges of the bot.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
for_channels (``bool``, *optional*):
|
||||||
|
Pass True to get default privileges of the bot in channels. Otherwise, default privileges of the bot
|
||||||
|
for groups and supergroups will be returned.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: On success, True is returned.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
privileges = await app.get_bot_default_privileges()
|
||||||
|
"""
|
||||||
|
|
||||||
|
bot_info = await self.invoke(
|
||||||
|
raw.functions.users.GetFullUser(
|
||||||
|
id=raw.types.InputUserSelf()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
field = "bot_broadcast_admin_rights" if for_channels else "bot_group_admin_rights"
|
||||||
|
|
||||||
|
admin_rights = getattr(bot_info.full_user, field)
|
||||||
|
|
||||||
|
return types.ChatPrivileges._parse(admin_rights) if admin_rights else None
|
79
pyrogram/methods/bots/set_bot_default_privileges.py
Normal file
79
pyrogram/methods/bots/set_bot_default_privileges.py
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
# 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 SetBotDefaultPrivileges:
|
||||||
|
async def set_bot_default_privileges(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
privileges: "types.ChatPrivileges" = None,
|
||||||
|
for_channels: bool = None
|
||||||
|
) -> bool:
|
||||||
|
"""Change the default privileges requested by the bot when it's added as an administrator to groups or channels.
|
||||||
|
|
||||||
|
These privileges will be suggested to users, but they are are free to modify the list before adding the bot.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
privileges (:obj:`~pyrogram.types.ChatPrivileges`):
|
||||||
|
New default privileges. None to clear.
|
||||||
|
Defaults to None.
|
||||||
|
|
||||||
|
for_channels (``bool``, *optional*):
|
||||||
|
Pass True to change the default privileges of the bot in channels. Otherwise, the default privileges of
|
||||||
|
the bot for groups and supergroups will be changed.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: On success, True is returned.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from pyrogram.types import ChatPrivileges
|
||||||
|
|
||||||
|
await app.set_bot_default_privileges(
|
||||||
|
ChatPrivileges(
|
||||||
|
can_delete_messages=True,
|
||||||
|
can_restrict_members=True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
|
||||||
|
function = (
|
||||||
|
raw.functions.bots.SetBotBroadcastDefaultAdminRights
|
||||||
|
if for_channels
|
||||||
|
else raw.functions.bots.SetBotGroupDefaultAdminRights
|
||||||
|
)
|
||||||
|
|
||||||
|
admin_rights = raw.types.ChatAdminRights(
|
||||||
|
change_info=privileges.can_change_info,
|
||||||
|
post_messages=privileges.can_post_messages,
|
||||||
|
edit_messages=privileges.can_edit_messages,
|
||||||
|
delete_messages=privileges.can_delete_messages,
|
||||||
|
ban_users=privileges.can_restrict_members,
|
||||||
|
invite_users=privileges.can_invite_users,
|
||||||
|
pin_messages=privileges.can_pin_messages,
|
||||||
|
add_admins=privileges.can_promote_members,
|
||||||
|
anonymous=privileges.is_anonymous,
|
||||||
|
manage_call=privileges.can_manage_video_chats,
|
||||||
|
other=privileges.can_manage_chat
|
||||||
|
) if privileges else raw.types.ChatAdminRights()
|
||||||
|
|
||||||
|
return await self.invoke(function(admin_rights=admin_rights))
|
Loading…
x
Reference in New Issue
Block a user