✨ 新增线程安全共享内存储存器
This commit is contained in:
@ -8,7 +8,7 @@ from src.utils.base.data_manager import InstalledPlugin, plugin_db
|
||||
from src.utils.base.resource import load_resources
|
||||
from src.utils.message.tools import check_for_package
|
||||
|
||||
from liteyuki import get_bot, chan
|
||||
from liteyuki import get_bot
|
||||
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
|
||||
|
@ -8,12 +8,9 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
||||
@File : __init__.py.py
|
||||
@Software: PyCharm
|
||||
"""
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
import nonebot
|
||||
|
||||
from liteyuki.comm import Channel, set_channel
|
||||
from liteyuki.core import IS_MAIN_PROCESS
|
||||
from liteyuki.plugin import PluginMetadata
|
||||
from .nb_utils import adapter_manager, driver_manager
|
||||
@ -23,20 +20,15 @@ __plugin_meta__ = PluginMetadata(
|
||||
)
|
||||
|
||||
|
||||
def nb_run(chan_active: "Channel", chan_passive: "Channel", *args, **kwargs):
|
||||
def nb_run(*args, **kwargs):
|
||||
"""
|
||||
初始化NoneBot并运行在子进程
|
||||
Args:
|
||||
|
||||
chan_active:
|
||||
chan_passive:
|
||||
**kwargs:
|
||||
|
||||
Returns:
|
||||
"""
|
||||
# 给子进程传递通道对象
|
||||
set_channel("nonebot-active", chan_active)
|
||||
set_channel("nonebot-passive", chan_passive)
|
||||
|
||||
kwargs.update(kwargs.get("nonebot", {})) # nonebot配置优先
|
||||
nonebot.init(**kwargs)
|
||||
|
@ -7,4 +7,5 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
||||
@Email : snowykami@outlook.com
|
||||
@File : __init__.py
|
||||
@Software: PyCharm
|
||||
"""
|
||||
"""
|
||||
from .after_start import *
|
@ -11,13 +11,15 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
||||
import time
|
||||
|
||||
from liteyuki import get_bot
|
||||
from liteyuki.comm.storage import shared_memory
|
||||
|
||||
liteyuki = get_bot()
|
||||
|
||||
|
||||
@liteyuki.on_after_start
|
||||
@liteyuki.on_before_start
|
||||
def save_startup_timestamp():
|
||||
"""
|
||||
储存启动的时间戳
|
||||
"""
|
||||
startup_timestamp = time.time()
|
||||
shared_memory.set("startup_timestamp", startup_timestamp)
|
||||
|
20
src/nonebot_plugins/ts_ly_comm.py
Normal file
20
src/nonebot_plugins/ts_ly_comm.py
Normal file
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
||||
|
||||
@Time : 2024/8/16 下午8:30
|
||||
@Author : snowykami
|
||||
@Email : snowykami@outlook.com
|
||||
@File : ts_ly_comm.py
|
||||
@Software: PyCharm
|
||||
"""
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from liteyuki.comm.storage import shared_memory
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="轻雪通信测试",
|
||||
description="用于测试轻雪插件通信",
|
||||
usage="不面向用户",
|
||||
)
|
||||
|
||||
print("共享内存数据:", shared_memory.get("startup_timestamp", default=None))
|
Reference in New Issue
Block a user