nonebot2/nonebot/message.py
2020-07-05 20:39:51 +08:00

27 lines
698 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from nonebot.log import logger
from nonebot.event import Event
from nonebot.matcher import matchers
async def handle_message(bot, event: Event):
# TODO: PreProcess
for priority in sorted(matchers.keys()):
for index in range(len(matchers[priority])):
Matcher = matchers[priority][index]
if not Matcher.check_rule(event):
continue
matcher = Matcher()
if Matcher.temp:
del matchers[priority][index]
try:
await matcher.run(bot, event)
except Exception as e:
logger.exception(e)
return