41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from astrbot.api.event import AstrMessageEvent
|
|
from astrbot.api.provider import LLMResponse
|
|
from astrbot.api import logger
|
|
from astrbot.core.message.message_event_result import MessageChain,Plain
|
|
from ..tool.pattern import Pattern
|
|
from astrbot.api.star import Star
|
|
import asyncio
|
|
|
|
class TimerService:
|
|
def __init__(self,star:Star) -> None:
|
|
self.star = star
|
|
pass
|
|
|
|
# 解析模板并进行定时
|
|
async def parse(self,event:AstrMessageEvent):
|
|
res = event.get_result()
|
|
if not res:
|
|
return
|
|
|
|
Second:int|None = None
|
|
logger.info("[wait_msg]:开始解析模板")
|
|
|
|
chain = res.chain
|
|
for i in chain :
|
|
if not isinstance(i,Plain) or i.type == "Plain":
|
|
continue
|
|
dump = Pattern(i.text)
|
|
i.text = dump.string
|
|
Second = dump.count
|
|
if not Second is None:
|
|
self.timer(event,Second)
|
|
|
|
yield
|
|
|
|
# 定时:
|
|
def timer(self,event:AstrMessageEvent,Sec:int):
|
|
asyncio.create_task(self.timer_task())
|
|
|
|
async def timer_task(self):
|
|
await asyncio.sleep(1)
|
|
logger.warning("awa现在过去一秒了哦") |