2020-07-04 22:51:10 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-07-05 20:39:34 +08:00
|
|
|
from nonebot.log import logger
|
|
|
|
from nonebot.event import Event
|
|
|
|
from nonebot.matcher import matchers
|
2020-07-04 22:51:10 +08:00
|
|
|
|
|
|
|
|
2020-07-11 17:32:03 +08:00
|
|
|
async def handle_event(bot, event: Event):
|
2020-07-04 22:51:10 +08:00
|
|
|
# TODO: PreProcess
|
|
|
|
|
|
|
|
for priority in sorted(matchers.keys()):
|
|
|
|
for index in range(len(matchers[priority])):
|
|
|
|
Matcher = matchers[priority][index]
|
2020-07-11 17:32:03 +08:00
|
|
|
try:
|
|
|
|
if not Matcher.check_rule(event):
|
|
|
|
continue
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(
|
|
|
|
f"Rule check failed for matcher {Matcher}. Ignored.")
|
|
|
|
logger.exception(e)
|
2020-07-04 22:51:10 +08:00
|
|
|
continue
|
|
|
|
|
|
|
|
matcher = Matcher()
|
|
|
|
if Matcher.temp:
|
|
|
|
del matchers[priority][index]
|
|
|
|
|
|
|
|
try:
|
|
|
|
await matcher.run(bot, event)
|
|
|
|
except Exception as e:
|
2020-07-11 17:32:03 +08:00
|
|
|
logger.error(f"Running matcher {matcher} failed.")
|
2020-07-04 22:51:10 +08:00
|
|
|
logger.exception(e)
|
|
|
|
return
|