mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +00:00
Remove old code. (2)
This commit is contained in:
parent
c7cf2e0c24
commit
00cc42c216
41 changed files with 0 additions and 2376 deletions
|
|
@ -1,28 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
class Animation(Deserializable):
|
||||
"""
|
||||
You can provide an animation for your game so that it looks stylish in chats.
|
||||
This object represents an animation file to be displayed in the message containing a game.
|
||||
|
||||
https://core.telegram.org/bots/api#animation
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, thumb, file_name, mime_type, file_size):
|
||||
self.file_id: str = file_id
|
||||
self.thumb: PhotoSize = thumb
|
||||
self.file_name: str = file_name
|
||||
self.mime_type: str = mime_type
|
||||
self.file_size: int = file_size
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
file_id = raw_data.get('file_id')
|
||||
thumb = PhotoSize.deserialize(raw_data.get('thumb'))
|
||||
file_name = raw_data.get('file_name')
|
||||
mime_type = raw_data.get('mime_type')
|
||||
file_size = raw_data.get('file_size')
|
||||
|
||||
return Animation(file_id, thumb, file_name, mime_type, file_size)
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class Audio(Deserializable):
|
||||
"""
|
||||
This object represents an audio file to be treated as music by the Telegram clients.
|
||||
|
||||
https://core.telegram.org/bots/api#audio
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, duration, performer, title, mime_type, file_size):
|
||||
self.file_id: str = file_id
|
||||
self.duration: int = duration
|
||||
self.performer: str = performer
|
||||
self.title: str = title
|
||||
self.mime_type: str = mime_type
|
||||
self.file_size: int = file_size
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
file_id = raw_data.get('file_id')
|
||||
duration = raw_data.get('duration')
|
||||
performer = raw_data.get('performer')
|
||||
title = raw_data.get('title')
|
||||
mime_type = raw_data.get('mime_type')
|
||||
file_size = raw_data.get('file_size')
|
||||
|
||||
return Audio(file_id, duration, performer, title, mime_type, file_size)
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .message import Message
|
||||
from .user import User
|
||||
|
||||
|
||||
class CallbackQuery(Deserializable):
|
||||
"""
|
||||
This object represents an incoming callback query from a callback button in an inline keyboard.
|
||||
|
||||
If the button that originated the query was attached to a message sent by the bot,
|
||||
the field message will be present.
|
||||
|
||||
If the button was attached to a message sent via the bot (in inline mode),
|
||||
the field inline_message_id will be present.
|
||||
|
||||
Exactly one of the fields data or game_short_name will be present.
|
||||
|
||||
https://core.telegram.org/bots/api#callbackquery
|
||||
"""
|
||||
|
||||
def __init__(self, id, from_user, message, inline_message_id, chat_instance, data, game_short_name):
|
||||
self.id: int = id
|
||||
self.from_user: User = from_user
|
||||
self.message: Message = message
|
||||
self.inline_message_id: int = inline_message_id
|
||||
self.chat_instance: str = chat_instance
|
||||
self.data: str = data
|
||||
self.game_short_name: str = game_short_name
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
id = raw_data.get('id')
|
||||
from_user = User.deserialize(raw_data.get('from'))
|
||||
message = Message.deserialize(raw_data.get('message'))
|
||||
inline_message_id = raw_data.get('inline_message_id')
|
||||
chat_instance = raw_data.get('chat_instance')
|
||||
data = raw_data.get('data')
|
||||
game_short_name = raw_data.get('game_short_name')
|
||||
|
||||
return CallbackQuery(id, from_user, message, inline_message_id, chat_instance, data, game_short_name)
|
||||
|
|
@ -1,162 +0,0 @@
|
|||
from aiogram.utils.markdown import hlink, link
|
||||
from .base import Deserializable
|
||||
from .chat_photo import ChatPhoto
|
||||
from ..utils.helper import Helper, HelperMode, Item
|
||||
|
||||
|
||||
class Chat(Deserializable):
|
||||
"""
|
||||
This object represents a chat.
|
||||
|
||||
https://core.telegram.org/bots/api#chat
|
||||
"""
|
||||
|
||||
def __init__(self, id, type, title, username, first_name, last_name, all_members_are_administrators, photo,
|
||||
description, invite_link, pinned_message):
|
||||
from .message import Message
|
||||
|
||||
self.id: int = id
|
||||
self.type: str = type
|
||||
self.title: str = title
|
||||
self.username: str = username
|
||||
self.first_name: str = first_name
|
||||
self.last_name: str = last_name
|
||||
self.all_members_are_administrators: bool = all_members_are_administrators
|
||||
self.photo: ChatPhoto = photo
|
||||
self.description: str = description
|
||||
self.invite_link: str = invite_link
|
||||
self.pinned_message: Message = pinned_message
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data) -> 'Chat':
|
||||
from .message import Message
|
||||
|
||||
id: int = raw_data.get('id')
|
||||
type: str = raw_data.get('type')
|
||||
title: str = raw_data.get('title')
|
||||
username: str = raw_data.get('username')
|
||||
first_name: str = raw_data.get('first_name')
|
||||
last_name: str = raw_data.get('last_name')
|
||||
all_members_are_administrators: bool = raw_data.get('all_members_are_administrators', False)
|
||||
photo = raw_data.get('photo')
|
||||
description = raw_data.get('description')
|
||||
invite_link = raw_data.get('invite_link')
|
||||
pinned_message: Message = Message.deserialize(raw_data.get('pinned_message'))
|
||||
|
||||
return Chat(id, type, title, username, first_name, last_name, all_members_are_administrators, photo,
|
||||
description, invite_link, pinned_message)
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
if self.type == ChatType.PRIVATE:
|
||||
full_name = self.first_name
|
||||
if self.last_name:
|
||||
full_name += ' ' + self.last_name
|
||||
return full_name
|
||||
return self.title
|
||||
|
||||
@property
|
||||
def mention(self):
|
||||
"""
|
||||
Get mention if dialog have username or full name if this is Private dialog otherwise None
|
||||
"""
|
||||
if self.username:
|
||||
return '@' + self.username
|
||||
if self.type == ChatType.PRIVATE:
|
||||
return self.full_name
|
||||
return None
|
||||
|
||||
@property
|
||||
def user_url(self):
|
||||
if self.type != ChatType.PRIVATE:
|
||||
raise TypeError('This property available only in private chats.')
|
||||
|
||||
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 hlink(name, self.user_url)
|
||||
return link(name, self.user_url)
|
||||
|
||||
async def set_photo(self, photo):
|
||||
return await self.bot.set_chat_photo(self.id, photo)
|
||||
|
||||
async def delete_photo(self):
|
||||
return await self.bot.delete_chat_photo(self.id)
|
||||
|
||||
async def set_title(self, title):
|
||||
return await self.bot.set_chat_title(self.id, title)
|
||||
|
||||
async def set_description(self, description):
|
||||
return await self.bot.delete_chat_description(self.id, description)
|
||||
|
||||
async def pin_message(self, message_id: int, disable_notification: bool = False):
|
||||
return await self.bot.pin_chat_message(self.id, message_id, disable_notification)
|
||||
|
||||
async def unpin_message(self):
|
||||
return await self.bot.unpin_chat_message(self.id)
|
||||
|
||||
async def leave(self):
|
||||
return await self.bot.leave_chat(self.id)
|
||||
|
||||
async def get_administrators(self):
|
||||
return await self.bot.get_chat_administrators(self.id)
|
||||
|
||||
async def get_members_count(self):
|
||||
return await self.bot.get_chat_members_count(self.id)
|
||||
|
||||
async def get_member(self, user_id):
|
||||
return await self.bot.get_chat_member(self.id, user_id)
|
||||
|
||||
async def do(self, action):
|
||||
return await self.bot.send_chat_action(self.id, action)
|
||||
|
||||
|
||||
class ChatType(Helper):
|
||||
"""
|
||||
List of chat types
|
||||
|
||||
:key: PRIVATE
|
||||
:key: GROUP
|
||||
:key: SUPER_GROUP
|
||||
:key: CHANNEL
|
||||
"""
|
||||
|
||||
mode = HelperMode.lowercase
|
||||
|
||||
PRIVATE = Item() # private
|
||||
GROUP = Item() # group
|
||||
SUPER_GROUP = Item() # supergroup
|
||||
CHANNEL = Item() # channel
|
||||
|
||||
|
||||
class ChatActions(Helper):
|
||||
"""
|
||||
List of chat actions
|
||||
|
||||
:key: TYPING
|
||||
:key: UPLOAD_PHOTO
|
||||
:key: RECORD_VIDEO
|
||||
:key: UPLOAD_VIDEO
|
||||
:key: RECORD_AUDIO
|
||||
:key: UPLOAD_AUDIO
|
||||
:key: UPLOAD_DOCUMENT
|
||||
:key: FIND_LOCATION
|
||||
:key: RECORD_VIDEO_NOTE
|
||||
:key: UPLOAD_VIDEO_NOTE
|
||||
"""
|
||||
|
||||
mode = HelperMode.snake_case
|
||||
|
||||
TYPING = Item() # typing
|
||||
UPLOAD_PHOTO = Item() # upload_photo
|
||||
RECORD_VIDEO = Item() # record_video
|
||||
UPLOAD_VIDEO = Item() # upload_video
|
||||
RECORD_AUDIO = Item() # record_audio
|
||||
UPLOAD_AUDIO = Item() # upload_audio
|
||||
UPLOAD_DOCUMENT = Item() # upload_document
|
||||
FIND_LOCATION = Item() # find_location
|
||||
RECORD_VIDEO_NOTE = Item() # record_video_note
|
||||
UPLOAD_VIDEO_NOTE = Item() # upload_video_note
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
import datetime
|
||||
|
||||
from .base import Deserializable
|
||||
from .user import User
|
||||
from ..utils.helper import Helper, Item
|
||||
|
||||
|
||||
class ChatMember(Deserializable):
|
||||
"""
|
||||
This object contains information about one member of the chat.
|
||||
|
||||
https://core.telegram.org/bots/api#chatmember
|
||||
"""
|
||||
|
||||
def __init__(self, user, status, until_date, can_be_edited, can_change_info, can_post_messages,
|
||||
can_edit_messages, can_delete_messages, can_invite_users, can_restrict_members,
|
||||
can_pin_messages, can_promote_members, can_send_messages, can_send_media_messages,
|
||||
can_send_other_messages, can_add_web_page_previews
|
||||
):
|
||||
self.user: User = user
|
||||
self.status: str = status
|
||||
|
||||
self.until_date: datetime.datetime = until_date
|
||||
self.can_be_edited: bool = can_be_edited
|
||||
self.can_change_info: bool = can_change_info
|
||||
self.can_post_messages: bool = can_post_messages
|
||||
self.can_edit_messages: bool = can_edit_messages
|
||||
self.can_delete_messages: bool = can_delete_messages
|
||||
self.can_invite_users: bool = can_invite_users
|
||||
self.can_restrict_members: bool = can_restrict_members
|
||||
self.can_pin_messages: bool = can_pin_messages
|
||||
self.can_promote_members: bool = can_promote_members
|
||||
self.can_send_messages: bool = can_send_messages
|
||||
self.can_send_media_messages: bool = can_send_media_messages
|
||||
self.can_send_other_messages: bool = can_send_other_messages
|
||||
self.can_add_web_page_previews: bool = can_add_web_page_previews
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
user = User.deserialize(raw_data.get('user'))
|
||||
status = raw_data.get('status')
|
||||
|
||||
until_date = cls._parse_date(raw_data.get('until_date'))
|
||||
can_be_edited = raw_data.get('can_be_edited')
|
||||
can_change_info = raw_data.get('can_change_info')
|
||||
can_post_messages = raw_data.get('can_post_messages')
|
||||
can_edit_messages = raw_data.get('can_edit_messages')
|
||||
can_delete_messages = raw_data.get('can_delete_messages')
|
||||
can_invite_users = raw_data.get('can_invite_users')
|
||||
can_restrict_members = raw_data.get('can_restrict_members')
|
||||
can_pin_messages = raw_data.get('can_pin_messages')
|
||||
can_promote_members = raw_data.get('can_promote_members')
|
||||
can_send_messages = raw_data.get('can_send_messages')
|
||||
can_send_media_messages = raw_data.get('can_send_media_messages')
|
||||
can_send_other_messages = raw_data.get('can_send_other_messages')
|
||||
can_add_web_page_previews = raw_data.get('can_add_web_page_previews')
|
||||
|
||||
return ChatMember(user, status, until_date, can_be_edited, can_change_info, can_post_messages,
|
||||
can_edit_messages, can_delete_messages, can_invite_users, can_restrict_members,
|
||||
can_pin_messages, can_promote_members, can_send_messages, can_send_media_messages,
|
||||
can_send_other_messages, can_add_web_page_previews
|
||||
)
|
||||
|
||||
|
||||
class ChatMemberStatus(Helper):
|
||||
CREATOR = Item() # creator
|
||||
ADMINISTRATOR = Item() # administrator
|
||||
MEMBER = Item() # member
|
||||
LEFT = Item() # left
|
||||
KICKED = Item() # kicked
|
||||
|
||||
@classmethod
|
||||
def is_admin(cls, role):
|
||||
return role in [cls.ADMINISTRATOR, cls.CREATOR]
|
||||
|
||||
@classmethod
|
||||
def is_member(cls, role):
|
||||
return role in [cls.MEMBER, cls.ADMINISTRATOR, cls.CREATOR]
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class ChatPhoto(Deserializable):
|
||||
"""
|
||||
This object represents a chat photo.
|
||||
|
||||
https://core.telegram.org/bots/api#chatphoto
|
||||
"""
|
||||
|
||||
def __init__(self, small_file_id, big_file_id):
|
||||
self.small_file_id: str = small_file_id
|
||||
self.big_file_id: str = big_file_id
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
small_file_id = raw_data.get('small_file_id')
|
||||
big_file_id = raw_data.get('big_file_id')
|
||||
|
||||
return ChatPhoto(small_file_id, big_file_id)
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .location import Location
|
||||
from .user import User
|
||||
|
||||
|
||||
class ChosenInlineResult(Deserializable):
|
||||
"""
|
||||
Represents a result of an inline query that was chosen by the user and sent to their chat partner.
|
||||
|
||||
https://core.telegram.org/bots/api#choseninlineresult
|
||||
"""
|
||||
|
||||
def __init__(self, result_id, from_user, location, inline_message_id, query):
|
||||
self.result_id: str = result_id
|
||||
self.from_user: User = from_user
|
||||
self.location: Location = location
|
||||
self.inline_message_id: str = inline_message_id
|
||||
self.query: str = query
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
result_id = raw_data.get('result_id')
|
||||
from_user = User.deserialize(raw_data.get('from'))
|
||||
location = Location.deserialize(raw_data.get('location'))
|
||||
inline_message_id = raw_data.get('inline_message_id')
|
||||
query = raw_data.get('query')
|
||||
|
||||
return ChosenInlineResult(result_id, from_user, location, inline_message_id, query)
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class Contact(Deserializable):
|
||||
"""
|
||||
This object represents a phone contact.
|
||||
|
||||
https://core.telegram.org/bots/api#contact
|
||||
"""
|
||||
|
||||
def __init__(self, phone_number, first_name, last_name, user_id):
|
||||
self.phone_number: str = phone_number
|
||||
self.first_name: str = first_name
|
||||
self.last_name: str = last_name
|
||||
self.user_id: int = user_id
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
phone_number = raw_data.get('phone_number')
|
||||
first_name = raw_data.get('first_name')
|
||||
last_name = raw_data.get('last_name')
|
||||
user_id = raw_data.get('user_id')
|
||||
|
||||
return Contact(phone_number, first_name, last_name, user_id)
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
class Document(Deserializable):
|
||||
"""
|
||||
This object represents a general file (as opposed to photos, voice messages and audio files).
|
||||
|
||||
https://core.telegram.org/bots/api#document
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, thumb, file_name, mime_type, file_size):
|
||||
self.file_id: str = file_id
|
||||
self.thumb: PhotoSize = thumb
|
||||
self.file_name: str = file_name
|
||||
self.mime_type: str = mime_type
|
||||
self.file_size: int = file_size
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
file_id = raw_data.get('file_id')
|
||||
thumb = PhotoSize.deserialize(raw_data.get('thumb'))
|
||||
file_name = raw_data.get('file_name')
|
||||
mime_type = raw_data.get('mime_type')
|
||||
file_size = raw_data.get('file_size')
|
||||
|
||||
return Document(file_id, thumb, file_name, mime_type, file_size)
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class File(Deserializable):
|
||||
"""
|
||||
This object represents a file ready to be downloaded.
|
||||
|
||||
The file can be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>.
|
||||
|
||||
It is guaranteed that the link will be valid for at least 1 hour. When the link expires,
|
||||
a new one can be requested by calling getFile.
|
||||
|
||||
https://core.telegram.org/bots/api#file
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, file_size, file_path):
|
||||
self.file_id: str = file_id
|
||||
self.file_size: int = file_size
|
||||
self.file_path: str = file_path
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
file_id = raw_data.get('file_id')
|
||||
file_size = raw_data.get('file_size')
|
||||
file_path = raw_data.get('file_path')
|
||||
|
||||
return File(file_id, file_size, file_path)
|
||||
|
||||
async def download(self, destination=None, timeout=30, chunk_size=65536, seek=True):
|
||||
return await self.bot.download_file(self.file_path, destination, timeout, chunk_size, seek)
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
from .base import Serializable
|
||||
|
||||
|
||||
class ForceReply(Serializable):
|
||||
"""
|
||||
Upon receiving a message with this object,
|
||||
Telegram clients will display a reply interface to the user
|
||||
(act as if the user has selected the bot‘s message and tapped ’Reply').
|
||||
|
||||
This can be extremely useful if you want to create user-friendly step-by-step
|
||||
interfaces without having to sacrifice privacy mode.
|
||||
|
||||
https://core.telegram.org/bots/api#forcereply
|
||||
"""
|
||||
|
||||
def __init__(self, selective=None):
|
||||
self.selective = selective
|
||||
|
||||
def to_json(self):
|
||||
data = {'force_reply': True}
|
||||
if self.selective:
|
||||
data['selective'] = True
|
||||
return data
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
from .animation import Animation
|
||||
from .base import Deserializable
|
||||
from .message_entity import MessageEntity
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
class Game(Deserializable):
|
||||
"""
|
||||
This object represents a game.
|
||||
|
||||
Use BotFather to create and edit games, their short names will act as unique identifiers.
|
||||
|
||||
https://core.telegram.org/bots/api#game
|
||||
"""
|
||||
|
||||
def __init__(self, title, description, photo, text, text_entities, animation):
|
||||
self.title = title
|
||||
self.description = description
|
||||
self.photo = photo
|
||||
self.text = text
|
||||
self.text_entities = text_entities
|
||||
self.animation = animation
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
title = raw_data.get('title')
|
||||
description = raw_data.get('description')
|
||||
photo = PhotoSize.deserialize(raw_data.get('photo'))
|
||||
text = raw_data.get('text')
|
||||
text_entities = MessageEntity.deserialize(raw_data.get('text_entities'))
|
||||
animation = Animation.deserialize(raw_data.get('animation'))
|
||||
|
||||
return Game(title, description, photo, text, text_entities, animation)
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .user import User
|
||||
|
||||
|
||||
class GameHighScore(Deserializable):
|
||||
"""
|
||||
This object represents one row of the high scores table for a game.
|
||||
|
||||
https://core.telegram.org/bots/api#gamehighscore
|
||||
"""
|
||||
|
||||
def __init__(self, position, user, score):
|
||||
self.position: int = position
|
||||
self.user: User = user
|
||||
self.score: int = score
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
position = raw_data.get('position')
|
||||
user = User.deserialize(raw_data.get('user'))
|
||||
score = raw_data.get('score')
|
||||
|
||||
return GameHighScore(position, user, score)
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
from .base import Serializable
|
||||
|
||||
|
||||
class InlineKeyboardMarkup(Serializable):
|
||||
"""
|
||||
This object represents an inline keyboard that appears right next to the message it belongs to.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinekeyboardmarkup
|
||||
"""
|
||||
|
||||
def __init__(self, row_width=3):
|
||||
self.row_width = row_width
|
||||
|
||||
self.keyboard = []
|
||||
|
||||
def add(self, *args):
|
||||
i = 1
|
||||
row = []
|
||||
for button in args:
|
||||
row.append(button.to_json())
|
||||
if i % self.row_width == 0:
|
||||
self.keyboard.append(row)
|
||||
row = []
|
||||
i += 1
|
||||
if len(row) > 0:
|
||||
self.keyboard.append(row)
|
||||
|
||||
def row(self, *args):
|
||||
btn_array = []
|
||||
for button in args:
|
||||
btn_array.append(button.to_json())
|
||||
self.keyboard.append(btn_array)
|
||||
return self
|
||||
|
||||
def to_json(self):
|
||||
return {'inline_keyboard': self.keyboard}
|
||||
|
||||
|
||||
class InlineKeyboardButton(Serializable):
|
||||
"""
|
||||
This object represents one button of an inline keyboard. You must use exactly one of the optional fields.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinekeyboardbutton
|
||||
"""
|
||||
|
||||
def __init__(self, text, url=None, callback_data=None, switch_inline_query=None,
|
||||
switch_inline_query_current_chat=None, callback_game=None, pay=None):
|
||||
self.text = text
|
||||
self.url = url
|
||||
self.callback_data = callback_data
|
||||
self.switch_inline_query = switch_inline_query
|
||||
self.switch_inline_query_current_chat = switch_inline_query_current_chat
|
||||
self.callback_game = callback_game
|
||||
self.pay = pay
|
||||
|
||||
def to_json(self):
|
||||
return {key: value for key, value in self.__dict__.items() if value}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .location import Location
|
||||
from .user import User
|
||||
|
||||
|
||||
class InlineQuery(Deserializable):
|
||||
"""
|
||||
This object represents an incoming inline query.
|
||||
|
||||
When the user sends an empty query, your bot could return some default or trending results.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequery
|
||||
"""
|
||||
|
||||
def __init__(self, id, from_user, location, query, offset):
|
||||
self.id: int = id
|
||||
self.from_user: User = from_user
|
||||
self.location: Location = location
|
||||
self.query: str = query
|
||||
self.offset: str = offset
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
id = raw_data.get('id')
|
||||
from_user = User.deserialize(raw_data.get('from'))
|
||||
location = Location.deserialize(raw_data.get('location'))
|
||||
query = raw_data.get('query')
|
||||
offset = raw_data.get('offset')
|
||||
|
||||
return InlineQuery(id, from_user, location, query, offset)
|
||||
|
|
@ -1,605 +0,0 @@
|
|||
from .base import Serializable
|
||||
from .inline_keyboard import InlineKeyboardMarkup
|
||||
|
||||
|
||||
class InputMessageContent(Serializable):
|
||||
"""
|
||||
This object represents the content of a message to be sent as a result of an inline query.
|
||||
|
||||
Telegram clients currently support the following 4 types:
|
||||
|
||||
:class:`aiogram.types.InputTextMessageContent`
|
||||
:class:`aiogram.types.InputLocationMessageContent`
|
||||
:class:`aiogram.types.InputVenueMessageContent`
|
||||
:class:`aiogram.types.InputContactMessageContent`
|
||||
"""
|
||||
|
||||
def to_json(self):
|
||||
return {k: v.to_json() if hasattr(v, 'to_json') else v for k, v in self.__dict__.items() if
|
||||
v is not None and not k.startswith('_')}
|
||||
|
||||
|
||||
class InlineQueryResult(InputMessageContent):
|
||||
"""
|
||||
This object represents one result of an inline query.
|
||||
|
||||
Telegram clients currently support results of the following 20 types:
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultCachedAudio`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultCachedDocument`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultCachedGif`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultCachedMpeg4Gif`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultCachedPhoto`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultCachedSticker`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultCachedVideo`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultCachedVoice`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultArticle`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultAudio`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultContact`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultGame`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultDocument`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultGif`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultLocation`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultMpeg4Gif`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultPhoto`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultVenue`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultVideo`
|
||||
|
||||
:class:`aiogram.types.InlineQueryResultVoice`
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class InlineQueryResultArticle(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to an article or web page.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultarticle
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, title: str, input_message_content: InputMessageContent,
|
||||
reply_markup: InlineKeyboardMarkup = None, url: str = None, hide_url: bool = None,
|
||||
description: str = None, thumb_url: str = None, thumb_width: int = None, thumb_height: int = None):
|
||||
self.type = 'article'
|
||||
self.id: str = id
|
||||
self.title: str = title
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.url: str = url
|
||||
self.hide_url: bool = hide_url
|
||||
self.description: str = description
|
||||
self.thumb_url: str = thumb_url
|
||||
self.thumb_width: int = thumb_width
|
||||
self.thumb_height: int = thumb_height
|
||||
|
||||
|
||||
class InlineQueryResultPhoto(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a photo. By default, this photo will be sent by the user with optional caption.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified content instead
|
||||
of the photo.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultphoto
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, photo_url: str, thumb_url: str, photo_width: int = None,
|
||||
photo_height: int = None, title: str = None, description: str = None, caption: str = None,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None):
|
||||
self.type = 'photo'
|
||||
self.id: str = id
|
||||
self.photo_url: str = photo_url
|
||||
self.thumb_url: str = thumb_url
|
||||
self.photo_width: int = photo_width
|
||||
self.photo_height: int = photo_height
|
||||
self.title: str = title
|
||||
self.description: str = description
|
||||
self.caption: str = caption
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultGif(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to an animated GIF file.
|
||||
|
||||
By default, this animated GIF file will be sent by the user with optional caption.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified
|
||||
content instead of the animation.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultgif
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, gif_url: str, thumb_url: str, gif_width: int = None, gif_height: int = None,
|
||||
gif_duration: int = None, title: str = None, caption: str = None,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None):
|
||||
self.type = 'gif'
|
||||
self.id: str = id
|
||||
self.gif_url: str = gif_url
|
||||
self.gif_width: int = gif_width
|
||||
self.gif_height: int = gif_height
|
||||
self.gif_duration: int = gif_duration
|
||||
self.thumb_url: str = thumb_url
|
||||
self.title: str = title
|
||||
self.caption: str = caption
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a video animation (H.264/MPEG-4 AVC video without sound).
|
||||
|
||||
By default, this animated MPEG-4 file will be sent by the user with optional caption.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified content
|
||||
instead of the animation.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, mpeg4_url: str, thumb_url: str, mpeg4_width: int = None,
|
||||
mpeg4_height: int = None, mpeg4_duration: int = None, title: str = None, caption: str = None,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None):
|
||||
self.type = 'mpeg4_gif'
|
||||
self.id: str = id
|
||||
self.mpeg4_url: str = mpeg4_url
|
||||
self.mpeg4_width: int = mpeg4_width
|
||||
self.mpeg4_height: int = mpeg4_height
|
||||
self.mpeg4_duration: int = mpeg4_duration
|
||||
self.thumb_url: str = thumb_url
|
||||
self.title: str = title
|
||||
self.caption: str = caption
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultVideo(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a page containing an embedded video player or a video file.
|
||||
By default, this video file will be sent by the user with an optional caption.
|
||||
Alternatively, you can use input_message_content to send a message with the specified content
|
||||
instead of the video.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultvideo
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, video_url: str, mime_type: str, thumb_url: str, title: str,
|
||||
caption: str = None, video_width: int = None, video_height: int = None, video_duration: int = None,
|
||||
description: str = None, reply_markup: InlineKeyboardMarkup = None,
|
||||
input_message_content: InputMessageContent = None):
|
||||
self.type = 'video'
|
||||
self.id: str = id
|
||||
self.video_url: str = video_url
|
||||
self.mime_type: str = mime_type
|
||||
self.thumb_url: str = thumb_url
|
||||
self.title: str = title
|
||||
self.caption: str = caption
|
||||
self.video_width: int = video_width
|
||||
self.video_height: int = video_height
|
||||
self.video_duration: int = video_duration
|
||||
self.description: str = description
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultAudio(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to an mp3 audio file. By default, this audio file will be sent by the user. Alternatively,
|
||||
you can use input_message_content to send a message with the specified content instead of the audio.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultaudio
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, audio_url: str, title: str, caption: str = None, performer: str = None,
|
||||
audio_duration: int = None, reply_markup: InlineKeyboardMarkup = None,
|
||||
input_message_content: InputMessageContent = None):
|
||||
self.type = 'audio'
|
||||
self.id: str = id
|
||||
self.audio_url: str = audio_url
|
||||
self.title: str = title
|
||||
self.caption: str = caption
|
||||
self.performer: str = performer
|
||||
self.audio_duration: int = audio_duration
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultVoice(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a voice recording in an .ogg container encoded with OPUS.
|
||||
|
||||
By default, this voice recording will be sent by the user.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified content
|
||||
instead of the the voice message.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultvoice
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, voice_url: str, title: str, caption: str = None, voice_duration: int = None,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None):
|
||||
self.type = 'voice'
|
||||
self.id: str = id
|
||||
self.voice_url: str = voice_url
|
||||
self.title: str = title
|
||||
self.caption: str = caption
|
||||
self.voice_duration: int = voice_duration
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultDocument(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a file. By default, this file will be sent by the user with an optional caption.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified content
|
||||
instead of the file. Currently, only .PDF and .ZIP files can be sent using this method.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultdocument
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, title: str, document_url: str, mime_type: str, caption: str = None,
|
||||
description: str = None, reply_markup: InlineKeyboardMarkup = None,
|
||||
input_message_content: InputMessageContent = None, thumb_url: str = None, thumb_width: int = None,
|
||||
thumb_height: int = None):
|
||||
self.type = 'document'
|
||||
self.id: str = id
|
||||
self.title: str = title
|
||||
self.caption: str = caption
|
||||
self.document_url: str = document_url
|
||||
self.mime_type: str = mime_type
|
||||
self.description: str = description
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
self.thumb_url: str = thumb_url
|
||||
self.thumb_width: int = thumb_width
|
||||
self.thumb_height: int = thumb_height
|
||||
|
||||
|
||||
class InlineQueryResultLocation(InlineQueryResult):
|
||||
"""
|
||||
Represents a location on a map. By default, the location will be sent by the user.
|
||||
Alternatively, you can use input_message_content to send a message with the specified content
|
||||
instead of the location.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultlocation
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, latitude: float, longitude: float, title: str,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None,
|
||||
thumb_url: str = None, thumb_width: int = None, thumb_height: int = None):
|
||||
self.type = 'location'
|
||||
self.id: str = id
|
||||
self.latitude: float = latitude
|
||||
self.longitude: float = longitude
|
||||
self.title: str = title
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
self.thumb_url: str = thumb_url
|
||||
self.thumb_width: int = thumb_width
|
||||
self.thumb_height: int = thumb_height
|
||||
|
||||
|
||||
class InlineQueryResultVenue(InlineQueryResult):
|
||||
"""
|
||||
Represents a venue. By default, the venue will be sent by the user.
|
||||
Alternatively, you can use input_message_content to send a message with the specified
|
||||
content instead of the venue.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultvenue
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, latitude: float, longitude: float, title: str, address: str,
|
||||
foursquare_id: str = None, reply_markup: InlineKeyboardMarkup = None,
|
||||
input_message_content: InputMessageContent = None, thumb_url: str = None, thumb_width: int = None,
|
||||
thumb_height: int = None):
|
||||
self.type = 'venue'
|
||||
self.id: str = id
|
||||
self.latitude: float = latitude
|
||||
self.longitude: float = longitude
|
||||
self.title: str = title
|
||||
self.address: str = address
|
||||
self.foursquare_id: str = foursquare_id
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
self.thumb_url: str = thumb_url
|
||||
self.thumb_width: int = thumb_width
|
||||
self.thumb_height: int = thumb_height
|
||||
|
||||
|
||||
class InlineQueryResultContact(InlineQueryResult):
|
||||
"""
|
||||
Represents a contact with a phone number.
|
||||
|
||||
By default, this contact will be sent by the user.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified content instead
|
||||
of the contact.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultcontact
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, phone_number: str, first_name: str, last_name: str = None,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None,
|
||||
thumb_url: str = None, thumb_width: int = None, thumb_height: int = None):
|
||||
self.type = 'contact'
|
||||
self.id: str = id
|
||||
self.phone_number: str = phone_number
|
||||
self.first_name: str = first_name
|
||||
self.last_name: str = last_name
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
self.thumb_url: str = thumb_url
|
||||
self.thumb_width: int = thumb_width
|
||||
self.thumb_height: int = thumb_height
|
||||
|
||||
|
||||
class InlineQueryResultGame(InlineQueryResult):
|
||||
"""
|
||||
Represents a Game.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultgame
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, game_short_name: str, reply_markup: InlineKeyboardMarkup = None):
|
||||
self.type = 'game'
|
||||
self.id: str = id
|
||||
self.game_short_name: str = game_short_name
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
|
||||
|
||||
class InlineQueryResultCachedPhoto(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a photo stored on the Telegram servers.
|
||||
|
||||
By default, this photo will be sent by the user with an optional caption.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified
|
||||
content instead of the photo.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultcachedphoto
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, photo_file_id: str, title: str = None, description: str = None,
|
||||
caption: str = None, reply_markup: InlineKeyboardMarkup = None,
|
||||
input_message_content: InputMessageContent = None):
|
||||
self.type = 'photo'
|
||||
self.id: str = id
|
||||
self.photo_file_id: str = photo_file_id
|
||||
self.title: str = title
|
||||
self.description: str = description
|
||||
self.caption: str = caption
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultCachedGif(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to an animated GIF file stored on the Telegram servers.
|
||||
|
||||
By default, this animated GIF file will be sent by the user with an optional caption.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with specified content
|
||||
instead of the animation.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultcachedgif
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, gif_file_id: str, title: str = None, caption: str = None,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None):
|
||||
self.type = 'gif'
|
||||
self.id: str = id
|
||||
self.gif_file_id: str = gif_file_id
|
||||
self.title: str = title
|
||||
self.caption: str = caption
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers.
|
||||
|
||||
By default, this animated MPEG-4 file will be sent by the user with an optional caption.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified content
|
||||
instead of the animation.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, mpeg4_file_id: str, title: str = None, caption: str = None,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None):
|
||||
self.type = 'mpeg4_gif'
|
||||
self.id: str = id
|
||||
self.mpeg4_file_id: str = mpeg4_file_id
|
||||
self.title: str = title
|
||||
self.caption: str = caption
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultCachedSticker(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a sticker stored on the Telegram servers.
|
||||
|
||||
By default, this sticker will be sent by the user.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified content
|
||||
instead of the sticker.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultcachedsticker
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, sticker_file_id: str, reply_markup: InlineKeyboardMarkup = None,
|
||||
input_message_content: InputMessageContent = None):
|
||||
self.type = 'sticker'
|
||||
self.id: str = id
|
||||
self.sticker_file_id: str = sticker_file_id
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultCachedDocument(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a file stored on the Telegram servers.
|
||||
|
||||
By default, this file will be sent by the user with an optional caption.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified content
|
||||
instead of the file.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultcacheddocument
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, title: str, document_file_id: str, description: str = None,
|
||||
caption: str = None, reply_markup: InlineKeyboardMarkup = None,
|
||||
input_message_content: InputMessageContent = None):
|
||||
self.type = 'document'
|
||||
self.id: str = id
|
||||
self.title: str = title
|
||||
self.document_file_id: str = document_file_id
|
||||
self.description: str = description
|
||||
self.caption: str = caption
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultCachedVideo(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a video file stored on the Telegram servers.
|
||||
By default, this video file will be sent by the user with an optional caption.
|
||||
Alternatively, you can use input_message_content to send a message with the specified content instead
|
||||
of the video.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultcachedvideo
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, video_file_id: str, title: str, description: str = None, caption: str = None,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None):
|
||||
self.type = 'video'
|
||||
self.id: str = id
|
||||
self.video_file_id: str = video_file_id
|
||||
self.title: str = title
|
||||
self.description: str = description
|
||||
self.caption: str = caption
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultCachedVoice(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a voice message stored on the Telegram servers.
|
||||
|
||||
By default, this voice message will be sent by the user.
|
||||
|
||||
Alternatively, you can use input_message_content to send a message with the specified content
|
||||
instead of the voice message.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultcachedvoice
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, voice_file_id: str, title: str, caption: str = None,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None):
|
||||
self.type = 'voice'
|
||||
self.id: str = id
|
||||
self.voice_file_id: str = voice_file_id
|
||||
self.title: str = title
|
||||
self.caption: str = caption
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InlineQueryResultCachedAudio(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to an mp3 audio file stored on the Telegram servers.
|
||||
|
||||
By default, this audio file will be sent by the user.
|
||||
Alternatively, you can use input_message_content to send a message with the specified content
|
||||
instead of the audio.
|
||||
|
||||
https://core.telegram.org/bots/api#inlinequeryresultcachedaudio
|
||||
"""
|
||||
|
||||
def __init__(self, id: str, audio_file_id: str, caption: str = None,
|
||||
reply_markup: InlineKeyboardMarkup = None, input_message_content: InputMessageContent = None):
|
||||
self.type = 'audio'
|
||||
self.id: str = id
|
||||
self.audio_file_id: str = audio_file_id
|
||||
self.caption: str = caption
|
||||
self.reply_markup: InlineKeyboardMarkup = reply_markup
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
|
||||
class InputTextMessageContent(InputMessageContent):
|
||||
"""
|
||||
Represents the content of a text message to be sent as the result of an inline query.
|
||||
|
||||
https://core.telegram.org/bots/api#inputtextmessagecontent
|
||||
"""
|
||||
|
||||
def __init__(self, message_text: str, parse_mode: str = None, disable_web_page_preview: bool = None):
|
||||
self.message_text: str = message_text
|
||||
self.parse_mode: str = parse_mode
|
||||
self.disable_web_page_preview: bool = disable_web_page_preview
|
||||
|
||||
|
||||
class InputLocationMessageContent(InputMessageContent):
|
||||
"""
|
||||
Represents the content of a location message to be sent as the result of an inline query.
|
||||
|
||||
https://core.telegram.org/bots/api#inputlocationmessagecontent
|
||||
"""
|
||||
|
||||
def __init__(self, latitude: float, longitude: float):
|
||||
self.latitude: float = latitude
|
||||
self.longitude: float = longitude
|
||||
|
||||
|
||||
class InputVenueMessageContent(InputMessageContent):
|
||||
"""
|
||||
Represents the content of a venue message to be sent as the result of an inline query.
|
||||
|
||||
https://core.telegram.org/bots/api#inputvenuemessagecontent
|
||||
"""
|
||||
|
||||
def __init__(self, latitude: float, longitude: float, title: str, address: str, foursquare_id: str = None):
|
||||
self.latitude: float = latitude
|
||||
self.longitude: float = longitude
|
||||
self.title: str = title
|
||||
self.address: str = address
|
||||
self.foursquare_id: str = foursquare_id
|
||||
|
||||
|
||||
class InputContactMessageContent(InputMessageContent):
|
||||
"""
|
||||
Represents the content of a contact message to be sent as the result of an inline query.
|
||||
|
||||
https://core.telegram.org/bots/api#inputcontactmessagecontent
|
||||
"""
|
||||
|
||||
def __init__(self, phone_number: str, first_name: str, last_name: str = None):
|
||||
self.phone_number: str = phone_number
|
||||
self.first_name: str = first_name
|
||||
self.last_name: str = last_name
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class Invoice(Deserializable):
|
||||
"""
|
||||
This object contains basic information about an invoice.
|
||||
|
||||
https://core.telegram.org/bots/api#invoice
|
||||
"""
|
||||
|
||||
def __init__(self, title, description, start_parameter, currency, total_amount):
|
||||
self.title: str = title
|
||||
self.description: str = description
|
||||
self.start_parameter: str = start_parameter
|
||||
self.currency: str = currency
|
||||
self.total_amount: int = total_amount
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
title = raw_data.get('title')
|
||||
description = raw_data.get('description')
|
||||
start_parameter = raw_data.get('start_parameter')
|
||||
currency = raw_data.get('currency')
|
||||
total_amount = raw_data.get('total_amount')
|
||||
|
||||
return Invoice(title, description, start_parameter, currency, total_amount)
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
from .base import Serializable
|
||||
|
||||
|
||||
class LabeledPrice(Serializable):
|
||||
"""
|
||||
This object represents a portion of the price for goods or services.
|
||||
|
||||
https://core.telegram.org/bots/api#labeledprice
|
||||
"""
|
||||
|
||||
def __init__(self, label, amount):
|
||||
self.label = label
|
||||
self.amount = amount
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class Location(Deserializable):
|
||||
"""
|
||||
This object represents a point on the map.
|
||||
|
||||
https://core.telegram.org/bots/api#location
|
||||
"""
|
||||
|
||||
def __init__(self, longitude, latitude):
|
||||
self.longitude = longitude
|
||||
self.latitude = latitude
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
longitude = raw_data.get('longitude')
|
||||
latitude = raw_data.get('latitude')
|
||||
|
||||
return Location(longitude, latitude)
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class MaskPosition(Deserializable):
|
||||
"""
|
||||
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
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
point = raw_data.get('point')
|
||||
x_shift = raw_data.get('x_shift')
|
||||
y_shift = raw_data.get('y_shift')
|
||||
zoom = raw_data.get('zoom')
|
||||
|
||||
return cls(point=point, x_shift=x_shift, y_shift=y_shift, zoom=zoom)
|
||||
|
|
@ -1,289 +0,0 @@
|
|||
import datetime
|
||||
|
||||
from .audio import Audio
|
||||
from .base import Deserializable
|
||||
from .chat import Chat
|
||||
from .contact import Contact
|
||||
from .document import Document
|
||||
from .game import Game
|
||||
from .invoice import Invoice
|
||||
from .location import Location
|
||||
from .message_entity import MessageEntity
|
||||
from .photo_size import PhotoSize
|
||||
from .sticker import Sticker
|
||||
from .successful_payment import SuccessfulPayment
|
||||
from .user import User
|
||||
from .venue import Venue
|
||||
from .video import Video
|
||||
from .video_note import VideoNote
|
||||
from .voice import Voice
|
||||
from ..utils.exceptions import TelegramAPIError
|
||||
from ..utils.helper import Item, HelperMode, Helper, ListItem
|
||||
|
||||
|
||||
class Message(Deserializable):
|
||||
"""
|
||||
This object represents a message.
|
||||
|
||||
https://core.telegram.org/bots/api#message
|
||||
"""
|
||||
|
||||
def __init__(self, message_id, from_user, date, chat, forward_from, forward_from_chat, forward_from_message_id,
|
||||
forward_signature, forward_date, reply_to_message, edit_date, author_signature, text, entities, audio,
|
||||
document, game, photo, sticker, video, voice, video_note, new_chat_members, caption, contact, location,
|
||||
venue, left_chat_member, new_chat_title, new_chat_photo, delete_chat_photo, group_chat_created,
|
||||
supergroup_chat_created, channel_chat_created, migrate_to_chat_id, migrate_from_chat_id,
|
||||
pinned_message, invoice, successful_payment, content_type):
|
||||
self.message_id: int = message_id
|
||||
self.from_user: User = from_user
|
||||
self.date: datetime.datetime = date
|
||||
self.chat: Chat = chat
|
||||
self.forward_from: User = forward_from
|
||||
self.forward_from_chat: Chat = forward_from_chat
|
||||
self.forward_from_message_id: int = forward_from_message_id
|
||||
self.forward_signature: str = forward_signature
|
||||
self.forward_date: datetime.datetime = forward_date
|
||||
self.reply_to_message: Message = reply_to_message
|
||||
self.edit_date: datetime.datetime = edit_date
|
||||
self.author_signature: str = author_signature
|
||||
self.text: str = text
|
||||
self.entities = entities
|
||||
self.audio = audio
|
||||
self.document = document
|
||||
self.game = game
|
||||
self.photo = photo
|
||||
self.sticker = sticker
|
||||
self.video = video
|
||||
self.voice = voice
|
||||
self.video_note = video_note
|
||||
self.new_chat_members = new_chat_members
|
||||
self.caption = caption
|
||||
self.contact = contact
|
||||
self.location = location
|
||||
self.venue = venue
|
||||
self.left_chat_member = left_chat_member
|
||||
self.new_chat_title = new_chat_title
|
||||
self.new_chat_photo = new_chat_photo
|
||||
self.delete_chat_photo = delete_chat_photo
|
||||
self.group_chat_created = group_chat_created
|
||||
self.supergroup_chat_created = supergroup_chat_created
|
||||
self.channel_chat_created = channel_chat_created
|
||||
self.migrate_to_chat_id = migrate_to_chat_id
|
||||
self.migrate_from_chat_id = migrate_from_chat_id
|
||||
self.pinned_message = pinned_message
|
||||
self.invoice = invoice
|
||||
self.successful_payment = successful_payment
|
||||
|
||||
self.content_type = content_type
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
message_id = raw_data.get('message_id')
|
||||
from_user = User.deserialize(raw_data.get('from'))
|
||||
date = cls._parse_date(raw_data.get('date', 0))
|
||||
chat = Chat.deserialize(raw_data.get('chat', {}))
|
||||
forward_from = User.deserialize(raw_data.get('forward_from', {}))
|
||||
forward_from_chat = Chat.deserialize(raw_data.get('forward_from_chat', {}))
|
||||
forward_from_message_id = raw_data.get('forward_from_message_id')
|
||||
forward_signature = raw_data.get('forward_signature')
|
||||
forward_date = cls._parse_date(raw_data.get('forward_date', 0))
|
||||
reply_to_message = Message.deserialize(raw_data.get('reply_to_message', {}))
|
||||
edit_date = cls._parse_date(raw_data.get('edit_date', 0))
|
||||
author_signature = raw_data.get('author_signature')
|
||||
text = raw_data.get('text')
|
||||
entities = MessageEntity.deserialize(raw_data.get('entities'))
|
||||
audio = Audio.deserialize(raw_data.get('audio'))
|
||||
document = Document.deserialize(raw_data.get('document'))
|
||||
game = Game.deserialize(raw_data.get('game'))
|
||||
photo = PhotoSize.deserialize(raw_data.get('photo'))
|
||||
sticker = Sticker.deserialize(raw_data.get('sticker'))
|
||||
video = Video.deserialize(raw_data.get('video'))
|
||||
voice = Voice.deserialize(raw_data.get('voice'))
|
||||
video_note = VideoNote.deserialize(raw_data.get('video_note'))
|
||||
new_chat_members = User.deserialize(raw_data.get('new_chat_members'))
|
||||
caption = raw_data.get('caption')
|
||||
contact = Contact.deserialize(raw_data.get('contact'))
|
||||
location = Location.deserialize(raw_data.get('location'))
|
||||
venue = Venue.deserialize(raw_data.get('venue'))
|
||||
left_chat_member = User.deserialize(raw_data.get('left_chat_member'))
|
||||
new_chat_title = raw_data.get('new_chat_title')
|
||||
new_chat_photo = raw_data.get('new_chat_photo')
|
||||
delete_chat_photo = PhotoSize.deserialize(raw_data.get('delete_chat_photo'))
|
||||
group_chat_created = raw_data.get('group_chat_created')
|
||||
supergroup_chat_created = raw_data.get('supergroup_chat_created')
|
||||
channel_chat_created = raw_data.get('channel_chat_created')
|
||||
migrate_to_chat_id = raw_data.get('migrate_to_chat_id')
|
||||
migrate_from_chat_id = raw_data.get('migrate_from_chat_id')
|
||||
pinned_message = Message.deserialize(raw_data.get('pinned_message'))
|
||||
invoice = Invoice.deserialize(raw_data.get('invoice'))
|
||||
successful_payment = SuccessfulPayment.deserialize(raw_data.get('successful_payment'))
|
||||
|
||||
if text:
|
||||
content_type = ContentType.TEXT[0]
|
||||
elif audio:
|
||||
content_type = ContentType.AUDIO[0]
|
||||
elif document:
|
||||
content_type = ContentType.DOCUMENT[0]
|
||||
elif game:
|
||||
content_type = ContentType.GAME[0]
|
||||
elif photo:
|
||||
content_type = ContentType.PHOTO[0]
|
||||
elif sticker:
|
||||
content_type = ContentType.STICKER[0]
|
||||
elif video:
|
||||
content_type = ContentType.VIDEO[0]
|
||||
elif voice:
|
||||
content_type = ContentType.VOICE[0]
|
||||
elif new_chat_members:
|
||||
content_type = ContentType.NEW_CHAT_MEMBERS[0]
|
||||
elif left_chat_member:
|
||||
content_type = ContentType.LEFT_CHAT_MEMBER[0]
|
||||
elif invoice:
|
||||
content_type = ContentType.INVOICE[0]
|
||||
elif successful_payment:
|
||||
content_type = ContentType.SUCCESSFUL_PAYMENT[0]
|
||||
else:
|
||||
content_type = ContentType.UNKNOWN[0]
|
||||
|
||||
return Message(message_id, from_user, date, chat, forward_from, forward_from_chat, forward_from_message_id,
|
||||
forward_signature, forward_date, reply_to_message, edit_date, author_signature, text, entities,
|
||||
audio, document, game, photo, sticker, video, voice, video_note, new_chat_members, caption,
|
||||
contact, location, venue, left_chat_member, new_chat_title, new_chat_photo, delete_chat_photo,
|
||||
group_chat_created, supergroup_chat_created, channel_chat_created, migrate_to_chat_id,
|
||||
migrate_from_chat_id, pinned_message, invoice, successful_payment, content_type)
|
||||
|
||||
def is_command(self):
|
||||
"""
|
||||
Check message text is command
|
||||
:return: bool
|
||||
"""
|
||||
return self.text and self.text.startswith('/')
|
||||
|
||||
def get_full_command(self):
|
||||
"""
|
||||
Split command and args
|
||||
:return: tuple of (command, args)
|
||||
"""
|
||||
if self.is_command():
|
||||
command, _, args = self.text.partition(' ')
|
||||
return command, args
|
||||
|
||||
def get_command(self):
|
||||
command = self.get_full_command()
|
||||
if command:
|
||||
return command[0]
|
||||
|
||||
def get_args(self):
|
||||
command = self.get_full_command()
|
||||
if command:
|
||||
return command[1].strip()
|
||||
|
||||
@property
|
||||
def md_text(self):
|
||||
text = self.text
|
||||
|
||||
if self.text and self.entities:
|
||||
for entity in reversed(self.entities):
|
||||
text = entity.apply_md(text)
|
||||
|
||||
return text
|
||||
|
||||
@property
|
||||
def html_text(self):
|
||||
text = self.text
|
||||
|
||||
if self.text and self.entities:
|
||||
for entity in reversed(self.entities):
|
||||
text = entity.apply_html(text)
|
||||
|
||||
return text
|
||||
|
||||
async def reply(self, text, parse_mode=None, disable_web_page_preview=None,
|
||||
disable_notification=None, reply_markup=None) -> 'Message':
|
||||
"""
|
||||
Reply to this message
|
||||
|
||||
:param text: str
|
||||
:param parse_mode: str
|
||||
:param disable_web_page_preview: bool
|
||||
:param disable_notification: bool
|
||||
:param reply_markup:
|
||||
:return: :class:`aoigram.types.Message`
|
||||
"""
|
||||
return await self.bot.send_message(self.chat.id, text, parse_mode, disable_web_page_preview,
|
||||
disable_notification, self.message_id, reply_markup)
|
||||
|
||||
async def forward(self, chat_id, disable_notification=None) -> 'Message':
|
||||
"""
|
||||
Forward this message
|
||||
|
||||
:param chat_id:
|
||||
:param disable_notification:
|
||||
:return:
|
||||
"""
|
||||
return await self.bot.forward_message(chat_id, self.chat.id, self.message_id, disable_notification)
|
||||
|
||||
async def delete(self):
|
||||
"""
|
||||
Delete this message
|
||||
|
||||
:return: bool
|
||||
"""
|
||||
try:
|
||||
await self.bot.delete_message(self.chat.id, self.message_id)
|
||||
except TelegramAPIError:
|
||||
return False
|
||||
return True
|
||||
|
||||
async def pin(self, disable_notification: bool = False):
|
||||
return await self.chat.pin_message(self.message_id, disable_notification)
|
||||
|
||||
|
||||
class ContentType(Helper):
|
||||
"""
|
||||
List of message content types
|
||||
|
||||
:key: TEXT
|
||||
:key: AUDIO
|
||||
:key: DOCUMENT
|
||||
:key: GAME
|
||||
:key: PHOTO
|
||||
:key: STICKER
|
||||
:key: VIDEO
|
||||
:key: VOICE
|
||||
:key: NEW_CHAT_MEMBERS
|
||||
:key: LEFT_CHAT_MEMBER
|
||||
:key: INVOICE
|
||||
:key: SUCCESSFUL_PAYMENT
|
||||
:key: UNKNOWN
|
||||
"""
|
||||
mode = HelperMode.snake_case
|
||||
|
||||
TEXT = ListItem() # text
|
||||
AUDIO = ListItem() # audio
|
||||
DOCUMENT = ListItem() # document
|
||||
GAME = ListItem() # game
|
||||
PHOTO = ListItem() # photo
|
||||
STICKER = ListItem() # sticker
|
||||
VIDEO = ListItem() # video
|
||||
VOICE = ListItem() # voice
|
||||
NEW_CHAT_MEMBERS = ListItem() # new_chat_members
|
||||
LEFT_CHAT_MEMBER = ListItem() # left_chat_member
|
||||
INVOICE = ListItem() # invoice
|
||||
SUCCESSFUL_PAYMENT = ListItem() # successful_payment
|
||||
|
||||
UNKNOWN = 'unknown'
|
||||
|
||||
|
||||
class ParseMode(Helper):
|
||||
"""
|
||||
Parse modes
|
||||
|
||||
:key: MARKDOWN
|
||||
:key: HTML
|
||||
"""
|
||||
|
||||
mode = HelperMode.lowercase
|
||||
|
||||
MARKDOWN = Item()
|
||||
HTML = Item()
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .user import User
|
||||
from ..utils import markdown
|
||||
from ..utils.helper import Helper, Item, HelperMode
|
||||
|
||||
|
||||
class MessageEntity(Deserializable):
|
||||
"""
|
||||
This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.
|
||||
|
||||
https://core.telegram.org/bots/api#messageentity
|
||||
"""
|
||||
|
||||
def __init__(self, type, offset, length, url, user):
|
||||
self.type: str = type
|
||||
self.offset: int = offset
|
||||
self.length: int = length
|
||||
self.url: str = url
|
||||
self.user: User = user
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
type = raw_data.get('type')
|
||||
offset = raw_data.get('offset')
|
||||
length = raw_data.get('length')
|
||||
url = raw_data.get('url')
|
||||
user = User.deserialize(raw_data.get('user'))
|
||||
|
||||
return MessageEntity(type, offset, length, url, user)
|
||||
|
||||
def _apply(self, text, func):
|
||||
return text[:self.offset] + \
|
||||
func(text[self.offset:self.offset + self.length]) + \
|
||||
text[self.offset + self.length:]
|
||||
|
||||
def apply_md(self, text):
|
||||
if self.type == MessageEntityType.BOLD:
|
||||
return self._apply(text, markdown.bold)
|
||||
elif self.type == MessageEntityType.ITALIC:
|
||||
return self._apply(text, markdown.italic)
|
||||
elif self.type == MessageEntityType.PRE:
|
||||
return self._apply(text, markdown.pre)
|
||||
elif self.type == MessageEntityType.CODE:
|
||||
return self._apply(text, markdown.code)
|
||||
elif self.type == MessageEntityType.URL:
|
||||
return self._apply(text, lambda url: markdown.link(url, url))
|
||||
elif self.type == MessageEntityType.TEXT_LINK:
|
||||
return self._apply(text, lambda url: markdown.link(url, self.url))
|
||||
return text
|
||||
|
||||
def apply_html(self, text):
|
||||
if self.type == MessageEntityType.BOLD:
|
||||
return self._apply(text, markdown.hbold)
|
||||
elif self.type == MessageEntityType.ITALIC:
|
||||
return self._apply(text, markdown.hitalic)
|
||||
elif self.type == MessageEntityType.PRE:
|
||||
return self._apply(text, markdown.hpre)
|
||||
elif self.type == MessageEntityType.CODE:
|
||||
return self._apply(text, markdown.hcode)
|
||||
elif self.type == MessageEntityType.URL:
|
||||
return self._apply(text, lambda url: markdown.hlink(url, url))
|
||||
elif self.type == MessageEntityType.TEXT_LINK:
|
||||
return self._apply(text, lambda url: markdown.hlink(url, self.url))
|
||||
return text
|
||||
|
||||
|
||||
class MessageEntityType(Helper):
|
||||
"""
|
||||
List of entity types
|
||||
|
||||
:key: MENTION
|
||||
:key: HASHTAG
|
||||
:key: BOT_COMMAND
|
||||
:key: URL
|
||||
:key: EMAIL
|
||||
:key: BOLD
|
||||
:key: ITALIC
|
||||
:key: CODE
|
||||
:key: PRE
|
||||
:key: TEXT_LINK
|
||||
:key: TEXT_MENTION
|
||||
"""
|
||||
mode = HelperMode.snake_case
|
||||
|
||||
MENTION = Item() # mention - @username
|
||||
HASHTAG = Item() # hashtag
|
||||
BOT_COMMAND = Item() # bot_command
|
||||
URL = Item() # url
|
||||
EMAIL = Item() # email
|
||||
BOLD = Item() # bold - bold text
|
||||
ITALIC = Item() # italic - italic text
|
||||
CODE = Item() # code - monowidth string
|
||||
PRE = Item() # pre - monowidth block
|
||||
TEXT_LINK = Item() # text_link - for clickable text URLs
|
||||
TEXT_MENTION = Item() # text_mention - for users without usernames
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .shipping_address import ShippingAddress
|
||||
|
||||
|
||||
class OrderInfo(Deserializable):
|
||||
"""
|
||||
his object represents information about an order.
|
||||
|
||||
https://core.telegram.org/bots/api#orderinfo
|
||||
"""
|
||||
|
||||
def __init__(self, name, phone_number, email, shipping_address):
|
||||
self.name: str = name
|
||||
self.phone_number: str = phone_number
|
||||
self.email: str = email
|
||||
self.shipping_address: ShippingAddress = shipping_address
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
name = raw_data.get('name')
|
||||
phone_number = raw_data.get('phone_number')
|
||||
email = raw_data.get('email')
|
||||
shipping_address = ShippingAddress.deserialize(raw_data.get('shipping_address'))
|
||||
|
||||
return OrderInfo(name, phone_number, email, shipping_address)
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
from .base import deserialize, Deserializable
|
||||
|
||||
|
||||
class PhotoSize(Deserializable):
|
||||
"""
|
||||
This object represents one size of a photo or a file / sticker thumbnail.
|
||||
|
||||
https://core.telegram.org/bots/api#photosize
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, width, height, file_size):
|
||||
self.file_id: str = file_id
|
||||
self.width: int = width
|
||||
self.height: int = height
|
||||
self.file_size: int = file_size
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
file_id = raw_data.get('file_id')
|
||||
width = raw_data.get('width')
|
||||
height = raw_data.get('height')
|
||||
file_size = raw_data.get('file_size')
|
||||
|
||||
return PhotoSize(file_id, width, height, file_size)
|
||||
|
||||
@classmethod
|
||||
def parse_array(cls, photos):
|
||||
return [deserialize(PhotoSize, photo) for photo in photos] if photos else None
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .order_info import OrderInfo
|
||||
from .user import User
|
||||
|
||||
|
||||
class PreCheckoutQuery(Deserializable):
|
||||
"""
|
||||
This object contains information about an incoming pre-checkout query.
|
||||
|
||||
https://core.telegram.org/bots/api#precheckoutquery
|
||||
"""
|
||||
|
||||
def __init__(self, id, from_user, currency, total_amount, invoice_payload, shipping_option_id, order_info):
|
||||
self.id: str = id
|
||||
self.from_user: User = from_user
|
||||
self.currency: str = currency
|
||||
self.total_amount: int = total_amount
|
||||
self.invoice_payload: str = invoice_payload
|
||||
self.shipping_option_id: str = shipping_option_id
|
||||
self.order_info: OrderInfo = order_info
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
id = raw_data.get('id')
|
||||
from_user = User.deserialize(raw_data.get('from'))
|
||||
currency = raw_data.get('currency')
|
||||
total_amount = raw_data.get('total_amount')
|
||||
invoice_payload = raw_data.get('invoice_payload')
|
||||
shipping_option_id = raw_data.get('shipping_option_id')
|
||||
order_info = OrderInfo.deserialize(raw_data.get('order_info'))
|
||||
|
||||
return PreCheckoutQuery(id, from_user, currency, total_amount, invoice_payload, shipping_option_id, order_info)
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
from .base import Serializable
|
||||
|
||||
|
||||
class ReplyKeyboardMarkup(Serializable):
|
||||
"""
|
||||
This object represents a custom keyboard with reply options
|
||||
|
||||
https://core.telegram.org/bots/api#replykeyboardmarkup
|
||||
"""
|
||||
|
||||
def __init__(self, resize_keyboard=None, one_time_keyboard=None, selective=None, row_width=3):
|
||||
self.resize_keyboard = resize_keyboard
|
||||
self.one_time_keyboard = one_time_keyboard
|
||||
self.selective = selective
|
||||
self.row_width = row_width
|
||||
|
||||
self.keyboard = []
|
||||
|
||||
def add(self, *args):
|
||||
i = 1
|
||||
row = []
|
||||
for button in args:
|
||||
if isinstance(button, str):
|
||||
row.append({'text': button})
|
||||
elif isinstance(button, bytes):
|
||||
row.append({'text': button.decode('utf-8')})
|
||||
else:
|
||||
row.append(button.to_json())
|
||||
if i % self.row_width == 0:
|
||||
self.keyboard.append(row)
|
||||
row = []
|
||||
i += 1
|
||||
if len(row) > 0:
|
||||
self.keyboard.append(row)
|
||||
|
||||
def row(self, *args):
|
||||
btn_array = []
|
||||
for button in args:
|
||||
if isinstance(button, str):
|
||||
btn_array.append({'text': button})
|
||||
else:
|
||||
btn_array.append(button.to_json())
|
||||
self.keyboard.append(btn_array)
|
||||
return self
|
||||
|
||||
def to_json(self):
|
||||
return {key: value for key, value in self.__dict__.items() if value and key != 'row_width'}
|
||||
|
||||
|
||||
class KeyboardButton(Serializable):
|
||||
"""
|
||||
This object represents one button of the reply keyboard.
|
||||
|
||||
For simple text buttons String can be used instead of this object to specify text of the button.
|
||||
|
||||
Optional fields are mutually exclusive
|
||||
|
||||
https://core.telegram.org/bots/api#keyboardbutton
|
||||
"""
|
||||
|
||||
def __init__(self, text, request_contact=None, request_location=None):
|
||||
self.text = text
|
||||
self.request_contact = request_contact
|
||||
self.request_location = request_location
|
||||
|
||||
def to_json(self):
|
||||
return self.__dict__
|
||||
|
||||
|
||||
class ReplyKeyboardRemove(Serializable):
|
||||
"""
|
||||
Upon receiving a message with this object,
|
||||
Telegram clients will remove the current custom keyboard and display the default letter-keyboard.
|
||||
|
||||
By default, custom keyboards are displayed until a new keyboard
|
||||
is sent by a bot.
|
||||
|
||||
An exception is made for one-time keyboards that are hidden immediately after the user presses a button
|
||||
|
||||
https://core.telegram.org/bots/api#replykeyboardremove
|
||||
"""
|
||||
|
||||
def __init__(self, selective=None):
|
||||
self.selective = selective
|
||||
|
||||
def to_json(self):
|
||||
json_dict = {'remove_keyboard': True}
|
||||
if self.selective:
|
||||
json_dict['selective'] = True
|
||||
return json_dict
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class ResponseParameters(Deserializable):
|
||||
"""
|
||||
Contains information about why a request was unsuccessfull.
|
||||
|
||||
https://core.telegram.org/bots/api#responseparameters
|
||||
"""
|
||||
|
||||
def __init__(self, migrate_to_chat_id, retry_after):
|
||||
self.migrate_to_chat_id = migrate_to_chat_id
|
||||
self.retry_after = retry_after
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
migrate_to_chat_id = data.get('migrate_to_chat_id')
|
||||
retry_after = data.get('retry_after')
|
||||
|
||||
return ResponseParameters(migrate_to_chat_id, retry_after)
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class ShippingAddress(Deserializable):
|
||||
"""
|
||||
This object represents a shipping address.
|
||||
|
||||
https://core.telegram.org/bots/api#shippingaddress
|
||||
"""
|
||||
|
||||
def __init__(self, country_code, state, city, street_line1, street_line2, post_code):
|
||||
self.country_code: str = country_code
|
||||
self.state: str = state
|
||||
self.city: str = city
|
||||
self.street_line1: str = street_line1
|
||||
self.street_line2: str = street_line2
|
||||
self.post_code: str = post_code
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
country_code = raw_data.get('country_code')
|
||||
state = raw_data.get('state')
|
||||
city = raw_data.get('city')
|
||||
street_line1 = raw_data.get('street_line1')
|
||||
street_line2 = raw_data.get('street_line2')
|
||||
post_code = raw_data.get('post_code')
|
||||
|
||||
return ShippingAddress(country_code, state, city, street_line1, street_line2, post_code)
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
from .base import Serializable
|
||||
|
||||
|
||||
class ShippingOption(Serializable):
|
||||
"""
|
||||
This object represents one shipping option.
|
||||
|
||||
https://core.telegram.org/bots/api#shippingoption
|
||||
"""
|
||||
|
||||
def __init__(self, id, title, prices):
|
||||
self.id = id
|
||||
self.title = title
|
||||
self.prices = prices
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .shipping_address import ShippingAddress
|
||||
from .user import User
|
||||
|
||||
|
||||
class ShippingQuery(Deserializable):
|
||||
"""
|
||||
This object contains information about an incoming shipping query.
|
||||
|
||||
https://core.telegram.org/bots/api#shippingquery
|
||||
"""
|
||||
|
||||
def __init__(self, id, from_user, invoice_payload, shipping_address):
|
||||
self.id: str = id
|
||||
self.from_user: User = from_user
|
||||
self.invoice_payload: str = invoice_payload
|
||||
self.shipping_address: ShippingAddress = shipping_address
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
id = raw_data.get('id')
|
||||
from_user = User.deserialize(raw_data.get('from'))
|
||||
invoice_payload = raw_data.get('invoice_payload')
|
||||
shipping_address = ShippingAddress.deserialize(raw_data.get('shipping_address'))
|
||||
|
||||
return ShippingQuery(id, from_user, invoice_payload, shipping_address)
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .mask_position import MaskPosition
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
class Sticker(Deserializable):
|
||||
"""
|
||||
This object represents a sticker.
|
||||
|
||||
https://core.telegram.org/bots/api#sticker
|
||||
"""
|
||||
|
||||
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
|
||||
def de_json(cls, raw_data):
|
||||
file_id = raw_data.get('file_id')
|
||||
width = raw_data.get('width')
|
||||
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, set_name, mask_position, file_size)
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
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):
|
||||
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)
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .order_info import OrderInfo
|
||||
|
||||
|
||||
class SuccessfulPayment(Deserializable):
|
||||
"""
|
||||
This object contains basic information about a successful payment.
|
||||
|
||||
https://core.telegram.org/bots/api#successfulpayment
|
||||
"""
|
||||
|
||||
def __init__(self, currency, total_amount, invoice_payload, shipping_option_id, order_info,
|
||||
telegram_payment_charge_id, provider_payment_charge_id):
|
||||
self.currency: str = currency
|
||||
self.total_amount: int = total_amount
|
||||
self.invoice_payload: str = invoice_payload
|
||||
self.shipping_option_id: str = shipping_option_id
|
||||
self.order_info: OrderInfo = order_info
|
||||
self.telegram_payment_charge_id: str = telegram_payment_charge_id
|
||||
self.provider_payment_charge_id: str = provider_payment_charge_id
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
currency = raw_data.get('currency')
|
||||
total_amount = raw_data.get('total_amount')
|
||||
invoice_payload = raw_data.get('invoice_payload')
|
||||
shipping_option_id = raw_data.get('shipping_option_id')
|
||||
order_info = OrderInfo.deserialize(raw_data.get('order_info'))
|
||||
telegram_payment_charge_id = raw_data.get('telegram_payment_charge_id')
|
||||
provider_payment_charge_id = raw_data.get('provider_payment_charge_id')
|
||||
|
||||
return SuccessfulPayment(currency, total_amount, invoice_payload, shipping_option_id, order_info,
|
||||
telegram_payment_charge_id, provider_payment_charge_id)
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .callback_query import CallbackQuery
|
||||
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.helper import Helper, ListItem, HelperMode
|
||||
|
||||
|
||||
class Update(Deserializable):
|
||||
"""
|
||||
This object represents an incoming update.
|
||||
|
||||
At most one of the optional parameters can be present in any given update.
|
||||
|
||||
https://core.telegram.org/bots/api#update
|
||||
"""
|
||||
|
||||
def __init__(self, update_id, message, edited_message, channel_post, edited_channel_post, inline_query,
|
||||
chosen_inline_result, callback_query, shipping_query, pre_checkout_query):
|
||||
self.update_id: int = update_id
|
||||
self.message: Message = message
|
||||
self.edited_message: Message = edited_message
|
||||
self.channel_post: Message = channel_post
|
||||
self.edited_channel_post: Message = edited_channel_post
|
||||
self.inline_query: InlineQuery = inline_query
|
||||
self.chosen_inline_result: ChosenInlineResult = chosen_inline_result
|
||||
self.callback_query: CallbackQuery = callback_query
|
||||
self.shipping_query: ShippingQuery = shipping_query
|
||||
self.pre_checkout_query: PreCheckoutQuery = pre_checkout_query
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
update_id = raw_data.get('update_id')
|
||||
message = Message.deserialize(raw_data.get('message'))
|
||||
edited_message = Message.deserialize(raw_data.get('edited_message'))
|
||||
channel_post = Message.deserialize(raw_data.get('channel_post'))
|
||||
edited_channel_post = Message.deserialize(raw_data.get('edited_channel_post'))
|
||||
|
||||
inline_query = InlineQuery.deserialize(raw_data.get('inline_query'))
|
||||
chosen_inline_result = ChosenInlineResult.deserialize(raw_data.get('chosen_inline_result'))
|
||||
callback_query = CallbackQuery.deserialize(raw_data.get('callback_query'))
|
||||
shipping_query = ShippingQuery.deserialize(raw_data.get('shipping_query'))
|
||||
pre_checkout_query = PreCheckoutQuery.deserialize(raw_data.get('pre_checkout_query'))
|
||||
|
||||
return Update(update_id, message, edited_message, channel_post, edited_channel_post, inline_query,
|
||||
chosen_inline_result, callback_query, shipping_query, pre_checkout_query)
|
||||
|
||||
|
||||
class AllowedUpdates(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 = HelperMode.snake_case
|
||||
|
||||
MESSAGE = ListItem() # message
|
||||
EDITED_MESSAGE = ListItem() # edited_message
|
||||
CHANNEL_POST = ListItem() # channel_post
|
||||
EDITED_CHANNEL_POST = ListItem() # edited_channel_post
|
||||
INLINE_QUERY = ListItem() # inline_query
|
||||
CHOSEN_INLINE_QUERY = ListItem() # chosen_inline_result
|
||||
CALLBACK_QUERY = ListItem() # callback_query
|
||||
SHIPPING_QUERY = ListItem() # shipping_query
|
||||
PRE_CHECKOUT_QUERY = ListItem() # pre_checkout_query
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
from ..utils.markdown import link, hlink
|
||||
|
||||
try:
|
||||
import babel
|
||||
except ImportError:
|
||||
babel = None
|
||||
|
||||
from .base import Deserializable
|
||||
|
||||
|
||||
class User(Deserializable):
|
||||
"""
|
||||
This object represents a Telegram user or bot.
|
||||
|
||||
https://core.telegram.org/bots/api#user
|
||||
"""
|
||||
|
||||
def __init__(self, id, is_bot, first_name, last_name, username, language_code):
|
||||
self.id: int = id
|
||||
self.is_bot: bool = is_bot
|
||||
self.first_name: str = first_name
|
||||
self.last_name: str = last_name
|
||||
self.username: str = username
|
||||
self.language_code: str = language_code
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data: str or dict) -> 'User':
|
||||
id = raw_data.get('id')
|
||||
is_bot = raw_data.get('is_bot')
|
||||
first_name = raw_data.get('first_name')
|
||||
last_name = raw_data.get('last_name')
|
||||
username = raw_data.get('username')
|
||||
language_code = raw_data.get('language_code')
|
||||
|
||||
return User(id, is_bot, first_name, last_name, username, language_code)
|
||||
|
||||
@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 menthion 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 hlink(name, self.url)
|
||||
return 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,21 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
class UserProfilePhotos(Deserializable):
|
||||
"""
|
||||
This object represent a user's profile pictures.
|
||||
|
||||
https://core.telegram.org/bots/api#userprofilephotos
|
||||
"""
|
||||
|
||||
def __init__(self, total_count, photos):
|
||||
self.total_count: int = total_count
|
||||
self.photos: [PhotoSize] = photos
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
total_count = raw_data.get('total_count')
|
||||
photos = [PhotoSize.deserialize(item) for item in raw_data.get('photos')]
|
||||
|
||||
return UserProfilePhotos(total_count, photos)
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .location import Location
|
||||
|
||||
|
||||
class Venue(Deserializable):
|
||||
"""
|
||||
This object represents a venue.
|
||||
|
||||
https://core.telegram.org/bots/api#venue
|
||||
"""
|
||||
|
||||
def __init__(self, location, title, address, foursquare_id):
|
||||
self.location: Location = location
|
||||
self.title: str = title
|
||||
self.address: str = address
|
||||
self.foursquare_id: str = foursquare_id
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
location = Location.deserialize(raw_data.get('location'))
|
||||
title = raw_data.get('title')
|
||||
address = raw_data.get('address')
|
||||
foursquare_id = raw_data.get('foursquare_id')
|
||||
|
||||
return Venue(location, title, address, foursquare_id)
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
class Video(Deserializable):
|
||||
"""
|
||||
This object represents a video file.
|
||||
|
||||
https://core.telegram.org/bots/api#video
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, width, height, duration, thumb, mime_type, file_size):
|
||||
self.file_id: str = file_id
|
||||
self.width: int = width
|
||||
self.height: int = height
|
||||
self.duration: int = duration
|
||||
self.thumb: PhotoSize = thumb
|
||||
self.mime_type = mime_type
|
||||
self.file_size: int = file_size
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
file_id = raw_data.get('file_id')
|
||||
width = raw_data.get('width')
|
||||
height = raw_data.get('height')
|
||||
duration = raw_data.get('duration')
|
||||
thumb = PhotoSize.deserialize(raw_data.get('thumb'))
|
||||
mime_type = raw_data.get('mime_type')
|
||||
file_size = raw_data.get('file_size')
|
||||
|
||||
return Video(file_id, width, height, duration, thumb, mime_type, file_size)
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
from .base import Deserializable
|
||||
from .photo_size import PhotoSize
|
||||
|
||||
|
||||
class VideoNote(Deserializable):
|
||||
"""
|
||||
This object represents a video message.
|
||||
|
||||
https://core.telegram.org/bots/api#videonote
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, length, duration, thumb, file_size):
|
||||
self.file_id: str = file_id
|
||||
self.length: int = length
|
||||
self.duration: int = duration
|
||||
self.thumb: PhotoSize = thumb
|
||||
self.file_size: int = file_size
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
file_id = raw_data.get('file_id')
|
||||
length = raw_data.get('length')
|
||||
duration = raw_data.get('duration')
|
||||
thumb = PhotoSize.deserialize(raw_data.get('thumb'))
|
||||
file_size = raw_data.get('file_size')
|
||||
|
||||
return VideoNote(file_id, length, duration, thumb, file_size)
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class Voice(Deserializable):
|
||||
"""
|
||||
This object represents a voice note.
|
||||
|
||||
https://core.telegram.org/bots/api#voice
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, duration, mime_type, file_size):
|
||||
self.file_id: str = file_id
|
||||
self.duration: int = duration
|
||||
self.mime_type: str = mime_type
|
||||
self.file_size: int = file_size
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
file_id = raw_data.get('file_id')
|
||||
duration = raw_data.get('duration')
|
||||
mime_type = raw_data.get('mime_type')
|
||||
file_size = raw_data.get('file_size')
|
||||
|
||||
return Voice(file_id, duration, mime_type, file_size)
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
from .base import Deserializable
|
||||
|
||||
|
||||
class WebhookInfo(Deserializable):
|
||||
"""
|
||||
Contains information about the current status of a webhook.
|
||||
|
||||
https://core.telegram.org/bots/api#webhookinfo
|
||||
"""
|
||||
|
||||
def __init__(self, url, has_custom_certificate, pending_update_count, last_error_date, last_error_message,
|
||||
max_connections, allowed_updates):
|
||||
self.url: str = url
|
||||
self.has_custom_certificate: bool = has_custom_certificate
|
||||
self.pending_update_count: int = pending_update_count
|
||||
self.last_error_date: int = last_error_date
|
||||
self.last_error_message: str = last_error_message
|
||||
self.max_connections: int = max_connections
|
||||
self.allowed_updates: [str] = allowed_updates
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, raw_data):
|
||||
url = raw_data.get('url')
|
||||
has_custom_certificate = raw_data.get('has_custom_certificate')
|
||||
pending_update_count = raw_data.get('pending_update_count')
|
||||
last_error_date = cls._parse_date(raw_data.get('last_error_date'))
|
||||
last_error_message = raw_data.get('last_error_message')
|
||||
max_connections = raw_data.get('max_connections')
|
||||
allowed_updates = raw_data.get('allowed_updates')
|
||||
|
||||
return WebhookInfo(url, has_custom_certificate, pending_update_count, last_error_date, last_error_message,
|
||||
max_connections, allowed_updates)
|
||||
Loading…
Add table
Add a link
Reference in a new issue