mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +00:00
Add message type (not full)
This commit is contained in:
parent
06f46c5e6a
commit
80305c326b
1 changed files with 133 additions and 0 deletions
133
aiogram/types/message.py
Normal file
133
aiogram/types/message.py
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
import datetime
|
||||
|
||||
from aiogram.types import Deserializable
|
||||
from aiogram.types.chat import Chat
|
||||
from aiogram.types.user import User
|
||||
|
||||
|
||||
class Message(Deserializable):
|
||||
__slots__ = (
|
||||
'data', 'message_id', 'from', 'date', 'chat', 'forward_from', 'forward_from_chat', 'forward_from_message_id',
|
||||
'forward_date', 'reply_to_message', 'edit_date', 'text', 'entities', 'audio', 'document', 'game', 'photo',
|
||||
'sticker', 'video', 'voice', 'video_note', 'new_chat_members', 'caption', 'contact', 'location', 'venue',
|
||||
'new_chat_member', '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')
|
||||
|
||||
def __init__(self, data, message_id, from_user, date, chat, forward_from, forward_from_chat,
|
||||
forward_from_message_id, forward_date, reply_to_message, edit_date, text, entities, audio, document,
|
||||
game, photo, sticker, video, voice, video_note, new_chat_members, caption, contact, location, venue,
|
||||
new_chat_member, 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):
|
||||
self.data = data
|
||||
|
||||
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_date: datetime.datetime = forward_date
|
||||
self.reply_to_message: Message = reply_to_message
|
||||
self.edit_date: datetime.datetime = edit_date
|
||||
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.new_chat_member = new_chat_member
|
||||
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
|
||||
|
||||
@classmethod
|
||||
def _parse_date(cls, unix_time):
|
||||
return datetime.datetime.fromtimestamp(unix_time)
|
||||
|
||||
@classmethod
|
||||
def _parse_user(cls, user):
|
||||
return User.de_json(user)
|
||||
|
||||
@classmethod
|
||||
def _parse_chat(cls, chat):
|
||||
return Chat.de_json(chat)
|
||||
|
||||
@classmethod
|
||||
def _parse_message(cls, message):
|
||||
return Message.de_json(message)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data):
|
||||
data = cls.check_json(data)
|
||||
|
||||
message_id = data.get('message_id')
|
||||
from_user = data.get('from')
|
||||
date = cls._parse_date(data.get('date', 0))
|
||||
chat = cls._parse_chat(data.get('chat', {}))
|
||||
forward_from = cls._parse_user(data.get('forward_from', {}))
|
||||
forward_from_chat = cls._parse_chat(data.get('forward_from_chat', {}))
|
||||
forward_from_message_id = data.get('forward_from_message_id')
|
||||
forward_date = cls._parse_date(data.get('forward_date', 0))
|
||||
reply_to_message = cls._parse_message(data.get('reply_to_message', {}))
|
||||
edit_date = cls._parse_date(data.get('edit_date', 0))
|
||||
text = data.get('text')
|
||||
|
||||
entities = data.get('entities')
|
||||
audio = data.get('audio')
|
||||
document = data.get('document')
|
||||
game = data.get('game')
|
||||
photo = data.get('photo')
|
||||
sticker = data.get('sticker')
|
||||
video = data.get('video')
|
||||
voice = data.get('voice')
|
||||
video_note = data.get('video_note')
|
||||
new_chat_members = data.get('new_chat_members')
|
||||
caption = data.get('caption')
|
||||
contact = data.get('contact')
|
||||
location = data.get('location')
|
||||
venue = data.get('venue')
|
||||
new_chat_member = data.get('new_chat_member')
|
||||
left_chat_member = data.get('left_chat_member')
|
||||
new_chat_title = data.get('new_chat_title')
|
||||
new_chat_photo = data.get('new_chat_photo')
|
||||
delete_chat_photo = data.get('delete_chat_photo')
|
||||
group_chat_created = data.get('group_chat_created')
|
||||
supergroup_chat_created = data.get('supergroup_chat_created')
|
||||
channel_chat_created = data.get('channel_chat_created')
|
||||
migrate_to_chat_id = data.get('migrate_to_chat_id')
|
||||
migrate_from_chat_id = data.get('migrate_from_chat_id')
|
||||
pinned_message = data.get('pinned_message')
|
||||
invoice = data.get('invoice')
|
||||
successful_payment = data.get('successful_payment')
|
||||
|
||||
return Message(data, message_id, from_user, date, chat, forward_from, forward_from_chat,
|
||||
forward_from_message_id, forward_date, reply_to_message, edit_date, text, entities, audio,
|
||||
document, game, photo, sticker, video, voice, video_note, new_chat_members, caption, contact,
|
||||
location, venue, new_chat_member, 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)
|
||||
|
||||
def is_command(self):
|
||||
return self.text and self.text.startswith('/')
|
||||
Loading…
Add table
Add a link
Reference in a new issue