From 44221872eb52e81869966c9a904013986e30e325 Mon Sep 17 00:00:00 2001 From: Oleg A Date: Sun, 5 Apr 2020 16:07:01 +0300 Subject: [PATCH] #289 added Dice type and ContentType --- aiogram/types/__init__.py | 1 + aiogram/types/dice.py | 13 +++++++++++++ aiogram/types/message.py | 14 ++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 aiogram/types/dice.py diff --git a/aiogram/types/__init__.py b/aiogram/types/__init__.py index 35461bb9..7d201ede 100644 --- a/aiogram/types/__init__.py +++ b/aiogram/types/__init__.py @@ -11,6 +11,7 @@ from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto from .chosen_inline_result import ChosenInlineResult from .contact import Contact +from .dice import Dice from .document import Document from .encrypted_credentials import EncryptedCredentials from .encrypted_passport_element import EncryptedPassportElement diff --git a/aiogram/types/dice.py b/aiogram/types/dice.py new file mode 100644 index 00000000..9d0e22d0 --- /dev/null +++ b/aiogram/types/dice.py @@ -0,0 +1,13 @@ +from . import base, fields + + +class Dice(base.TelegramObject): + """ + This object represents a dice with random value from 1 to 6. + (Yes, we're aware of the “proper” singular of die. + But it's awkward, and we decided to help it change. One dice at a time!) + + https://core.telegram.org/bots/api#dice + """ + + value: base.Integer = fields.Field() diff --git a/aiogram/types/message.py b/aiogram/types/message.py index badf1d51..d50eaf28 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -10,6 +10,7 @@ from .animation import Animation from .audio import Audio from .chat import Chat, ChatType from .contact import Contact +from .dice import Dice from .document import Document from .force_reply import ForceReply from .game import Game @@ -70,6 +71,8 @@ class Message(base.TelegramObject): contact: Contact = fields.Field(base=Contact) location: Location = fields.Field(base=Location) venue: Venue = fields.Field(base=Venue) + poll: Poll = fields.Field(base=Poll) + dice: Dice = fields.Field(base=Dice) new_chat_members: typing.List[User] = fields.ListField(base=User) left_chat_member: User = fields.Field(base=User) new_chat_title: base.String = fields.Field() @@ -85,7 +88,6 @@ class Message(base.TelegramObject): successful_payment: SuccessfulPayment = fields.Field(base=SuccessfulPayment) connected_website: base.String = fields.Field() passport_data: PassportData = fields.Field(base=PassportData) - poll: Poll = fields.Field(base=Poll) reply_markup: InlineKeyboardMarkup = fields.Field(base=InlineKeyboardMarkup) @property @@ -117,6 +119,10 @@ class Message(base.TelegramObject): return ContentType.VENUE if self.location: return ContentType.LOCATION + if self.poll: + return ContentType.POLL + if self.dice: + return ContentType.DICE if self.new_chat_members: return ContentType.NEW_CHAT_MEMBERS if self.left_chat_member: @@ -143,8 +149,7 @@ class Message(base.TelegramObject): return ContentType.GROUP_CHAT_CREATED if self.passport_data: return ContentType.PASSPORT_DATA - if self.poll: - return ContentType.POLL + return ContentType.UNKNOWN @@ -1685,6 +1690,8 @@ class ContentType(helper.Helper): CONTACT = helper.Item() # contact LOCATION = helper.Item() # location VENUE = helper.Item() # venue + POLL = helper.Item() # poll + DICE = helper.Item() # dice NEW_CHAT_MEMBERS = helper.Item() # new_chat_member LEFT_CHAT_MEMBER = helper.Item() # left_chat_member INVOICE = helper.Item() # invoice @@ -1698,7 +1705,6 @@ class ContentType(helper.Helper): DELETE_CHAT_PHOTO = helper.Item() # delete_chat_photo GROUP_CHAT_CREATED = helper.Item() # group_chat_created PASSPORT_DATA = helper.Item() # passport_data - POLL = helper.Item() UNKNOWN = helper.Item() # unknown ANY = helper.Item() # any