mirror of
				https://github.com/LiteyukiStudio/LiteyukiBot.git
				synced 2025-11-04 02:56:23 +00:00 
			
		
		
		
	feat: 优化了排版和渲染
This commit is contained in:
		@@ -17,6 +17,18 @@ __plugin_meta__ = PluginMetadata(
 | 
			
		||||
    }
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
print("\033[34m" + r"""
 | 
			
		||||
 __        ______  ________  ________  __      __  __    __  __    __  ______ 
 | 
			
		||||
/  |      /      |/        |/        |/  \    /  |/  |  /  |/  |  /  |/      |
 | 
			
		||||
$$ |      $$$$$$/ $$$$$$$$/ $$$$$$$$/ $$  \  /$$/ $$ |  $$ |$$ | /$$/ $$$$$$/ 
 | 
			
		||||
$$ |        $$ |     $$ |   $$ |__     $$  \/$$/  $$ |  $$ |$$ |/$$/    $$ |  
 | 
			
		||||
$$ |        $$ |     $$ |   $$    |     $$  $$/   $$ |  $$ |$$  $$<     $$ |  
 | 
			
		||||
$$ |        $$ |     $$ |   $$$$$/       $$$$/    $$ |  $$ |$$$$$  \    $$ |  
 | 
			
		||||
$$ |_____  _$$ |_    $$ |   $$ |_____     $$ |    $$ \__$$ |$$ |$$  \  _$$ |_ 
 | 
			
		||||
$$       |/ $$   |   $$ |   $$       |    $$ |    $$    $$/ $$ | $$  |/ $$   |
 | 
			
		||||
$$$$$$$$/ $$$$$$/    $$/    $$$$$$$$/     $$/      $$$$$$/  $$/   $$/ $$$$$$/ 
 | 
			
		||||
""" + "\033[0m")
 | 
			
		||||
 | 
			
		||||
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)}"))
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
import base64
 | 
			
		||||
from typing import Any
 | 
			
		||||
 | 
			
		||||
import nonebot
 | 
			
		||||
import pip
 | 
			
		||||
from git import Repo
 | 
			
		||||
from nonebot import Bot, require, get_driver
 | 
			
		||||
@@ -13,12 +12,10 @@ from liteyuki.utils.data_manager import StoredConfig, common_db
 | 
			
		||||
from liteyuki.utils.language import get_user_lang
 | 
			
		||||
from liteyuki.utils.ly_typing import T_Bot, T_MessageEvent
 | 
			
		||||
from liteyuki.utils.message import Markdown as md
 | 
			
		||||
from .reloader import Reloader
 | 
			
		||||
from liteyuki.utils import htmlrender
 | 
			
		||||
from liteyuki.utils.reloader import Reloader
 | 
			
		||||
 | 
			
		||||
require("nonebot_plugin_alconna"), require("nonebot_plugin_htmlrender")
 | 
			
		||||
from nonebot_plugin_alconna import on_alconna, Alconna, Args, Subcommand, Arparma
 | 
			
		||||
from nonebot_plugin_htmlrender import html_to_pic
 | 
			
		||||
 | 
			
		||||
driver = get_driver()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,67 +0,0 @@
 | 
			
		||||
import threading
 | 
			
		||||
from multiprocessing import get_context
 | 
			
		||||
 | 
			
		||||
import nonebot
 | 
			
		||||
from nonebot import logger
 | 
			
		||||
from typing import List, Optional
 | 
			
		||||
 | 
			
		||||
from nonebot import get_driver
 | 
			
		||||
from pydantic import BaseSettings
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
reboot_grace_time_limit: int = 20
 | 
			
		||||
 | 
			
		||||
_nb_run = nonebot.run
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Reloader:
 | 
			
		||||
    event: threading.Event = None
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def reload(cls, delay: int = 0):
 | 
			
		||||
        if cls.event is None:
 | 
			
		||||
            raise RuntimeError()
 | 
			
		||||
        if delay > 0:
 | 
			
		||||
            threading.Timer(delay, function=cls.event.set).start()
 | 
			
		||||
            return
 | 
			
		||||
        cls.event.set()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _run(ev: threading.Event, *args, **kwargs):
 | 
			
		||||
    Reloader.event = ev
 | 
			
		||||
    _nb_run(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def run(*args, **kwargs):
 | 
			
		||||
    should_exit = False
 | 
			
		||||
    ctx = get_context("spawn")
 | 
			
		||||
    while not should_exit:
 | 
			
		||||
        event = ctx.Event()
 | 
			
		||||
        process = ctx.Process(
 | 
			
		||||
            target=_run,
 | 
			
		||||
            args=(
 | 
			
		||||
                    event,
 | 
			
		||||
                    *args,
 | 
			
		||||
            ),
 | 
			
		||||
            kwargs=kwargs,
 | 
			
		||||
        )
 | 
			
		||||
        process.start()
 | 
			
		||||
        while not should_exit:
 | 
			
		||||
            if event.wait(1):
 | 
			
		||||
                logger.info("Receive reboot event")
 | 
			
		||||
                process.terminate()
 | 
			
		||||
                process.join(reboot_grace_time_limit)
 | 
			
		||||
                if process.is_alive():
 | 
			
		||||
                    logger.warning(
 | 
			
		||||
                        f"Cannot shutdown gracefully in {reboot_grace_time_limit} second, force kill process."
 | 
			
		||||
                    )
 | 
			
		||||
                    process.kill()
 | 
			
		||||
                break
 | 
			
		||||
            elif process.is_alive():
 | 
			
		||||
                continue
 | 
			
		||||
            else:
 | 
			
		||||
                # Process stoped without setting event
 | 
			
		||||
                should_exit = True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
nonebot.run = run
 | 
			
		||||
@@ -127,7 +127,8 @@ async def _(bot: T_Bot, event: T_MessageEvent):
 | 
			
		||||
    image_bytes = await template2image(
 | 
			
		||||
        template=get_path("templates/stats.html", abs_path=True),
 | 
			
		||||
        templates=templ,
 | 
			
		||||
        scale_factor=4,
 | 
			
		||||
        scale_factor=1,
 | 
			
		||||
        debug=True
 | 
			
		||||
    )
 | 
			
		||||
    # await md.send_image(image_bytes, bot, event=event)
 | 
			
		||||
    await stats.finish(MessageSegment.image(image_bytes))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user