mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-13 02:19:54 +00:00
Update to Bot API 3.2. Teach your bot to handle stickers and sticker sets.
This commit is contained in:
parent
1413baf4b8
commit
146e876099
7 changed files with 187 additions and 34 deletions
|
|
@ -24,6 +24,7 @@ from .inline_query_result import InlineQueryResult, InlineQueryResultArticle, In
|
|||
from .invoice import Invoice
|
||||
from .labeled_price import LabeledPrice
|
||||
from .location import Location
|
||||
from .mask_position import MaskPosition
|
||||
from .message import Message, ContentType, ParseMode
|
||||
from .message_entity import MessageEntity
|
||||
from .order_info import OrderInfo
|
||||
|
|
@ -34,6 +35,7 @@ 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 Update
|
||||
from .user import User
|
||||
|
|
@ -99,6 +101,7 @@ __all__ = [
|
|||
'KeyboardButton',
|
||||
'LabeledPrice',
|
||||
'Location',
|
||||
'MaskPosition'
|
||||
'Message',
|
||||
'MessageEntity',
|
||||
'OrderInfo',
|
||||
|
|
@ -111,6 +114,7 @@ __all__ = [
|
|||
'ShippingOption',
|
||||
'ShippingQuery',
|
||||
'Sticker',
|
||||
'StickerSet'
|
||||
'SuccessfulPayment',
|
||||
'Update',
|
||||
'User',
|
||||
|
|
|
|||
15
aiogram/types/mask_position.py
Normal file
15
aiogram/types/mask_position.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from .base import Serializable
|
||||
|
||||
|
||||
class MaskPosition(Serializable):
|
||||
"""
|
||||
This object describes the position on faces where a mask should be placed by default.
|
||||
|
||||
https://core.telegram.org/bots/api#maskposition
|
||||
"""
|
||||
|
||||
def __init__(self, point, x_shift, y_shift, zoom):
|
||||
self.point: str = point
|
||||
self.x_shift: float = x_shift
|
||||
self.y_shift: float = y_shift
|
||||
self.zoom: float = zoom
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
from .base import Deserializable
|
||||
from .photo_size import PhotoSize
|
||||
from .mask_position import MaskPosition
|
||||
|
||||
|
||||
class Sticker(Deserializable):
|
||||
|
|
@ -8,12 +9,15 @@ class Sticker(Deserializable):
|
|||
|
||||
https://core.telegram.org/bots/api#sticker
|
||||
"""
|
||||
def __init__(self, file_id, width, height, thumb, emoji, file_size):
|
||||
|
||||
def __init__(self, file_id, width, height, thumb, emoji, set_name, mask_position, file_size):
|
||||
self.file_id: str = file_id
|
||||
self.width: int = width
|
||||
self.height: int = height
|
||||
self.thumb: PhotoSize = thumb
|
||||
self.emoji: str = emoji
|
||||
self.set_name: str = set_name
|
||||
self.mask_position: MaskPosition = mask_position
|
||||
self.file_size: int = file_size
|
||||
|
||||
@classmethod
|
||||
|
|
@ -25,6 +29,8 @@ class Sticker(Deserializable):
|
|||
height = raw_data.get('height')
|
||||
thumb = PhotoSize.deserialize(raw_data.get('thumb'))
|
||||
emoji = raw_data.get('emoji')
|
||||
set_name = raw_data.get('set_name')
|
||||
mask_position = MaskPosition.deserialize(raw_data.get('mask_position'))
|
||||
file_size = raw_data.get('file_size')
|
||||
|
||||
return Sticker(file_id, width, height, thumb, emoji, file_size)
|
||||
return Sticker(file_id, width, height, thumb, emoji, set_name, mask_position, file_size)
|
||||
|
|
|
|||
27
aiogram/types/sticker_set.py
Normal file
27
aiogram/types/sticker_set.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from .base import Deserializable
|
||||
from .sticker import Sticker
|
||||
|
||||
|
||||
class StickerSet(Deserializable):
|
||||
"""
|
||||
This object represents a sticker set.
|
||||
|
||||
https://core.telegram.org/bots/api#stickerset
|
||||
"""
|
||||
|
||||
def __init__(self, name, title, is_mask, stickers):
|
||||
self.name: str = name
|
||||
self.title: str = title
|
||||
self.is_mask: bool = is_mask
|
||||
self.stickers: [Sticker] = stickers
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
raw_data = cls.check_json(raw_data)
|
||||
|
||||
name = raw_data.get('name')
|
||||
title = raw_data.get('title')
|
||||
is_mask = raw_data.get('is_mask')
|
||||
stickers = Sticker.deserialize(raw_data.get('stickers'))
|
||||
|
||||
return StickerSet(name, title, is_mask, stickers)
|
||||
Loading…
Add table
Add a link
Reference in a new issue