-
Notifications
You must be signed in to change notification settings - Fork 103
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 [ | ||
[ | ||
|
@@ -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 [ | ||
[ | ||
|
@@ -54,3 +60,81 @@ async def _render_keyboard( | |
), | ||
], | ||
] | ||
|
||
|
||
class RequestChat(Keyboard): | ||
def __init__( | ||
self, | ||
text: Text, | ||
RequestButton: KeyboardButtonRequestChat, | ||
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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` There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
), | ||
], | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pep8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly. Ruff
There was a problem hiding this comment.
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