Added native support of MagicFilter

This commit is contained in:
Alex Root Junior 2022-11-06 01:10:32 +02:00
parent 27dea25c52
commit 93a425f528
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
3 changed files with 10 additions and 2 deletions

View file

@ -2,6 +2,8 @@ import abc
import inspect
import typing
from magic_filter import MagicFilter
from ..handler import Handler, FilterObj
@ -25,6 +27,9 @@ def get_filter_spec(dispatcher, filter_: callable):
if not callable(filter_):
raise TypeError('Filter must be callable and/or awaitable!')
if isinstance(filter_, MagicFilter):
filter_ = filter_.resolve
spec = inspect.getfullargspec(filter_)
if 'dispatcher' in spec:
kwargs['dispatcher'] = dispatcher
@ -202,14 +207,14 @@ class BoundFilter(Filter):
You need to implement ``__init__`` method with single argument related with key attribute
and ``check`` method where you need to implement filter logic.
"""
key = None
"""Unique name of the filter argument. You need to override this attribute."""
required = False
"""If :obj:`True` this filter will be added to the all of the registered handlers"""
default = None
"""Default value for configure required filters"""
@classmethod
def validate(cls, full_config: typing.Dict[str, typing.Any]) -> typing.Dict[str, typing.Any]:
"""

View file

@ -324,6 +324,8 @@ class Message(base.TelegramObject):
url += f"c/{self.chat.shifted_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
def link(self, text, as_html=True) -> str:

View file

@ -1,3 +1,4 @@
aiohttp>=3.8.0,<3.9.0
Babel>=2.9.1,<2.10.0
certifi>=2021.10.8
magic-filter>=1.0.9