mirror of
https://github.com/TriM-Organization/LiteyukiBot-TriM.git
synced 2024-11-28 08:15:03 +08:00
✨ 修改启动逻辑和插件加载逻辑
This commit is contained in:
parent
c171873fa6
commit
3ea0acd48b
@ -32,4 +32,3 @@ $$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/
|
||||
|
||||
sys_lang = Language(get_default_lang_code())
|
||||
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,5 +1,5 @@
|
||||
import nonebot.plugin
|
||||
|
||||
from nonebot import get_driver
|
||||
from liteyuki.utils import init_log
|
||||
from liteyuki.utils.base.config import get_config
|
||||
from liteyuki.utils.base.data_manager import InstalledPlugin, plugin_db
|
||||
@ -9,19 +9,25 @@ from liteyuki.utils.message.tools import check_for_package
|
||||
load_resources()
|
||||
init_log()
|
||||
|
||||
nonebot.plugin.load_plugins("liteyuki/plugins")
|
||||
# 从数据库读取已安装的插件
|
||||
if not get_config("safe_mode", False):
|
||||
driver = get_driver()
|
||||
|
||||
|
||||
@driver.on_startup
|
||||
async def load_plugins():
|
||||
nonebot.plugin.load_plugins("liteyuki/plugins")
|
||||
# 从数据库读取已安装的插件
|
||||
if not get_config("safe_mode", False):
|
||||
# 安全模式下,不加载插件
|
||||
|
||||
installed_plugins: list[InstalledPlugin] = plugin_db.where_all(InstalledPlugin())
|
||||
if installed_plugins:
|
||||
for installed_plugin in installed_plugins:
|
||||
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.")
|
||||
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)
|
||||
|
||||
nonebot.plugin.load_plugins("plugins")
|
||||
else:
|
||||
else:
|
||||
nonebot.logger.info("Safe mode is on, no plugin loaded.")
|
||||
|
@ -36,7 +36,7 @@ async def _(result: Arparma, event: T_MessageEvent):
|
||||
end = quote(quote(result.other_args.get("end")))
|
||||
|
||||
# 判断参数语言
|
||||
query_lang_code = "Eng" if ulang.lang_code not in ["zh-CN", "zh-HK"] else ""
|
||||
query_lang_code = ""
|
||||
if start.isalpha() and end.isalpha():
|
||||
query_lang_code = "Eng"
|
||||
|
||||
@ -55,9 +55,15 @@ async def _(result: Arparma, event: T_MessageEvent):
|
||||
|
||||
# 模板传参定义
|
||||
templates = {
|
||||
"data": {
|
||||
"data" : {
|
||||
"result": result["result"],
|
||||
}
|
||||
},
|
||||
"localization": ulang.get_many(
|
||||
"crt.station",
|
||||
"crt.hour",
|
||||
"crt.minute",
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
# 生成图片
|
||||
|
3
liteyuki/resources/liteyuki_crt/lang/en.lang
Normal file
3
liteyuki/resources/liteyuki_crt/lang/en.lang
Normal file
@ -0,0 +1,3 @@
|
||||
crt.station=Station(s)
|
||||
crt.hour=Hour(s)
|
||||
crt.minute=Min(s)
|
3
liteyuki/resources/liteyuki_crt/lang/zh-CN.lang
Normal file
3
liteyuki/resources/liteyuki_crt/lang/zh-CN.lang
Normal file
@ -0,0 +1,3 @@
|
||||
crt.station=站
|
||||
crt.hour=小时
|
||||
crt.minute=分钟
|
@ -6,15 +6,154 @@
|
||||
<link rel="stylesheet" href="./css/card.css">
|
||||
<link rel="stylesheet" href="./css/fonts.css">
|
||||
</head>
|
||||
<style>
|
||||
|
||||
:root {
|
||||
--color-primary: #f00;
|
||||
--color-secondary: #fff;
|
||||
--sub-text-color: #aaa;
|
||||
}
|
||||
|
||||
.segment {
|
||||
display: flex;
|
||||
background-color: #0d1117;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.line-icon {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.vertical-bar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 20px;
|
||||
height: 100%;
|
||||
border-radius: 50px;
|
||||
background-color: #f00;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.station-dot {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
aspect-ratio: 1/1;
|
||||
border-radius: 50%;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
/* 第一个点在bar顶端,第二个在底部*/
|
||||
.station-dot:first-child {
|
||||
margin-top: 2px;
|
||||
margin-bottom: auto;
|
||||
}
|
||||
|
||||
.station-dot:last-child {
|
||||
margin-top: auto;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.transfer-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.station-name {
|
||||
font-size: 16px;
|
||||
color: var(--color-secondary);
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.end-station {
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.line-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.line-name {
|
||||
padding: 3px;
|
||||
border-radius: 50px;
|
||||
background-color: #f00;
|
||||
color: var(--color-secondary);
|
||||
font-size: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.line-direction {
|
||||
font-size: 12px;
|
||||
color: var(--sub-text-color);
|
||||
}
|
||||
|
||||
.station-info {
|
||||
align-items: center;
|
||||
font-size: 10px;
|
||||
color: var(--sub-text-color);
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.start-station {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.segment-index {
|
||||
font-size: 12px;
|
||||
color: var(--sub-text-color);
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<div class="data-storage" id="data">{{ data | tojson }}</div>
|
||||
|
||||
<!---->
|
||||
<template id="route-template">
|
||||
<div class="info-box" id="route-info">
|
||||
|
||||
<template id="segment-template">
|
||||
<div class="segment">
|
||||
<div class="line-icon">
|
||||
<!-- 竖条-->
|
||||
<div class="vertical-bar">
|
||||
<div class="station-dot"></div>
|
||||
<div class="station-dot"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="transfer-info">
|
||||
<div class="start-station">
|
||||
<div class="station-name start-station-name">
|
||||
下北泽站
|
||||
</div>
|
||||
<div class="segment-index">
|
||||
第1段
|
||||
</div>
|
||||
</div>
|
||||
<div class="line-info">
|
||||
<div class="line-name">
|
||||
轨道交通环线外环
|
||||
</div>
|
||||
<div class="line-direction">
|
||||
沙坪坝方向
|
||||
</div>
|
||||
</div>
|
||||
<div class="station-info">
|
||||
5站(14分钟)
|
||||
</div>
|
||||
<div class="end-station">
|
||||
<div class="station-name end-station-name">
|
||||
新桥站
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template id="route-template">
|
||||
<div class="info-box route-info" id="route-info">
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<script src="./js/card.js"></script>
|
||||
<script src="./js/crt_route.js"></script>
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2024 SnowyKami Liteyuki Studio All Rights Reserved.
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @type {{
|
||||
* results: Array<{
|
||||
@ -25,7 +24,13 @@
|
||||
const data = JSON.parse(document.getElementById("data").innerText);
|
||||
const results = data["result"];
|
||||
|
||||
const solution_template = document.getElementById("route-template").innerText;
|
||||
const route_template = document.importNode(document.getElementById("route-template").content, true)
|
||||
|
||||
results.forEach(
|
||||
(item, index) => {
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
@ -119,7 +119,7 @@ weatherDaily['daily'].forEach(
|
||||
)
|
||||
|
||||
function get_time_hour(fxTime) {
|
||||
// fxTime 2024-05-03T02:00+08:00'
|
||||
// fxTime 2024-05-03T02:00+/-08:00'
|
||||
fxTime = fxTime.replace("-", "+")
|
||||
return fxTime.split("T")[1].split("+")[0]
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
import json
|
||||
import locale
|
||||
import os
|
||||
from typing import Any
|
||||
from typing import Any, overload
|
||||
|
||||
import nonebot
|
||||
|
||||
@ -142,6 +142,21 @@ class Language:
|
||||
return trans
|
||||
return default or item
|
||||
|
||||
def get_many(self, *args: str, **kwargs) -> dict[str, str]:
|
||||
"""
|
||||
获取多个文本
|
||||
Args:
|
||||
*args: 文本键
|
||||
**kwargs: 文本键和默认文本
|
||||
|
||||
Returns:
|
||||
dict: 多个文本
|
||||
"""
|
||||
args_data = {item: self.get(item) for item in args}
|
||||
kwargs_data = {item: self.get(item, default=default) for item, default in kwargs.items()}
|
||||
args_data.update(kwargs_data)
|
||||
return args_data
|
||||
|
||||
|
||||
def change_user_lang(user_id: str, lang_code: str):
|
||||
"""
|
||||
|
19
main.py
19
main.py
@ -1,12 +1,11 @@
|
||||
import nonebot
|
||||
from nonebot.adapters.onebot import v11, v12
|
||||
from nonebot.adapters import satori
|
||||
from liteyuki.utils import init, driver_manager, adapter_manager
|
||||
from liteyuki.utils import adapter_manager, driver_manager, init
|
||||
from liteyuki.utils.base.config import load_from_yaml
|
||||
from liteyuki.utils.base.data_manager import StoredConfig, common_db
|
||||
from liteyuki.utils.base.ly_api import liteyuki_api
|
||||
|
||||
if __name__ == "__mp_main__":
|
||||
# Start as multiprocessing
|
||||
init()
|
||||
store_config: dict = common_db.where_one(StoredConfig(), default=StoredConfig()).config
|
||||
static_config = load_from_yaml("config.yml")
|
||||
@ -14,20 +13,7 @@ if __name__ == "__mp_main__":
|
||||
driver_manager.init(config=store_config)
|
||||
adapter_manager.init(store_config)
|
||||
nonebot.init(**store_config)
|
||||
|
||||
adapter_manager.register()
|
||||
|
||||
# print(nonebot.get_adapters()['Satori'].__dict__)
|
||||
|
||||
# if not store_config.get("enable_satori", False):
|
||||
# adapters = [v11.Adapter, v12.Adapter]
|
||||
# else:
|
||||
# adapters = [v11.Adapter, v12.Adapter, satori.Adapter]
|
||||
# driver = nonebot.get_driver()
|
||||
# # print(driver.__dict__)
|
||||
# for adapter in adapters:
|
||||
# driver.register_adapter(adapter)
|
||||
|
||||
try:
|
||||
nonebot.load_plugin("liteyuki.liteyuki_main")
|
||||
nonebot.load_from_toml("pyproject.toml")
|
||||
@ -37,5 +23,6 @@ if __name__ == "__mp_main__":
|
||||
liteyuki_api.bug_report(str(e.__repr__()))
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Start as __main__
|
||||
from liteyuki.utils.base.reloader import Reloader
|
||||
nonebot.run()
|
Loading…
Reference in New Issue
Block a user