mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Make some objects mutable
This commit is contained in:
parent
c4961fd114
commit
eeb3b63b97
14 changed files with 36 additions and 29 deletions
|
|
@ -1,14 +1,21 @@
|
|||
import datetime
|
||||
|
||||
from pydantic import BaseModel, Extra
|
||||
|
||||
from aiogram.utils.mixins import ContextInstanceMixin
|
||||
from pydantic import BaseConfig, BaseModel, Extra
|
||||
|
||||
|
||||
class TelegramObject(ContextInstanceMixin, BaseModel):
|
||||
class Config(BaseConfig):
|
||||
class Config:
|
||||
use_enum_values = True
|
||||
orm_mode = True
|
||||
extra = Extra.allow
|
||||
validate_assignment = True
|
||||
allow_mutation = False
|
||||
allow_population_by_field_name = True
|
||||
json_encoders = {datetime.datetime: lambda dt: int(dt.timestamp())}
|
||||
|
||||
|
||||
class MutableTelegramObject(TelegramObject):
|
||||
class Config:
|
||||
allow_mutation = True
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ from __future__ import annotations
|
|||
|
||||
from typing import Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class ChatPermissions(TelegramObject):
|
||||
class ChatPermissions(MutableTelegramObject):
|
||||
"""
|
||||
Describes actions that a non-administrator user is allowed to take in a chat.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ from __future__ import annotations
|
|||
|
||||
from typing import Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class ForceReply(TelegramObject):
|
||||
class ForceReply(MutableTelegramObject):
|
||||
"""
|
||||
Upon receiving a message with this object, Telegram clients will display a reply interface to
|
||||
the user (act as if the user has selected the bot‘s message and tapped ’Reply'). This can be
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from .callback_game import CallbackGame
|
||||
from .login_url import LoginUrl
|
||||
|
||||
|
||||
class InlineKeyboardButton(TelegramObject):
|
||||
class InlineKeyboardButton(MutableTelegramObject):
|
||||
"""
|
||||
This object represents one button of an inline keyboard. You must use exactly one of the
|
||||
optional fields.
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, List
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from .inline_keyboard_button import InlineKeyboardButton
|
||||
|
||||
|
||||
class InlineKeyboardMarkup(TelegramObject):
|
||||
class InlineKeyboardMarkup(MutableTelegramObject):
|
||||
"""
|
||||
This object represents an inline keyboard that appears right next to the message it belongs
|
||||
to.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class InlineQueryResult(TelegramObject):
|
||||
class InlineQueryResult(MutableTelegramObject):
|
||||
"""
|
||||
This object represents one result of an inline query. Telegram clients currently support
|
||||
results of the following 20 types:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class InputMedia(TelegramObject):
|
||||
class InputMedia(MutableTelegramObject):
|
||||
"""
|
||||
This object represents the content of a media message to be sent. It should be one of
|
||||
- InputMediaAnimation
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class InputMessageContent(TelegramObject):
|
||||
class InputMessageContent(MutableTelegramObject):
|
||||
"""
|
||||
This object represents the content of a message to be sent as a result of an inline query.
|
||||
Telegram clients currently support the following 4 types:
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from .keyboard_button_poll_type import KeyboardButtonPollType
|
||||
|
||||
|
||||
class KeyboardButton(TelegramObject):
|
||||
class KeyboardButton(MutableTelegramObject):
|
||||
"""
|
||||
This object represents one button of the reply keyboard. For simple text buttons String can be
|
||||
used instead of this object to specify text of the button. Optional fields request_contact,
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ from __future__ import annotations
|
|||
|
||||
from typing import Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class KeyboardButtonPollType(TelegramObject):
|
||||
class KeyboardButtonPollType(MutableTelegramObject):
|
||||
"""
|
||||
This object represents type of a poll, which is allowed to be created and sent when the
|
||||
corresponding button is pressed.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class LabeledPrice(TelegramObject):
|
||||
class LabeledPrice(MutableTelegramObject):
|
||||
"""
|
||||
This object represents a portion of the price for goods or services.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class PassportElementError(TelegramObject):
|
||||
class PassportElementError(MutableTelegramObject):
|
||||
"""
|
||||
This object represents an error in the Telegram Passport element which was submitted that
|
||||
should be resolved by the user. It should be one of:
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, List, Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from .keyboard_button import KeyboardButton
|
||||
|
||||
|
||||
class ReplyKeyboardMarkup(TelegramObject):
|
||||
class ReplyKeyboardMarkup(MutableTelegramObject):
|
||||
"""
|
||||
This object represents a custom keyboard with reply options (see Introduction to bots for
|
||||
details and examples).
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ from __future__ import annotations
|
|||
|
||||
from typing import Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class ReplyKeyboardRemove(TelegramObject):
|
||||
class ReplyKeyboardRemove(MutableTelegramObject):
|
||||
"""
|
||||
Upon receiving a message with this object, Telegram clients will remove the current custom
|
||||
keyboard and display the default letter-keyboard. By default, custom keyboards are displayed
|
||||
|
|
@ -15,7 +15,7 @@ class ReplyKeyboardRemove(TelegramObject):
|
|||
Source: https://core.telegram.org/bots/api#replykeyboardremove
|
||||
"""
|
||||
|
||||
remove_keyboard: bool
|
||||
remove_keyboard: bool = True
|
||||
"""Requests clients to remove the custom keyboard (user will not be able to summon this
|
||||
keyboard; if you want to hide the keyboard from sight but keep it accessible, use
|
||||
one_time_keyboard in ReplyKeyboardMarkup)"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue