mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +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 inspect
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from ..types import ContentType
|
from ..types import CallbackQuery, ContentType, Message
|
||||||
from ..utils import context
|
from ..utils import context
|
||||||
from ..utils.helper import Helper, HelperMode, Item
|
from ..utils.helper import Helper, HelperMode, Item
|
||||||
|
|
||||||
|
|
@ -127,9 +127,12 @@ class RegexpFilter(Filter):
|
||||||
def __init__(self, regexp):
|
def __init__(self, regexp):
|
||||||
self.regexp = re.compile(regexp, flags=re.IGNORECASE | re.MULTILINE)
|
self.regexp = re.compile(regexp, flags=re.IGNORECASE | re.MULTILINE)
|
||||||
|
|
||||||
def check(self, message):
|
def check(self, obj):
|
||||||
if message.text:
|
if isinstance(obj, Message) and obj.text:
|
||||||
return bool(self.regexp.search(message.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):
|
class RegexpCommandsFilter(AsyncFilter):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue