mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Added native support of MagicFilter
This commit is contained in:
parent
27dea25c52
commit
93a425f528
3 changed files with 10 additions and 2 deletions
|
|
@ -2,6 +2,8 @@ import abc
|
||||||
import inspect
|
import inspect
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
from magic_filter import MagicFilter
|
||||||
|
|
||||||
from ..handler import Handler, FilterObj
|
from ..handler import Handler, FilterObj
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -25,6 +27,9 @@ def get_filter_spec(dispatcher, filter_: callable):
|
||||||
if not callable(filter_):
|
if not callable(filter_):
|
||||||
raise TypeError('Filter must be callable and/or awaitable!')
|
raise TypeError('Filter must be callable and/or awaitable!')
|
||||||
|
|
||||||
|
if isinstance(filter_, MagicFilter):
|
||||||
|
filter_ = filter_.resolve
|
||||||
|
|
||||||
spec = inspect.getfullargspec(filter_)
|
spec = inspect.getfullargspec(filter_)
|
||||||
if 'dispatcher' in spec:
|
if 'dispatcher' in spec:
|
||||||
kwargs['dispatcher'] = dispatcher
|
kwargs['dispatcher'] = dispatcher
|
||||||
|
|
@ -202,14 +207,14 @@ class BoundFilter(Filter):
|
||||||
You need to implement ``__init__`` method with single argument related with key attribute
|
You need to implement ``__init__`` method with single argument related with key attribute
|
||||||
and ``check`` method where you need to implement filter logic.
|
and ``check`` method where you need to implement filter logic.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = None
|
key = None
|
||||||
"""Unique name of the filter argument. You need to override this attribute."""
|
"""Unique name of the filter argument. You need to override this attribute."""
|
||||||
required = False
|
required = False
|
||||||
"""If :obj:`True` this filter will be added to the all of the registered handlers"""
|
"""If :obj:`True` this filter will be added to the all of the registered handlers"""
|
||||||
default = None
|
default = None
|
||||||
"""Default value for configure required filters"""
|
"""Default value for configure required filters"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate(cls, full_config: typing.Dict[str, typing.Any]) -> typing.Dict[str, typing.Any]:
|
def validate(cls, full_config: typing.Dict[str, typing.Any]) -> typing.Dict[str, typing.Any]:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -324,6 +324,8 @@ class Message(base.TelegramObject):
|
||||||
url += f"c/{self.chat.shifted_id}/"
|
url += f"c/{self.chat.shifted_id}/"
|
||||||
url += f"{self.message_id}"
|
url += f"{self.message_id}"
|
||||||
|
|
||||||
|
if self.is_topic_message and self.message_thread_id:
|
||||||
|
url += f"?topic={self.message_thread_id}"
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def link(self, text, as_html=True) -> str:
|
def link(self, text, as_html=True) -> str:
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
aiohttp>=3.8.0,<3.9.0
|
aiohttp>=3.8.0,<3.9.0
|
||||||
Babel>=2.9.1,<2.10.0
|
Babel>=2.9.1,<2.10.0
|
||||||
certifi>=2021.10.8
|
certifi>=2021.10.8
|
||||||
|
magic-filter>=1.0.9
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue