LiteyukiBot/docs/dev/api/bot/lifespan.md

171 lines
2.2 KiB
Markdown
Raw Normal View History

2024-08-19 01:43:46 +00:00
---
title: liteyuki.bot.lifespan
order: 1
icon: laptop-code
category: API
---
### ***def*** `run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None`
运行函数
Args:
2024-08-19 01:55:47 +00:00
funcs:
2024-08-19 01:43:46 +00:00
Returns:
2024-08-19 01:55:47 +00:00
### ***class*** `Lifespan`
2024-08-19 01:43:46 +00:00
###   ***def*** `__init__(self) -> None`
 轻雪生命周期管理,启动、停止、重启
2024-08-19 01:55:47 +00:00
###   ***@staticmethod***
###   ***def*** `run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None`
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
 运行函数
2024-08-19 01:43:46 +00:00
Args:
2024-08-19 01:55:47 +00:00
funcs:
2024-08-19 01:43:46 +00:00
Returns:
###   ***def*** `on_before_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC`
2024-08-19 01:55:47 +00:00
 注册启动时的函数
2024-08-19 01:43:46 +00:00
Args:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
func:
Returns:
2024-08-19 01:55:47 +00:00
LIFESPAN_FUNC:
2024-08-19 01:43:46 +00:00
###   ***def*** `on_after_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC`
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
 注册启动时的函数
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
Args:
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
func:
2024-08-19 01:43:46 +00:00
Returns:
2024-08-19 01:55:47 +00:00
LIFESPAN_FUNC:
2024-08-19 01:43:46 +00:00
###   ***def*** `on_before_process_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC`
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
 注册停止前的函数
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
Args:
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
func:
2024-08-19 01:43:46 +00:00
Returns:
2024-08-19 01:55:47 +00:00
LIFESPAN_FUNC:
2024-08-19 01:43:46 +00:00
###   ***def*** `on_after_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC`
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
 注册停止后的函数
2024-08-19 01:43:46 +00:00
Args:
func:
Returns:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
LIFESPAN_FUNC:
###   ***def*** `on_before_process_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC`
2024-08-19 01:55:47 +00:00
 注册重启时的函数
2024-08-19 01:43:46 +00:00
Args:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
func:
Returns:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
LIFESPAN_FUNC:
###   ***def*** `on_after_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC`
2024-08-19 01:55:47 +00:00
 注册重启后的函数
2024-08-19 01:43:46 +00:00
Args:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
func:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
Returns:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
LIFESPAN_FUNC:
###   ***def*** `on_after_nonebot_init(self, func: Any) -> None`
2024-08-19 01:55:47 +00:00
 注册 NoneBot 初始化后的函数
2024-08-19 01:43:46 +00:00
Args:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
func:
Returns:
###   ***def*** `before_start(self) -> None`
2024-08-19 01:55:47 +00:00
 启动前
2024-08-19 01:43:46 +00:00
Returns:
###   ***def*** `after_start(self) -> None`
2024-08-19 01:55:47 +00:00
 启动后
2024-08-19 01:43:46 +00:00
Returns:
###   ***def*** `before_process_shutdown(self) -> None`
2024-08-19 01:55:47 +00:00
 停止前
2024-08-19 01:43:46 +00:00
Returns:
###   ***def*** `after_shutdown(self) -> None`
2024-08-19 01:55:47 +00:00
 停止后
2024-08-19 01:43:46 +00:00
Returns:
###   ***def*** `before_process_restart(self) -> None`
2024-08-19 01:55:47 +00:00
 重启前
2024-08-19 01:43:46 +00:00
Returns:
###   ***def*** `after_restart(self) -> None`
2024-08-19 01:55:47 +00:00
 重启后
2024-08-19 01:43:46 +00:00
Returns:
### ***var*** `tasks = []`
### ***var*** `loop = asyncio.get_event_loop()`
### ***var*** `loop = asyncio.new_event_loop()`