Added enums

This commit is contained in:
Alex Root Junior 2022-11-20 02:55:51 +02:00
parent cdab2301c6
commit 9cacea4b2b
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
8 changed files with 132 additions and 0 deletions

View file

@ -128,6 +128,8 @@ class AiohttpSession(BaseSession):
def build_form_data(self, request: Request) -> FormData:
form = FormData(quote_fields=False)
for key, value in request.data.items():
if request.method == "createForumTopic":
print(key, self.prepare_value(value))
if value is None or value is UNSET:
continue
form.add_field(key, self.prepare_value(value))

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import abc
import datetime
import json
from enum import Enum
from http import HTTPStatus
from types import TracebackType
from typing import TYPE_CHECKING, Any, AsyncGenerator, Callable, Final, Optional, Type, Union, cast
@ -162,6 +163,8 @@ class BaseSession(abc.ABC):
return str(round((now + value).timestamp()))
if isinstance(value, datetime.datetime):
return str(round(value.timestamp()))
if isinstance(value, Enum):
return self.prepare_value(value.value)
else:
return str(value)

13
aiogram/enums/__init__.py Normal file
View file

@ -0,0 +1,13 @@
from .chat_type import ChatType
from .content_type import ContentType
from .dice_emoji import DiceEmoji
from .topic_icon_color import TopicIconColor
from .update_type import UpdateType
__all__ = (
"ChatType",
"DiceEmoji",
"TopicIconColor",
"UpdateType",
"ContentType",
)

View file

@ -0,0 +1,12 @@
from enum import Enum
class ChatType(str, Enum):
"""
Type of chat
"""
PRIVATE = "private"
GROUP = "group"
SUPERGROUP = "supergroup"
CHANNEL = "channel"

View file

@ -0,0 +1,50 @@
from enum import Enum
class ContentType(str, Enum):
"""
Message content type
"""
UNKNOWN = "unknown"
ANY = "any"
TEXT = "text"
ANIMATION = "animation"
AUDIO = "audio"
DOCUMENT = "document"
PHOTO = "photo"
STICKER = "sticker"
VIDEO = "video"
VIDEO_NOTE = "video_note"
VOICE = "voice"
CONTACT = "contact"
DICE = "dice"
GAME = "game"
POLL = "poll"
VENUE = "venue"
LOCATION = "location"
NEW_CHAT_MEMBERS = "new_chat_members"
LEFT_CHAT_MEMBER = "left_chat_member"
NEW_CHAT_TITLE = "new_chat_title"
NEW_CHAT_PHOTO = "new_chat_photo"
DELETE_CHAT_PHOTO = "delete_chat_photo"
GROUP_CHAT_CREATED = "group_chat_created"
SUPERGROUP_CHAT_CREATED = "supergroup_chat_created"
CHANNEL_CHAT_CREATED = "channel_chat_created"
MESSAGE_AUTO_DELETE_TIMER_CHANGED = "message_auto_delete_timer_changed"
MIGRATE_TO_CHAT_ID = "migrate_to_chat_id"
MIGRATE_FROM_CHAT_ID = "migrate_from_chat_id"
PINNED_MESSAGE = "pinned_message"
INVOICE = "invoice"
SUCCESSFUL_PAYMENT = "successful_payment"
CONNECTED_WEBSITE = "connected_website"
PASSPORT_DATA = "passport_data"
PROXIMITY_ALERT_TRIGGERED = "proximity_alert_triggered"
FORUM_TOPIC_CREATED = "forum_topic_created"
FORUM_TOPIC_CLOSED = "forum_topic_closed"
FORUM_TOPIC_REOPENED = "forum_topic_reopened"
VIDEO_CHAT_SCHEDULED = "video_chat_scheduled"
VIDEO_CHAT_STARTED = "video_chat_started"
VIDEO_CHAT_ENDED = "video_chat_ended"
VIDEO_CHAT_PARTICIPANTS_INVITED = "video_chat_participants_invited"
WEB_APP_DATA = "web_app_data"

View file

@ -0,0 +1,14 @@
from enum import Enum
class DiceEmoji(str, Enum):
"""
Emoji on which the dice throw animation is based
"""
DICE = "🎲"
DART = "🎯"
BASKETBALL = "🏀"
FOOTBALL = ""
SLOT_MACHINE = "🎰"
BOWLING = "🎳"

View file

@ -0,0 +1,16 @@
from enum import Enum
class TopicIconColor(int, Enum):
"""
Color of the topic icon in RGB format.
Source: https://github.com/telegramdesktop/tdesktop/blob/991fe491c5ae62705d77aa8fdd44a79caf639c45/Telegram/SourceFiles/data/data_forum_topic.cpp#L51-L56
"""
BLUE = 0x6FB9F0
YELLOW = 0xFFD67E
VIOLET = 0xCB86DB
GREEN = 0x8EEE98
ROSE = 0xFF93B2
RED = 0xFB6F5F

View file

@ -0,0 +1,22 @@
from enum import Enum
class UpdateType(str, Enum):
"""
Known update types
"""
MESSAGE = "message"
EDITED_MESSAGE = "edited_message"
CHANNEL_POST = "channel_post"
EDITED_CHANNEL_POST = "edited_channel_post"
INLINE_QUERY = "inline_query"
CHOSEN_INLINE_RESULT = "chosen_inline_result"
CALLBACK_QUERY = "callback_query"
SHIPPING_QUERY = "shipping_query"
PRE_CHECKOUT_QUERY = "pre_checkout_query"
POLL = "poll"
POLL_ANSWER = "poll_answer"
MY_CHAT_MEMBER = "my_chat_member"
CHAT_MEMBER = "chat_member"
CHAT_JOIN_REQUEST = "chat_join_request"