mirror of
				https://github.com/LiteyukiStudio/LiteyukiBot.git
				synced 2025-11-04 11:06:24 +00:00 
			
		
		
		
	fix: 插件列表显示错误问题
This commit is contained in:
		
							
								
								
									
										25
									
								
								liteyuki/liteyuki_main/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								liteyuki/liteyuki_main/__init__.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
import nonebot
 | 
			
		||||
from nonebot.plugin import PluginMetadata
 | 
			
		||||
from liteyuki.utils.language import get_default_lang
 | 
			
		||||
from liteyuki.utils.data_manager import *
 | 
			
		||||
from .loader import *
 | 
			
		||||
from .webdash import *
 | 
			
		||||
from liteyuki.utils.config import config
 | 
			
		||||
 | 
			
		||||
__author__ = "snowykami"
 | 
			
		||||
__plugin_meta__ = PluginMetadata(
 | 
			
		||||
    name="轻雪主程序",
 | 
			
		||||
    description="轻雪主程序插件,包含了许多初始化的功能",
 | 
			
		||||
    usage="",
 | 
			
		||||
    homepage="https://github.com/snowykami/LiteyukiBot",
 | 
			
		||||
    extra={
 | 
			
		||||
            "liteyuki": True,
 | 
			
		||||
            "toggleable": False,
 | 
			
		||||
    }
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
auto_migrate()  # 自动迁移数据库
 | 
			
		||||
 | 
			
		||||
sys_lang = get_default_lang()
 | 
			
		||||
nonebot.logger.info(sys_lang.get("main.current_language", LANG=sys_lang.get("language.name")))
 | 
			
		||||
nonebot.logger.info(sys_lang.get("main.enable_webdash", URL=f"http://127.0.0.1:{config.get('port', 20216)}"))
 | 
			
		||||
							
								
								
									
										22
									
								
								liteyuki/liteyuki_main/loader.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								liteyuki/liteyuki_main/loader.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
import nonebot.plugin
 | 
			
		||||
 | 
			
		||||
from liteyuki.utils.data_manager import InstalledPlugin, plugin_db
 | 
			
		||||
from liteyuki.utils.resource import load_resource_from_dir
 | 
			
		||||
from liteyuki.utils.tools import check_for_package
 | 
			
		||||
 | 
			
		||||
THIS_PLUGIN_NAME = os.path.basename(os.path.dirname(__file__))
 | 
			
		||||
RESOURCE_PATH = "liteyuki/resources"
 | 
			
		||||
load_resource_from_dir(RESOURCE_PATH)
 | 
			
		||||
 | 
			
		||||
nonebot.plugin.load_plugins("liteyuki/plugins")
 | 
			
		||||
nonebot.plugin.load_plugins("plugins")
 | 
			
		||||
 | 
			
		||||
installed_plugins = plugin_db.all(InstalledPlugin)
 | 
			
		||||
if installed_plugins:
 | 
			
		||||
    for installed_plugin in plugin_db.all(InstalledPlugin):
 | 
			
		||||
        if not check_for_package(installed_plugin.module_name):
 | 
			
		||||
            nonebot.logger.error(f"{installed_plugin.module_name} not installed, but in loading database. please run `npm fixup` in chat to reinstall it.")
 | 
			
		||||
        else:
 | 
			
		||||
            nonebot.load_plugin(installed_plugin.module_name)
 | 
			
		||||
							
								
								
									
										91
									
								
								liteyuki/liteyuki_main/webdash.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								liteyuki/liteyuki_main/webdash.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,91 @@
 | 
			
		||||
import nonebot
 | 
			
		||||
import psutil
 | 
			
		||||
from dash import Dash, Input, Output, dcc, html
 | 
			
		||||
from starlette.middleware.wsgi import WSGIMiddleware
 | 
			
		||||
 | 
			
		||||
from liteyuki.utils.language import Language
 | 
			
		||||
from liteyuki.utils.tools import convert_size
 | 
			
		||||
 | 
			
		||||
app = nonebot.get_app()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_system_info():
 | 
			
		||||
    cpu_percent = psutil.cpu_percent()
 | 
			
		||||
    memory_info = psutil.virtual_memory()
 | 
			
		||||
    memory_percent = memory_info.percent
 | 
			
		||||
    return {
 | 
			
		||||
            "cpu_percent"   : cpu_percent,
 | 
			
		||||
            "memory_percent": memory_percent
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.get("/system_info")
 | 
			
		||||
async def system_info():
 | 
			
		||||
    return get_system_info()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
lang = Language()
 | 
			
		||||
dash_app = Dash(__name__)
 | 
			
		||||
dash_app.layout = dash_app.layout = html.Div(children=[
 | 
			
		||||
        html.H1(children=lang.get("main.monitor.title"), style={
 | 
			
		||||
                'textAlign': 'center'
 | 
			
		||||
        }),
 | 
			
		||||
 | 
			
		||||
        dcc.Graph(id='live-update-graph'),
 | 
			
		||||
        dcc.Interval(
 | 
			
		||||
            id='interval-component',
 | 
			
		||||
            interval=1 * 1000,  # in milliseconds
 | 
			
		||||
            n_intervals=0
 | 
			
		||||
        )
 | 
			
		||||
])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@dash_app.callback(Output('live-update-graph', 'figure'),
 | 
			
		||||
                   [Input('interval-component', 'n_intervals')])
 | 
			
		||||
def update_graph_live(n):
 | 
			
		||||
    lang = Language()
 | 
			
		||||
    system_inf = get_system_info()
 | 
			
		||||
    dash_app.layout = html.Div(children=[
 | 
			
		||||
            html.H1(children=lang.get("main.monitor.title"), style={
 | 
			
		||||
                    'textAlign': 'center'
 | 
			
		||||
            }),
 | 
			
		||||
 | 
			
		||||
            dcc.Graph(id='live-update-graph'),
 | 
			
		||||
            dcc.Interval(
 | 
			
		||||
                id='interval-component',
 | 
			
		||||
                interval=2 * 1000,  # in milliseconds
 | 
			
		||||
                n_intervals=0
 | 
			
		||||
            )
 | 
			
		||||
    ])
 | 
			
		||||
    mem = psutil.virtual_memory()
 | 
			
		||||
    cpu_f = psutil.cpu_freq()
 | 
			
		||||
    figure = {
 | 
			
		||||
            'data'  : [
 | 
			
		||||
                    {
 | 
			
		||||
                            'x'   : [f"{cpu_f.current / 1000:.2f}GHz {psutil.cpu_count(logical=False)}c{psutil.cpu_count()}t"],
 | 
			
		||||
                            'y'   : [system_inf['cpu_percent']],
 | 
			
		||||
                            'type': 'bar',
 | 
			
		||||
                            'name': f"{lang.get('main.monitor.cpu')} {lang.get('main.monitor.usage')}"
 | 
			
		||||
 | 
			
		||||
                    },
 | 
			
		||||
                    {
 | 
			
		||||
                            'x'   : [f"{convert_size(mem.used, add_unit=False)}/{convert_size(mem.total)}({mem.used / mem.total * 100:.2f}%)"],
 | 
			
		||||
                            'y'   : [system_inf['memory_percent']],
 | 
			
		||||
                            'type': 'bar',
 | 
			
		||||
                            'name': f"{lang.get('main.monitor.memory')} {lang.get('main.monitor.usage')}"
 | 
			
		||||
                    },
 | 
			
		||||
            ],
 | 
			
		||||
            'layout': {
 | 
			
		||||
                    'title': lang.get('main.monitor.description'),
 | 
			
		||||
                    # 'xaxis': {
 | 
			
		||||
                    #         'range': [0, 10]
 | 
			
		||||
                    #         },  # 设置x轴的范围
 | 
			
		||||
                    'yaxis': {
 | 
			
		||||
                            'range': [0, 100]
 | 
			
		||||
                    },  # 设置y轴的范围
 | 
			
		||||
            }
 | 
			
		||||
    }
 | 
			
		||||
    return figure
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
app.mount("/", WSGIMiddleware(dash_app.server))
 | 
			
		||||
		Reference in New Issue
	
	Block a user