mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 09:05:04 +08:00
23 lines
428 B
Python
23 lines
428 B
Python
_filters = []
|
|
|
|
|
|
def apply_filters(ctx_msg):
|
|
filters = sorted(_filters, key=lambda x: x[0], reverse=True)
|
|
for f in filters:
|
|
r = f[1](ctx_msg)
|
|
if r is False:
|
|
return False
|
|
return True
|
|
|
|
|
|
def add_filter(func, priority=10):
|
|
_filters.append((priority, func))
|
|
|
|
|
|
def as_filter(priority=10):
|
|
def decorator(func):
|
|
add_filter(func, priority)
|
|
return func
|
|
|
|
return decorator
|