添加对主流框架的消息io支持

This commit is contained in:
2024-08-20 06:20:41 +08:00
parent 237789e0d4
commit 0c942d9806
26 changed files with 267 additions and 192 deletions

View File

@ -8,11 +8,40 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@File : on.py
@Software: PyCharm
"""
import threading
from queue import Queue
from liteyuki.comm.storage import shared_memory
from liteyuki.log import logger
from liteyuki.message.event import Event
from liteyuki.message.matcher import Matcher
from liteyuki.message.rule import Rule
_matcher_list: list[Matcher] = []
_queue: Queue = Queue()
def on_message(permission) -> Matcher:
pass
@shared_memory.on_subscriber_receive("event_to_liteyuki")
async def _(event: Event):
current_priority = -1
for i, matcher in enumerate(_matcher_list):
logger.info(f"Running matcher {matcher} for event: {event}")
await matcher.run(event)
# 同优先级不阻断,不同优先级阻断
if current_priority != matcher.priority:
current_priority = matcher.priority
if matcher.block:
break
def on_message(rule: Rule = Rule(), priority: int = 0, block: bool = True) -> Matcher:
matcher = Matcher(rule, priority, block)
# 按照优先级插入
for i, m in enumerate(_matcher_list):
if m.priority < matcher.priority:
_matcher_list.insert(i, matcher)
break
else:
_matcher_list.append(matcher)
return matcher