mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
Added Regexp Commands Filter
This commit is contained in:
parent
f4a8923c80
commit
d1234880fa
1 changed files with 26 additions and 0 deletions
|
|
@ -132,6 +132,32 @@ class RegexpFilter(Filter):
|
||||||
return bool(self.regexp.search(message.text))
|
return bool(self.regexp.search(message.text))
|
||||||
|
|
||||||
|
|
||||||
|
class RegexpCommandsFilter(AsyncFilter):
|
||||||
|
"""
|
||||||
|
Check commands by regexp in message
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, regexp_commands):
|
||||||
|
self.regexp_commands = [re.compile(command, flags=re.IGNORECASE | re.MULTILINE) for command in regexp_commands]
|
||||||
|
|
||||||
|
async def check(self, message):
|
||||||
|
if not message.is_command():
|
||||||
|
return False
|
||||||
|
|
||||||
|
command = message.text.split()[0][1:]
|
||||||
|
command, _, mention = command.partition('@')
|
||||||
|
|
||||||
|
if mention and mention != (await message.bot.me).username:
|
||||||
|
return False
|
||||||
|
|
||||||
|
for command in self.regexp_commands:
|
||||||
|
search = command.search(message.text)
|
||||||
|
if search:
|
||||||
|
message.conf['regexp_command'] = search
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class ContentTypeFilter(Filter):
|
class ContentTypeFilter(Filter):
|
||||||
"""
|
"""
|
||||||
Check message content type
|
Check message content type
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue