Add class helper ChatAction (#803)

* Add class helper ChatAction

* Change using helper to using enum.Enum

* Add test for class ChatAction

* Use black formatting

* Add pull request description to CHANGES

* Add test coverage

* Use AutoName class for enum values

* Move `AutoName` to separate file

* Move inheritance from `str`

* Fix failing mypy

* Delete old actions

Co-authored-by: Evgen Fil <evgfilim1@yandex.ru>
This commit is contained in:
ShiroNoHaga 2022-07-09 23:47:11 +03:00 committed by GitHub
parent bc5b26de5f
commit 851f7a2a37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 0 deletions

View file

@ -13,6 +13,7 @@ from .bot_command_scope_default import BotCommandScopeDefault
from .callback_game import CallbackGame
from .callback_query import CallbackQuery
from .chat import Chat
from .chat_action import ChatAction
from .chat_administrator_rights import ChatAdministratorRights
from .chat_invite_link import ChatInviteLink
from .chat_join_request import ChatJoinRequest
@ -275,6 +276,7 @@ __all__ = (
"Game",
"CallbackGame",
"GameHighScore",
"ChatAction",
)
# Load typing forward refs for every TelegramObject

View file

@ -0,0 +1,33 @@
import enum
from ..utils.enum import AutoName
class ChatAction(AutoName):
"""
This object represents bot actions.
Choose one, depending on what the user is about to receive:
typing for text messages,
upload_photo for photos,
record_video or upload_video for videos,
record_voice or upload_voice for voice notes,
upload_document for general files,
choose_sticker for stickers,
find_location for location data,
record_video_note or upload_video_note for video notes.
Source: https://core.telegram.org/bots/api#sendchataction
"""
TYPING = enum.auto()
UPLOAD_PHOTO = enum.auto()
RECORD_VIDEO = enum.auto()
UPLOAD_VIDEO = enum.auto()
RECORD_VOICE = enum.auto()
UPLOAD_VOICE = enum.auto()
UPLOAD_DOCUMENT = enum.auto()
CHOOSE_STICKER = enum.auto()
FIND_LOCATION = enum.auto()
RECORD_VIDEO_NOTE = enum.auto()
UPLOAD_VIDEO_NOTE = enum.auto()

8
aiogram/utils/enum.py Normal file
View file

@ -0,0 +1,8 @@
import enum
from typing import Any, List
class AutoName(str, enum.Enum):
@staticmethod
def _generate_next_value_(name: str, start: int, count: int, last_values: List[Any]) -> str:
return name.lower()