feat:doc
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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
|
||||
|
||||
# 解析模板并进行定时
|
||||
def parse(self,event:AstrMessageEvent):
|
||||
res = event.get_result()
|
||||
if not res:
|
||||
logger.info("[wait_msg]:解析失败:没拿到消息链")
|
||||
return
|
||||
|
||||
Second:int|None = None
|
||||
logger.info("[wait_msg]:开始解析模板")
|
||||
|
||||
for index,i in enumerate(res.chain) :
|
||||
logger.info(f"获得消息链类型:{i.type}内容:{i}")
|
||||
if not isinstance(i,Plain) or not i.type == "Plain":
|
||||
continue
|
||||
dump = Pattern(i.text)
|
||||
i.text = dump.string
|
||||
Second = dump.count
|
||||
# 改变信息
|
||||
res.chain[index] = i
|
||||
|
||||
event.set_result(res)
|
||||
if not Second is None:
|
||||
self.timer(event,Second)
|
||||
return
|
||||
|
||||
|
||||
# 定时:
|
||||
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现在过去一秒了哦")
|
||||
Reference in New Issue
Block a user