diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 04cf917f..3db9e7a9 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -325,6 +325,8 @@ def pyrogram_api(): set_chat_menu_button get_chat_menu_button answer_web_app_query + get_bot_info + set_bot_info """, authorization=""" Authorization @@ -411,6 +413,7 @@ def pyrogram_api(): ForumTopic PeerUser PeerChannel + BotInfo """, messages_media=""" Messages & Media diff --git a/pyrogram/methods/bots/__init__.py b/pyrogram/methods/bots/__init__.py index da52fcfb..53612555 100644 --- a/pyrogram/methods/bots/__init__.py +++ b/pyrogram/methods/bots/__init__.py @@ -22,6 +22,7 @@ from .answer_web_app_query import AnswerWebAppQuery from .delete_bot_commands import DeleteBotCommands from .get_bot_commands import GetBotCommands from .get_bot_default_privileges import GetBotDefaultPrivileges +from .get_bot_info import GetBotInfo from .get_chat_menu_button import GetChatMenuButton from .get_game_high_scores import GetGameHighScores from .get_inline_bot_results import GetInlineBotResults @@ -30,6 +31,7 @@ from .send_game import SendGame from .send_inline_bot_result import SendInlineBotResult from .set_bot_commands import SetBotCommands from .set_bot_default_privileges import SetBotDefaultPrivileges +from .set_bot_info import SetBotInfo from .set_chat_menu_button import SetChatMenuButton from .set_game_score import SetGameScore @@ -48,6 +50,8 @@ class Bots( DeleteBotCommands, SetBotDefaultPrivileges, GetBotDefaultPrivileges, + SetBotInfo, + GetBotInfo, SetChatMenuButton, GetChatMenuButton, AnswerWebAppQuery diff --git a/pyrogram/methods/bots/get_bot_info.py b/pyrogram/methods/bots/get_bot_info.py new file mode 100644 index 00000000..dcb60de6 --- /dev/null +++ b/pyrogram/methods/bots/get_bot_info.py @@ -0,0 +1,49 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +from typing import Union + +import pyrogram +from pyrogram import raw + + +class GetBotInfo: + async def get_bot_info( + self: "pyrogram.Client", + lang_code: str, + bot: Union[int, str] = None + ) -> pyrogram.types.BotInfo: + """Get the bot info in given language. + + .. include:: /_includes/usable-by/users-bots.rst + + Note: + For normal bot you can only use this method to self. + For userbot you can only use this method if you are the owner of target bot. + + Parameters: + lang_code ``str``: + A two-letter ISO 639-1 language code. + bot (``int`` | ``str``, *optional*): + Unique identifier (int) or username (str) of the target bot. + """ + peer = None + if bot: + peer = await self.resolve_peer(bot) + r = await self.invoke(raw.functions.bots.GetBotInfo(lang_code=lang_code, bot=peer)) + return pyrogram.types.BotInfo._parse(r) diff --git a/pyrogram/methods/bots/set_bot_info.py b/pyrogram/methods/bots/set_bot_info.py new file mode 100644 index 00000000..7559a6b4 --- /dev/null +++ b/pyrogram/methods/bots/set_bot_info.py @@ -0,0 +1,61 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +from typing import Union + +import pyrogram +from pyrogram import raw + + +class SetBotInfo: + async def set_bot_info( + self: "pyrogram.Client", + lang_code: str, + bot: Union[int, str] = None, + name: str = None, + about: str = None, + description: str = None + ) -> bool: + """Get the bot info in given language. + + .. include:: /_includes/usable-by/users-bots.rst + + Note: + For normal bot you can only use this method to self. + For userbot you can only use this method if you are the owner of target bot. + + Parameters: + lang_code ``str``: + A two-letter ISO 639-1 language code. + bot (``int`` | ``str``, *optional*) : + Unique identifier (int) or username (str) of the target bot. + + name (``str``, *optional*): + The bot name. + + about (``str``, *optional*): + The bot bio. + + description (``str``, *optional*): + Description of the bot; + """ + peer = None + if bot: + peer = await self.resolve_peer(bot) + r = await self.invoke(raw.functions.bots.SetBotInfo(lang_code=lang_code, bot=peer, name=name, about=about, description=description)) + return bool(r) diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py index 6f05a3b4..bb9e0286 100644 --- a/pyrogram/types/bots_and_keyboards/__init__.py +++ b/pyrogram/types/bots_and_keyboards/__init__.py @@ -25,6 +25,7 @@ from .bot_command_scope_chat import BotCommandScopeChat from .bot_command_scope_chat_administrators import BotCommandScopeChatAdministrators from .bot_command_scope_chat_member import BotCommandScopeChatMember from .bot_command_scope_default import BotCommandScopeDefault +from .bot_info import BotInfo from .callback_game import CallbackGame from .callback_query import CallbackQuery from .force_reply import ForceReply @@ -62,6 +63,7 @@ __all__ = [ "BotCommandScopeChatAdministrators", "BotCommandScopeChatMember", "BotCommandScopeDefault", + "BotInfo", "WebAppInfo", "MenuButton", "MenuButtonCommands", diff --git a/pyrogram/types/bots_and_keyboards/bot_info.py b/pyrogram/types/bots_and_keyboards/bot_info.py new file mode 100644 index 00000000..c88bc92c --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/bot_info.py @@ -0,0 +1,52 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +from pyrogram import raw + +from ..object import Object + + +class BotInfo(Object): + """A bot Information. + + Parameters: + name (``str``): + The bot name. + + about (``str``): + The bot bio. + + description (``str``): + Description of the bot; + """ + + def __init__(self, name: str, about: str, description: str): + super().__init__() + + self.name = name + self.about = about + self.description = description + + + @staticmethod + def _parse(bot_info: "raw.types.bots.BotInfo") -> "BotInfo": + return BotInfo( + name=getattr(bot_info,"name", None), + about=getattr(bot_info,"about", None), + description=getattr(bot_info,"description", None) + )