mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
✨ 更新PriorityLifecycle.on_startup装饰器
This commit is contained in:
parent
f6f4ff1217
commit
b2f02921a4
@ -71,7 +71,7 @@ from public.bag_users t1
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@PriorityLifecycle.on_startup()
|
@PriorityLifecycle.on_startup(priority=5)
|
||||||
async def _():
|
async def _():
|
||||||
await ResourceManager.init_resources()
|
await ResourceManager.init_resources()
|
||||||
"""签到与用户的数据迁移"""
|
"""签到与用户的数据迁移"""
|
||||||
|
|||||||
@ -92,7 +92,7 @@ def migrate(path: Path):
|
|||||||
json.dump(new_data, f, ensure_ascii=False, indent=4)
|
json.dump(new_data, f, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
|
|
||||||
@PriorityLifecycle.on_startup()
|
@PriorityLifecycle.on_startup(priority=5)
|
||||||
def _():
|
def _():
|
||||||
"""数据迁移
|
"""数据迁移
|
||||||
|
|
||||||
|
|||||||
@ -96,7 +96,7 @@ async def _handle_setting(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@PriorityLifecycle.on_startup()
|
@PriorityLifecycle.on_startup(priority=5)
|
||||||
async def _():
|
async def _():
|
||||||
"""
|
"""
|
||||||
初始化插件数据配置
|
初始化插件数据配置
|
||||||
|
|||||||
@ -133,7 +133,7 @@ async def create_schedule(task: Task):
|
|||||||
logger.error(f"动态创建定时任务 {task.name}({task.module}) 失败", e=e)
|
logger.error(f"动态创建定时任务 {task.name}({task.module}) 失败", e=e)
|
||||||
|
|
||||||
|
|
||||||
@PriorityLifecycle.on_startup()
|
@PriorityLifecycle.on_startup(priority=5)
|
||||||
async def _():
|
async def _():
|
||||||
"""
|
"""
|
||||||
初始化插件数据配置
|
初始化插件数据配置
|
||||||
|
|||||||
@ -15,7 +15,7 @@ from zhenxun.utils.manager.priority_manager import PriorityLifecycle
|
|||||||
driver: Driver = nonebot.get_driver()
|
driver: Driver = nonebot.get_driver()
|
||||||
|
|
||||||
|
|
||||||
@PriorityLifecycle.on_startup()
|
@PriorityLifecycle.on_startup(priority=5)
|
||||||
async def update_city():
|
async def update_city():
|
||||||
"""
|
"""
|
||||||
部分插件需要中国省份城市
|
部分插件需要中国省份城市
|
||||||
@ -62,7 +62,7 @@ async def _():
|
|||||||
await update_city()
|
await update_city()
|
||||||
|
|
||||||
|
|
||||||
@PriorityLifecycle.on_startup()
|
@PriorityLifecycle.on_startup(priority=5)
|
||||||
async def _():
|
async def _():
|
||||||
"""开启/禁用插件格式修改"""
|
"""开启/禁用插件格式修改"""
|
||||||
_, is_create = await GroupConsole.get_or_create(group_id=133133133)
|
_, is_create = await GroupConsole.get_or_create(group_id=133133133)
|
||||||
|
|||||||
@ -55,7 +55,7 @@ LG_MESSAGE = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@PriorityLifecycle.on_startup()
|
@PriorityLifecycle.on_startup(priority=5)
|
||||||
async def init_image():
|
async def init_image():
|
||||||
SIGN_RESOURCE_PATH.mkdir(parents=True, exist_ok=True)
|
SIGN_RESOURCE_PATH.mkdir(parents=True, exist_ok=True)
|
||||||
SIGN_TODAY_CARD_PATH.mkdir(exist_ok=True, parents=True)
|
SIGN_TODAY_CARD_PATH.mkdir(exist_ok=True, parents=True)
|
||||||
|
|||||||
@ -32,7 +32,7 @@ driver: Driver = nonebot.get_driver()
|
|||||||
CONNECT_TIME = 0
|
CONNECT_TIME = 0
|
||||||
|
|
||||||
|
|
||||||
@PriorityLifecycle.on_startup()
|
@PriorityLifecycle.on_startup(priority=5)
|
||||||
async def _():
|
async def _():
|
||||||
global CONNECT_TIME
|
global CONNECT_TIME
|
||||||
CONNECT_TIME = int(time.time())
|
CONNECT_TIME = int(time.time())
|
||||||
|
|||||||
@ -22,7 +22,7 @@ router = APIRouter(prefix="/database")
|
|||||||
driver: Driver = nonebot.get_driver()
|
driver: Driver = nonebot.get_driver()
|
||||||
|
|
||||||
|
|
||||||
@PriorityLifecycle.on_startup()
|
@PriorityLifecycle.on_startup(priority=5)
|
||||||
async def _():
|
async def _():
|
||||||
for plugin in nonebot.get_loaded_plugins():
|
for plugin in nonebot.get_loaded_plugins():
|
||||||
module = plugin.name
|
module = plugin.name
|
||||||
|
|||||||
@ -101,6 +101,6 @@ class PluginInitManager:
|
|||||||
logger.error(f"执行: {module_path}:remove 失败", e=e)
|
logger.error(f"执行: {module_path}:remove 失败", e=e)
|
||||||
|
|
||||||
|
|
||||||
@PriorityLifecycle.on_startup()
|
@PriorityLifecycle.on_startup(priority=5)
|
||||||
async def _():
|
async def _():
|
||||||
await PluginInitManager.install_all()
|
await PluginInitManager.install_all()
|
||||||
|
|||||||
@ -15,7 +15,7 @@ class PriorityLifecycle:
|
|||||||
_data: ClassVar[dict[PriorityLifecycleType, dict[int, list[Callable]]]] = {}
|
_data: ClassVar[dict[PriorityLifecycleType, dict[int, list[Callable]]]] = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add(cls, hook_type: PriorityLifecycleType, func: Callable, priority: int = 5):
|
def add(cls, hook_type: PriorityLifecycleType, func: Callable, priority: int):
|
||||||
if hook_type not in cls._data:
|
if hook_type not in cls._data:
|
||||||
cls._data[hook_type] = {}
|
cls._data[hook_type] = {}
|
||||||
if priority not in cls._data[hook_type]:
|
if priority not in cls._data[hook_type]:
|
||||||
@ -23,7 +23,7 @@ class PriorityLifecycle:
|
|||||||
cls._data[hook_type][priority].append(func)
|
cls._data[hook_type][priority].append(func)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def on_startup(cls, *, priority: int = 5):
|
def on_startup(cls, *, priority: int):
|
||||||
def wrapper(func):
|
def wrapper(func):
|
||||||
cls.add(PriorityLifecycleType.STARTUP, func, priority)
|
cls.add(PriorityLifecycleType.STARTUP, func, priority)
|
||||||
return func
|
return func
|
||||||
@ -31,7 +31,7 @@ class PriorityLifecycle:
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def on_shutdown(cls, *, priority: int = 5):
|
def on_shutdown(cls, *, priority: int):
|
||||||
def wrapper(func):
|
def wrapper(func):
|
||||||
cls.add(PriorityLifecycleType.SHUTDOWN, func, priority)
|
cls.add(PriorityLifecycleType.SHUTDOWN, func, priority)
|
||||||
return func
|
return func
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user