mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-09 17:33:44 +00:00
regexp filter for callback query #19
This commit is contained in:
parent
d2d8f4b51c
commit
5467d91cf8
1 changed files with 8 additions and 5 deletions
|
|
@ -2,7 +2,7 @@ import asyncio
|
|||
import inspect
|
||||
import re
|
||||
|
||||
from ..types import ContentType
|
||||
from ..types import CallbackQuery, ContentType, Message
|
||||
from ..utils import context
|
||||
from ..utils.helper import Helper, HelperMode, Item
|
||||
|
||||
|
|
@ -127,9 +127,12 @@ class RegexpFilter(Filter):
|
|||
def __init__(self, regexp):
|
||||
self.regexp = re.compile(regexp, flags=re.IGNORECASE | re.MULTILINE)
|
||||
|
||||
def check(self, message):
|
||||
if message.text:
|
||||
return bool(self.regexp.search(message.text))
|
||||
def check(self, obj):
|
||||
if isinstance(obj, Message) and obj.text:
|
||||
return bool(self.regexp.search(obj.text))
|
||||
elif isinstance(obj, CallbackQuery) and obj.data:
|
||||
return bool(self.regexp.search(obj.data))
|
||||
return False
|
||||
|
||||
|
||||
class RegexpCommandsFilter(AsyncFilter):
|
||||
|
|
@ -168,7 +171,7 @@ class ContentTypeFilter(Filter):
|
|||
|
||||
def check(self, message):
|
||||
return ContentType.ANY[0] in self.content_types or \
|
||||
message.content_type in self.content_types
|
||||
message.content_type in self.content_types
|
||||
|
||||
|
||||
class CancelFilter(Filter):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue