mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-09 09:22:03 +00:00
Provide more content types and and allow to handle all (ContentType.ALL) types of messages.
This commit is contained in:
parent
ff6ee0723f
commit
798038484f
3 changed files with 39 additions and 20 deletions
|
|
@ -17,6 +17,7 @@ log = logging.getLogger(__name__)
|
|||
|
||||
MODE = 'MODE'
|
||||
LONG_POOLING = 'long-pooling'
|
||||
UPDATE_OBJECT = 'update_object'
|
||||
|
||||
|
||||
class Dispatcher:
|
||||
|
|
@ -112,6 +113,8 @@ class Dispatcher:
|
|||
try:
|
||||
self.last_update_id = update.update_id
|
||||
has_context = context.check_configured()
|
||||
if has_context:
|
||||
context.set_value(UPDATE_OBJECT, update)
|
||||
if update.message:
|
||||
if has_context:
|
||||
state = self.storage.get_state(chat=update.message.chat.id,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import inspect
|
||||
import re
|
||||
|
||||
from aiogram.utils import context
|
||||
from ..types import ContentType
|
||||
from ..utils import context
|
||||
from ..utils.helper import Helper, HelperMode, Item
|
||||
|
||||
USER_STATE = 'USER_STATE'
|
||||
|
|
@ -79,7 +80,8 @@ class ContentTypeFilter(Filter):
|
|||
self.content_types = content_types
|
||||
|
||||
def check(self, message):
|
||||
return message.content_type in self.content_types
|
||||
return ContentType.ANY[0] in self.content_types or \
|
||||
message.content_type in self.content_types
|
||||
|
||||
|
||||
class CancelFilter(Filter):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import datetime
|
||||
import typing
|
||||
import functools
|
||||
|
||||
from aiogram.utils import helper
|
||||
from . import base
|
||||
from . import fields
|
||||
from .audio import Audio
|
||||
|
|
@ -20,6 +20,7 @@ from .venue import Venue
|
|||
from .video import Video
|
||||
from .video_note import VideoNote
|
||||
from .voice import Voice
|
||||
from ..utils import helper
|
||||
|
||||
|
||||
class Message(base.TelegramObject):
|
||||
|
|
@ -70,30 +71,37 @@ class Message(base.TelegramObject):
|
|||
successful_payment: SuccessfulPayment = fields.Field(base=SuccessfulPayment)
|
||||
|
||||
@property
|
||||
@functools.lru_cache()
|
||||
def content_type(self):
|
||||
if self.text:
|
||||
return ContentType.TEXT[0]
|
||||
elif self.audio:
|
||||
if self.audio:
|
||||
return ContentType.AUDIO[0]
|
||||
elif self.document:
|
||||
if self.document:
|
||||
return ContentType.DOCUMENT[0]
|
||||
elif self.game:
|
||||
if self.game:
|
||||
return ContentType.GAME[0]
|
||||
elif self.photo:
|
||||
if self.photo:
|
||||
return ContentType.PHOTO[0]
|
||||
elif self.sticker:
|
||||
if self.sticker:
|
||||
return ContentType.STICKER[0]
|
||||
elif self.video:
|
||||
if self.video:
|
||||
return ContentType.VIDEO[0]
|
||||
elif self.voice:
|
||||
if self.video_note:
|
||||
return ContentType.VIDEO_NOTE[0]
|
||||
if self.voice:
|
||||
return ContentType.VOICE[0]
|
||||
elif self.new_chat_members:
|
||||
if self.contact:
|
||||
return ContentType.CONTACT[0]
|
||||
if self.location:
|
||||
return ContentType.LOCATION[0]
|
||||
if self.venue:
|
||||
return ContentType.VENUE[0]
|
||||
if self.new_chat_members:
|
||||
return ContentType.NEW_CHAT_MEMBERS[0]
|
||||
elif self.left_chat_member:
|
||||
return ContentType.LEFT_CHAT_MEMBER[0]
|
||||
elif self.invoice:
|
||||
if self.invoice:
|
||||
return ContentType.INVOICE[0]
|
||||
elif self.successful_payment:
|
||||
if self.successful_payment:
|
||||
return ContentType.SUCCESSFUL_PAYMENT[0]
|
||||
else:
|
||||
return ContentType.UNKNOWN[0]
|
||||
|
|
@ -225,12 +233,14 @@ class ContentType(helper.Helper):
|
|||
:key: PHOTO
|
||||
:key: STICKER
|
||||
:key: VIDEO
|
||||
:key: VIDEO_NOTE
|
||||
:key: VOICE
|
||||
:key: CONTACT
|
||||
:key: LOCATION
|
||||
:key: VENUE
|
||||
:key: NEW_CHAT_MEMBERS
|
||||
:key: LEFT_CHAT_MEMBER
|
||||
:key: INVOICE
|
||||
:key: SUCCESSFUL_PAYMENT
|
||||
:key: UNKNOWN
|
||||
"""
|
||||
mode = helper.HelperMode.snake_case
|
||||
|
||||
|
|
@ -241,13 +251,17 @@ class ContentType(helper.Helper):
|
|||
PHOTO = helper.ListItem() # photo
|
||||
STICKER = helper.ListItem() # sticker
|
||||
VIDEO = helper.ListItem() # video
|
||||
VIDEO_NOTE = helper.ListItem() # video_note
|
||||
VOICE = helper.ListItem() # voice
|
||||
NEW_CHAT_MEMBERS = helper.ListItem() # new_chat_members
|
||||
LEFT_CHAT_MEMBER = helper.ListItem() # left_chat_member
|
||||
CONTACT = helper.ListItem() # contact
|
||||
LOCATION = helper.ListItem() # location
|
||||
VENUE = helper.ListItem() # venue
|
||||
NEW_CHAT_MEMBERS = helper.ListItem() # new_chat_member
|
||||
INVOICE = helper.ListItem() # invoice
|
||||
SUCCESSFUL_PAYMENT = helper.ListItem() # successful_payment
|
||||
|
||||
UNKNOWN = 'unknown'
|
||||
UNKNOWN = helper.ListItem() # unknown
|
||||
ANY = helper.ListItem() # any
|
||||
|
||||
|
||||
class ParseMode(helper.Helper):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue