From 7caeeb667f064e53e750db25e4548e6c4f3faf67 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Mon, 8 Nov 2021 01:34:30 +0200 Subject: [PATCH] Added new modules --- aiogram/methods/approve_chat_join_request.py | 28 ++++++++++ aiogram/methods/decline_chat_join_request.py | 28 ++++++++++ aiogram/types/chat_join_request.py | 32 ++++++++++++ .../api/methods/approve_chat_join_request.rst | 51 +++++++++++++++++++ .../api/methods/decline_chat_join_request.rst | 51 +++++++++++++++++++ docs/api/types/chat_join_request.rst | 9 ++++ 6 files changed, 199 insertions(+) create mode 100644 aiogram/methods/approve_chat_join_request.py create mode 100644 aiogram/methods/decline_chat_join_request.py create mode 100644 aiogram/types/chat_join_request.py create mode 100644 docs/api/methods/approve_chat_join_request.rst create mode 100644 docs/api/methods/decline_chat_join_request.rst create mode 100644 docs/api/types/chat_join_request.rst diff --git a/aiogram/methods/approve_chat_join_request.py b/aiogram/methods/approve_chat_join_request.py new file mode 100644 index 00000000..5c4008af --- /dev/null +++ b/aiogram/methods/approve_chat_join_request.py @@ -0,0 +1,28 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union + +from .base import Request, TelegramMethod + +if TYPE_CHECKING: + from ..client.bot import Bot + + +class ApproveChatJoinRequest(TelegramMethod[bool]): + """ + Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right. Returns :code:`True` on success. + + Source: https://core.telegram.org/bots/api#approvechatjoinrequest + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" + user_id: int + """Unique identifier of the target user""" + + def build_request(self, bot: Bot) -> Request: + data: Dict[str, Any] = self.dict() + + return Request(method="approveChatJoinRequest", data=data) diff --git a/aiogram/methods/decline_chat_join_request.py b/aiogram/methods/decline_chat_join_request.py new file mode 100644 index 00000000..6bc03c9e --- /dev/null +++ b/aiogram/methods/decline_chat_join_request.py @@ -0,0 +1,28 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union + +from .base import Request, TelegramMethod + +if TYPE_CHECKING: + from ..client.bot import Bot + + +class DeclineChatJoinRequest(TelegramMethod[bool]): + """ + Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right. Returns :code:`True` on success. + + Source: https://core.telegram.org/bots/api#declinechatjoinrequest + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" + user_id: int + """Unique identifier of the target user""" + + def build_request(self, bot: Bot) -> Request: + data: Dict[str, Any] = self.dict() + + return Request(method="declineChatJoinRequest", data=data) diff --git a/aiogram/types/chat_join_request.py b/aiogram/types/chat_join_request.py new file mode 100644 index 00000000..fd411ba4 --- /dev/null +++ b/aiogram/types/chat_join_request.py @@ -0,0 +1,32 @@ +from __future__ import annotations + +import datetime +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .base import TelegramObject + +if TYPE_CHECKING: + from .chat import Chat + from .chat_invite_link import ChatInviteLink + from .user import User + + +class ChatJoinRequest(TelegramObject): + """ + Represents a join request sent to a chat. + + Source: https://core.telegram.org/bots/api#chatjoinrequest + """ + + chat: Chat + """Chat to which the request was sent""" + from_user: User = Field(..., alias="from") + """User that sent the join request""" + date: datetime.datetime + """Date the request was sent in Unix time""" + bio: Optional[str] = None + """*Optional*. Bio of the user.""" + invite_link: Optional[ChatInviteLink] = None + """*Optional*. Chat invite link that was used by the user to send the join request""" diff --git a/docs/api/methods/approve_chat_join_request.rst b/docs/api/methods/approve_chat_join_request.rst new file mode 100644 index 00000000..8ac4643a --- /dev/null +++ b/docs/api/methods/approve_chat_join_request.rst @@ -0,0 +1,51 @@ +###################### +approveChatJoinRequest +###################### + +Returns: :obj:`bool` + +.. automodule:: aiogram.methods.approve_chat_join_request + :members: + :member-order: bysource + :undoc-members: True + + +Usage +===== + +As bot method +------------- + +.. code-block:: + + result: bool = await bot.approve_chat_join_request(...) + + +Method as object +---------------- + +Imports: + +- :code:`from aiogram.methods.approve_chat_join_request import ApproveChatJoinRequest` +- alias: :code:`from aiogram.methods import ApproveChatJoinRequest` + +In handlers with current bot +---------------------------- + +.. code-block:: python + + result: bool = await ApproveChatJoinRequest(...) + +With specific bot +~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + result: bool = await bot(ApproveChatJoinRequest(...)) + +As reply into Webhook in handler +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + return ApproveChatJoinRequest(...) diff --git a/docs/api/methods/decline_chat_join_request.rst b/docs/api/methods/decline_chat_join_request.rst new file mode 100644 index 00000000..f367ec36 --- /dev/null +++ b/docs/api/methods/decline_chat_join_request.rst @@ -0,0 +1,51 @@ +###################### +declineChatJoinRequest +###################### + +Returns: :obj:`bool` + +.. automodule:: aiogram.methods.decline_chat_join_request + :members: + :member-order: bysource + :undoc-members: True + + +Usage +===== + +As bot method +------------- + +.. code-block:: + + result: bool = await bot.decline_chat_join_request(...) + + +Method as object +---------------- + +Imports: + +- :code:`from aiogram.methods.decline_chat_join_request import DeclineChatJoinRequest` +- alias: :code:`from aiogram.methods import DeclineChatJoinRequest` + +In handlers with current bot +---------------------------- + +.. code-block:: python + + result: bool = await DeclineChatJoinRequest(...) + +With specific bot +~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + result: bool = await bot(DeclineChatJoinRequest(...)) + +As reply into Webhook in handler +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + return DeclineChatJoinRequest(...) diff --git a/docs/api/types/chat_join_request.rst b/docs/api/types/chat_join_request.rst new file mode 100644 index 00000000..236a472a --- /dev/null +++ b/docs/api/types/chat_join_request.rst @@ -0,0 +1,9 @@ +############### +ChatJoinRequest +############### + + +.. automodule:: aiogram.types.chat_join_request + :members: + :member-order: bysource + :undoc-members: True