mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-14 19:00:23 +00:00
Check all types.
This commit is contained in:
parent
17871155ee
commit
0586c33b1d
16 changed files with 239 additions and 40 deletions
|
|
@ -1,9 +1,135 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
from .animation import Animation
|
||||
from .audio import Audio
|
||||
from .callback_game import CallbackGame
|
||||
from .callback_query import CallbackQuery
|
||||
from .chat import Chat, ChatActions, ChatType
|
||||
from .chat_member import ChatMember, ChatMemberStatus
|
||||
from .chat_photo import ChatPhoto
|
||||
from .chosen_inline_result import ChosenInlineResult
|
||||
from .contact import Contact
|
||||
from .document import Document
|
||||
from .file import File
|
||||
from .force_reply import ForceReply
|
||||
from .game import Game
|
||||
from .game_high_score import GameHighScore
|
||||
from .inline_keyboard import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from .inline_query import InlineQuery
|
||||
from .inline_query_result import InlineQueryResult, InlineQueryResultArticle, InlineQueryResultAudio, \
|
||||
InlineQueryResultCachedAudio, InlineQueryResultCachedDocument, InlineQueryResultCachedGif, \
|
||||
InlineQueryResultCachedMpeg4Gif, InlineQueryResultCachedPhoto, InlineQueryResultCachedSticker, \
|
||||
InlineQueryResultCachedVideo, InlineQueryResultCachedVoice, InlineQueryResultContact, InlineQueryResultDocument, \
|
||||
InlineQueryResultGame, InlineQueryResultGif, InlineQueryResultLocation, InlineQueryResultMpeg4Gif, \
|
||||
InlineQueryResultPhoto, InlineQueryResultVenue, InlineQueryResultVideo, InlineQueryResultVoice
|
||||
from .input_file import InputFile
|
||||
from .input_message_content import InputContactMessageContent, InputLocationMessageContent, InputMessageContent, \
|
||||
InputTextMessageContent, InputVenueMessageContent
|
||||
from .invoice import Invoice
|
||||
from .labeled_price import LabeledPrice
|
||||
from .location import Location
|
||||
from .mask_position import MaskPosition
|
||||
from .message import ContentType, Message, ParseMode
|
||||
from .message_entity import MessageEntity, MessageEntityType
|
||||
from .order_info import OrderInfo
|
||||
from .photo_size import PhotoSize
|
||||
from .pre_checkout_query import PreCheckoutQuery
|
||||
from .reply_keyboard import KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove
|
||||
from .response_parameters import ResponseParameters
|
||||
from .shipping_address import ShippingAddress
|
||||
from .shipping_option import ShippingOption
|
||||
from .shipping_query import ShippingQuery
|
||||
from .sticker import Sticker
|
||||
from .sticker_set import StickerSet
|
||||
from .successful_payment import SuccessfulPayment
|
||||
from .update import AllowedUpdates, Update
|
||||
from .user import User
|
||||
from .user_profile_photos import UserProfilePhotos
|
||||
from .venue import Venue
|
||||
from .video import Video
|
||||
from .video_note import VideoNote
|
||||
from .voice import Voice
|
||||
from .webhook_info import WebhookInfo
|
||||
|
||||
__all__ = (
|
||||
'base', 'fields',
|
||||
'InputFile', 'String', 'Integer', 'Float', 'Boolean',
|
||||
'Animation'
|
||||
'AllowedUpdates',
|
||||
'Animation',
|
||||
'Audio',
|
||||
'CallbackGame',
|
||||
'CallbackQuery',
|
||||
'Chat',
|
||||
'ChatActions',
|
||||
'ChatMember',
|
||||
'ChatMemberStatus',
|
||||
'ChatPhoto',
|
||||
'ChatType',
|
||||
'ChosenInlineResult',
|
||||
'Contact',
|
||||
'ContentType',
|
||||
'Document',
|
||||
'File',
|
||||
'ForceReply',
|
||||
'Game',
|
||||
'GameHighScore',
|
||||
'InlineKeyboardButton',
|
||||
'InlineKeyboardMarkup',
|
||||
'InlineQuery',
|
||||
'InlineQueryResult',
|
||||
'InlineQueryResultArticle',
|
||||
'InlineQueryResultAudio',
|
||||
'InlineQueryResultCachedAudio',
|
||||
'InlineQueryResultCachedDocument',
|
||||
'InlineQueryResultCachedGif',
|
||||
'InlineQueryResultCachedMpeg4Gif',
|
||||
'InlineQueryResultCachedPhoto',
|
||||
'InlineQueryResultCachedSticker',
|
||||
'InlineQueryResultCachedVideo',
|
||||
'InlineQueryResultCachedVoice',
|
||||
'InlineQueryResultContact',
|
||||
'InlineQueryResultDocument',
|
||||
'InlineQueryResultGame',
|
||||
'InlineQueryResultGif',
|
||||
'InlineQueryResultLocation',
|
||||
'InlineQueryResultMpeg4Gif',
|
||||
'InlineQueryResultPhoto',
|
||||
'InlineQueryResultVenue',
|
||||
'InlineQueryResultVideo',
|
||||
'InlineQueryResultVoice',
|
||||
'InputContactMessageContent',
|
||||
'InputFile',
|
||||
'InputLocationMessageContent',
|
||||
'InputMessageContent',
|
||||
'InputTextMessageContent',
|
||||
'InputVenueMessageContent',
|
||||
'Invoice',
|
||||
'KeyboardButton',
|
||||
'LabeledPrice',
|
||||
'Location',
|
||||
'MaskPosition',
|
||||
'Message',
|
||||
'MessageEntity',
|
||||
'MessageEntityType',
|
||||
'OrderInfo',
|
||||
'ParseMode',
|
||||
'PhotoSize',
|
||||
'PreCheckoutQuery',
|
||||
'ReplyKeyboardMarkup',
|
||||
'ReplyKeyboardRemove',
|
||||
'ResponseParameters',
|
||||
'ShippingAddress',
|
||||
'ShippingOption',
|
||||
'ShippingQuery',
|
||||
'Sticker',
|
||||
'StickerSet',
|
||||
'SuccessfulPayment',
|
||||
'Update',
|
||||
'User',
|
||||
'UserProfilePhotos',
|
||||
'Venue',
|
||||
'Video',
|
||||
'VideoNote',
|
||||
'Voice',
|
||||
'WebhookInfo',
|
||||
'base',
|
||||
'fields'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
|
||||
|
||||
class ResponseParameters(base.TelegramObject):
|
||||
|
|
@ -11,4 +10,3 @@ class ResponseParameters(base.TelegramObject):
|
|||
"""
|
||||
migrate_to_chat_id: base.Integer = fields.Field()
|
||||
retry_after: base.Integer = fields.Field()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
|
||||
|
||||
class ShippingAddress(base.TelegramObject):
|
||||
|
|
@ -15,4 +14,3 @@ class ShippingAddress(base.TelegramObject):
|
|||
street_line1: base.String = fields.Field()
|
||||
street_line2: base.String = fields.Field()
|
||||
post_code: base.String = fields.Field()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import typing
|
||||
|
||||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from .labeled_price import LabeledPrice
|
||||
|
||||
|
||||
|
|
@ -14,3 +15,18 @@ class ShippingOption(base.TelegramObject):
|
|||
title: base.String = fields.Field()
|
||||
prices: typing.List[LabeledPrice] = fields.ListField(base=LabeledPrice)
|
||||
|
||||
def __init__(self, id: base.String, title: base.String, prices: typing.List[LabeledPrice] = None):
|
||||
if prices is None:
|
||||
prices = []
|
||||
|
||||
super(ShippingOption, self).__init__(id=id, title=title, prices=prices)
|
||||
|
||||
def add(self, price: LabeledPrice):
|
||||
"""
|
||||
Add price
|
||||
|
||||
:param price:
|
||||
:return:
|
||||
"""
|
||||
self.prices.append(price)
|
||||
return self
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from .user import User
|
||||
from .shipping_address import ShippingAddress
|
||||
from .user import User
|
||||
|
||||
|
||||
class ShippingQuery(base.TelegramObject):
|
||||
|
|
@ -15,4 +14,3 @@ class ShippingQuery(base.TelegramObject):
|
|||
from_user: User = fields.Field(alias='from', base=User)
|
||||
invoice_payload: base.String = fields.Field()
|
||||
shipping_address: ShippingAddress = fields.Field(base=ShippingAddress)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from .photo_size import PhotoSize
|
||||
from .mask_position import MaskPosition
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
class Sticker(base.TelegramObject):
|
||||
|
|
@ -19,4 +18,3 @@ class Sticker(base.TelegramObject):
|
|||
set_name: base.String = fields.Field()
|
||||
mask_position: MaskPosition = fields.Field(base=MaskPosition)
|
||||
file_size: base.Integer = fields.Field()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import typing
|
||||
|
||||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from .sticker import Sticker
|
||||
|
||||
|
||||
|
|
@ -14,4 +15,3 @@ class StickerSet(base.TelegramObject):
|
|||
title: base.String = fields.Field()
|
||||
contains_masks: base.Boolean = fields.Field()
|
||||
stickers: typing.List[Sticker] = fields.ListField(base=Sticker)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from .order_info import OrderInfo
|
||||
|
||||
|
||||
|
|
@ -17,4 +16,3 @@ class SuccessfulPayment(base.TelegramObject):
|
|||
order_info: OrderInfo = fields.Field(base=OrderInfo)
|
||||
telegram_payment_charge_id: base.String = fields.Field()
|
||||
provider_payment_charge_id: base.String = fields.Field()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from .message import Message
|
||||
from .inline_query import InlineQuery
|
||||
from .chosen_inline_result import ChosenInlineResult
|
||||
from .callback_query import CallbackQuery
|
||||
from .shipping_query import ShippingQuery
|
||||
from .chosen_inline_result import ChosenInlineResult
|
||||
from .inline_query import InlineQuery
|
||||
from .message import Message
|
||||
from .pre_checkout_query import PreCheckoutQuery
|
||||
from .shipping_query import ShippingQuery
|
||||
from ..utils import helper
|
||||
|
||||
|
||||
class Update(base.TelegramObject):
|
||||
|
|
@ -27,3 +27,24 @@ class Update(base.TelegramObject):
|
|||
shipping_query: ShippingQuery = fields.Field(base=ShippingQuery)
|
||||
pre_checkout_query: PreCheckoutQuery = fields.Field(base=PreCheckoutQuery)
|
||||
|
||||
|
||||
class AllowedUpdates(helper.Helper):
|
||||
"""
|
||||
Helper for allowed_updates parameter in getUpdates and setWebhook methods.
|
||||
|
||||
You can use &, + or | operators for make combination of allowed updates.
|
||||
|
||||
Example:
|
||||
>>> bot.get_updates(allowed_updates=AllowedUpdates.MESSAGE + AllowedUpdates.EDITED_MESSAGE)
|
||||
"""
|
||||
mode = helper.HelperMode.snake_case
|
||||
|
||||
MESSAGE = helper.ListItem() # message
|
||||
EDITED_MESSAGE = helper.ListItem() # edited_message
|
||||
CHANNEL_POST = helper.ListItem() # channel_post
|
||||
EDITED_CHANNEL_POST = helper.ListItem() # edited_channel_post
|
||||
INLINE_QUERY = helper.ListItem() # inline_query
|
||||
CHOSEN_INLINE_QUERY = helper.ListItem() # chosen_inline_result
|
||||
CALLBACK_QUERY = helper.ListItem() # callback_query
|
||||
SHIPPING_QUERY = helper.ListItem() # shipping_query
|
||||
PRE_CHECKOUT_QUERY = helper.ListItem() # pre_checkout_query
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from ..utils import markdown
|
||||
|
||||
try:
|
||||
import babel
|
||||
except ImportError:
|
||||
babel = None
|
||||
|
||||
|
||||
class User(base.TelegramObject):
|
||||
|
|
@ -16,3 +21,55 @@ class User(base.TelegramObject):
|
|||
username: base.String = fields.Field()
|
||||
language_code: base.String = fields.Field()
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
"""
|
||||
You can get full name of user.
|
||||
|
||||
:return: str
|
||||
"""
|
||||
full_name = self.first_name
|
||||
if self.last_name:
|
||||
full_name += ' ' + self.last_name
|
||||
return full_name
|
||||
|
||||
@property
|
||||
def mention(self):
|
||||
"""
|
||||
You can get mention to user (If user have username, otherwise return full name)
|
||||
|
||||
:return: str
|
||||
"""
|
||||
if self.username:
|
||||
return '@' + self.username
|
||||
return self.full_name
|
||||
|
||||
@property
|
||||
def locale(self) -> 'babel.core.Locale' or None:
|
||||
"""
|
||||
This property require `Babel <https://pypi.python.org/pypi/Babel>`_ module
|
||||
|
||||
:return: :class:`babel.core.Locale`
|
||||
:raise: ImportError: when babel is not installed.
|
||||
"""
|
||||
if not babel:
|
||||
raise ImportError('Babel is not installed!')
|
||||
if not self.language_code:
|
||||
return None
|
||||
if not hasattr(self, '_locale'):
|
||||
setattr(self, '_locale', babel.core.Locale.parse(self.language_code, sep='-'))
|
||||
return getattr(self, '_locale')
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return f"tg://user?id={self.id}"
|
||||
|
||||
def get_mention(self, name=None, as_html=False):
|
||||
if name is None:
|
||||
name = self.mention
|
||||
if as_html:
|
||||
return markdown.hlink(name, self.url)
|
||||
return markdown.link(name, self.url)
|
||||
|
||||
async def get_user_profile_photos(self, offset=None, limit=None):
|
||||
return await self.bot.get_user_profile_photos(self.id, offset, limit)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import typing
|
||||
|
||||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
|
|
@ -11,5 +12,4 @@ class UserProfilePhotos(base.TelegramObject):
|
|||
https://core.telegram.org/bots/api#userprofilephotos
|
||||
"""
|
||||
total_count: base.Integer = fields.Field()
|
||||
photos: typing.List[typing.List[PhotoSize]] = fields.ListField(base=PhotoSize)
|
||||
|
||||
photos: typing.List[typing.List[PhotoSize]] = fields.ListOfLists(base=PhotoSize)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from .location import Location
|
||||
|
||||
|
||||
|
|
@ -14,4 +13,3 @@ class Venue(base.TelegramObject):
|
|||
title: base.String = fields.Field()
|
||||
address: base.String = fields.Field()
|
||||
foursquare_id: base.String = fields.Field()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
|
|
@ -17,4 +16,3 @@ class Video(base.TelegramObject):
|
|||
thumb: PhotoSize = fields.Field(base=PhotoSize)
|
||||
mime_type: base.String = fields.Field()
|
||||
file_size: base.Integer = fields.Field()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
|
|
@ -15,4 +14,3 @@ class VideoNote(base.TelegramObject):
|
|||
duration: base.Integer = fields.Field()
|
||||
thumb: PhotoSize = fields.Field(base=PhotoSize)
|
||||
file_size: base.Integer = fields.Field()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
|
||||
|
||||
class Voice(base.TelegramObject):
|
||||
|
|
@ -13,4 +12,3 @@ class Voice(base.TelegramObject):
|
|||
duration: base.Integer = fields.Field()
|
||||
mime_type: base.String = fields.Field()
|
||||
file_size: base.Integer = fields.Field()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
import typing
|
||||
|
||||
from . import base
|
||||
from . import fields
|
||||
import typing
|
||||
|
||||
|
||||
class WebhookInfo(base.TelegramObject):
|
||||
"""
|
||||
Contains information about the current status of a webhook.
|
||||
All types used in the Bot API responses are represented as JSON-objects.
|
||||
It is safe to use 32-bit signed integers for storing all Integer fields unless otherwise noted.
|
||||
Optional fields may be not returned when irrelevant.
|
||||
|
||||
https://core.telegram.org/bots/api#webhookinfo
|
||||
"""
|
||||
|
|
@ -19,4 +17,3 @@ class WebhookInfo(base.TelegramObject):
|
|||
last_error_message: base.String = fields.Field()
|
||||
max_connections: base.Integer = fields.Field()
|
||||
allowed_updates: typing.List[base.String] = fields.ListField()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue