nonebot2/filter.py

23 lines
428 B
Python
Raw Normal View History

2016-12-08 21:58:49 +08:00
_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
2017-01-02 13:38:58 +08:00
def add_filter(func, priority=10):
2016-12-08 21:58:49 +08:00
_filters.append((priority, func))
2017-01-02 13:38:58 +08:00
def as_filter(priority=10):
def decorator(func):
add_filter(func, priority)
return func
return decorator