Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 3 more requests #412

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/aiogram_dialog/widgets/kbd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"ScrollingGroup",
"RequestContact",
"RequestLocation",
"RequestChat",
"RequestUser",
"RequestUsers",
"Checkbox",
"ManagedCheckbox",
"Select",
Expand Down Expand Up @@ -62,7 +65,7 @@
PrevPage,
SwitchPage,
)
from .request import RequestContact, RequestLocation
from .request import RequestContact, RequestLocation, RequestChat, RequestUser, RequestUsers
from .scrolling_group import ScrollingGroup
from .select import (
ManagedMultiselect,
Expand Down
110 changes: 97 additions & 13 deletions src/aiogram_dialog/widgets/kbd/request.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
from typing import Callable, Dict, Union

from aiogram.types import KeyboardButton
from aiogram.types import (
KeyboardButton,
KeyboardButtonRequestChat,
KeyboardButtonRequestUser,
KeyboardButtonRequestUsers,
)

from aiogram_dialog.api.internal import RawKeyboard
from aiogram_dialog.api.protocols import DialogManager
from aiogram_dialog.widgets.text import Text

from .base import Keyboard


class RequestContact(Keyboard):
def __init__(
self,
text: Text,
when: Union[str, Callable, None] = None,
self,
text: Text,
when: Union[str, Callable, None] = None,
):
super().__init__(when=when)
self.text = text

async def _render_keyboard(
self,
data: Dict,
manager: DialogManager,
self,
data: Dict,
manager: DialogManager,
) -> RawKeyboard:
return [
[
Expand All @@ -34,17 +40,17 @@ async def _render_keyboard(

class RequestLocation(Keyboard):
def __init__(
self,
text: Text,
when: Union[str, Callable, None] = None,
self,
text: Text,
when: Union[str, Callable, None] = None,
):
super().__init__(when=when)
self.text = text

async def _render_keyboard(
self,
data: Dict,
manager: DialogManager,
self,
data: Dict,
manager: DialogManager,
) -> RawKeyboard:
return [
[
Expand All @@ -54,3 +60,81 @@ async def _render_keyboard(
),
],
]


class RequestChat(Keyboard):
def __init__(
self,
text: Text,
RequestButton: KeyboardButtonRequestChat,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pep8?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly. Ruff

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix naming according to pep8

when: Union[str, Callable, None] = None,
):
super().__init__(when=when)
self.text = text
self.RequestButton = RequestButton

async def _render_keyboard(
self,
data: Dict,
manager: DialogManager,
) -> RawKeyboard:
return [
[
KeyboardButton(
text=await self.text.render_text(data, manager),
request_chat=self.RequestButton,
),
],
]


class RequestUser(Keyboard):
def __init__(
self,
text: Text,
RequestButton: KeyboardButtonRequestUser,
when: Union[str, Callable, None] = None,
):
super().__init__(when=when)
self.text = text
self.RequestButton = RequestButton

async def _render_keyboard(
self,
data: Dict,
manager: DialogManager,
) -> RawKeyboard:
return [
[
KeyboardButton(
text=await self.text.render_text(data, manager),
request_user=self.RequestButton,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure it is good idea to have static request_id`

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? If I'm not mistaking, there're no static request_id. We provide RequestButton above which was set up earlier by developer.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean once you declare widget in dialog, it will have same request id here.

),
],
]


class RequestUsers(Keyboard):
def __init__(
self,
text: Text,
RequestButton: KeyboardButtonRequestUsers,
when: Union[str, Callable, None] = None,
):
super().__init__(when=when)
self.text = text
self.RequestButton = RequestButton

async def _render_keyboard(
self,
data: Dict,
manager: DialogManager,
) -> RawKeyboard:
return [
[
KeyboardButton(
text=await self.text.render_text(data, manager),
request_users=self.RequestButton,
),
],
]