mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-08 17:13:56 +00:00
Backward compatibility - implemented 'func' filter
This commit is contained in:
parent
42913389c0
commit
21908739e9
3 changed files with 23 additions and 2 deletions
|
|
@ -5,7 +5,7 @@ import logging
|
|||
import time
|
||||
import typing
|
||||
|
||||
from .filters import Command, ContentTypeFilter, ExceptionsFilter, FiltersFactory, HashTag, Regexp, \
|
||||
from .filters import Command, ContentTypeFilter, ExceptionsFilter, FiltersFactory, FuncFilter, HashTag, Regexp, \
|
||||
RegexpCommandsFilter, StateFilter, Text
|
||||
from .handler import Handler
|
||||
from .middlewares import MiddlewareManager
|
||||
|
|
@ -108,6 +108,9 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
|
|||
filters_factory.bind(ExceptionsFilter, event_handlers=[
|
||||
self.errors_handlers
|
||||
])
|
||||
filters_factory.bind(FuncFilter, exclude_event_handlers=[
|
||||
self.errors_handlers
|
||||
])
|
||||
|
||||
def __del__(self):
|
||||
self.stop_polling()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from .builtin import Command, CommandHelp, CommandPrivacy, CommandSettings, CommandStart, ContentTypeFilter, \
|
||||
ExceptionsFilter, HashTag, Regexp, RegexpCommandsFilter, StateFilter, Text
|
||||
ExceptionsFilter, FuncFilter, HashTag, Regexp, RegexpCommandsFilter, StateFilter, Text
|
||||
from .factory import FiltersFactory
|
||||
from .filters import AbstractFilter, BoundFilter, Filter, FilterNotPassed, FilterRecord, check_filter, check_filters
|
||||
|
||||
|
|
@ -14,6 +14,7 @@ __all__ = [
|
|||
'ContentTypeFilter',
|
||||
'ExceptionsFilter',
|
||||
'HashTag',
|
||||
'FuncFilter',
|
||||
'Filter',
|
||||
'FilterNotPassed',
|
||||
'FilterRecord',
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from typing import Any, Dict, Iterable, Optional, Union
|
|||
from aiogram import types
|
||||
from aiogram.dispatcher.filters.filters import BoundFilter, Filter
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
from aiogram.utils.deprecated import warn_deprecated
|
||||
|
||||
|
||||
class Command(Filter):
|
||||
|
|
@ -369,6 +370,22 @@ class StateFilter(BoundFilter):
|
|||
return False
|
||||
|
||||
|
||||
class FuncFilter(BoundFilter):
|
||||
key = 'func'
|
||||
|
||||
def __init__(self, dispatcher, func):
|
||||
self.dispatcher = dispatcher
|
||||
self.func = func
|
||||
|
||||
warn_deprecated('"func" filter will be removed in 2.1 version.\n'
|
||||
'Read mode: https://aiogram.readthedocs.io/en/dev-2.x/migration_1_to_2.html#custom-filters',
|
||||
stacklevel=8)
|
||||
|
||||
async def check(self, obj) -> bool:
|
||||
from .filters import check_filter
|
||||
return await check_filter(self.dispatcher, self.func, (obj,))
|
||||
|
||||
|
||||
class ExceptionsFilter(BoundFilter):
|
||||
"""
|
||||
Filter for exceptions
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue