mirror of
https://github.com/TriM-Organization/LiteyukiBot-TriM.git
synced 2026-06-14 00:22:26 +00:00
⚡合并轻雪f22f4d2更新,增加人性化语言内容。
This commit is contained in:
@@ -6,8 +6,8 @@ import time
|
||||
|
||||
import nonebot
|
||||
|
||||
__NAME__ = "LiteyukiBot-TriMO"
|
||||
__VERSION__ = "6.3.3" # 60201
|
||||
__NAME__ = "尹灵温|轻雪-睿乐"
|
||||
__VERSION__ = "6.3.4" # 60201
|
||||
# __VERSION_I__ = 99060303
|
||||
|
||||
import requests
|
||||
|
||||
@@ -7,14 +7,14 @@ from nonebot.adapters import satori
|
||||
|
||||
def init(config: dict):
|
||||
if config.get("satori", None) is None:
|
||||
nonebot.logger.info("Satori config not found, skip Satori init.")
|
||||
nonebot.logger.info("未查见 Satori 的配置文档,将跳过 Satori 初始化")
|
||||
return None
|
||||
satori_config = config.get("satori")
|
||||
if not satori_config.get("enable", False):
|
||||
nonebot.logger.info("Satori not enabled, skip Satori init.")
|
||||
nonebot.logger.info("未启用 Satori ,将跳过 Satori 初始化")
|
||||
return None
|
||||
if os.getenv("SATORI_CLIENTS", None) is not None:
|
||||
nonebot.logger.info("Satori clients already set in environment variable, skip.")
|
||||
nonebot.logger.info("Satori 客户端已设入环境变量,跳过此步。")
|
||||
os.environ["SATORI_CLIENTS"] = json.dumps(satori_config.get("hosts", []), ensure_ascii=False)
|
||||
config['satori_clients'] = satori_config.get("hosts", [])
|
||||
return
|
||||
|
||||
@@ -20,25 +20,26 @@ class SatoriNodeConfig(BaseModel):
|
||||
|
||||
|
||||
class SatoriConfig(BaseModel):
|
||||
comment: str = "These features are still in development. Do not enable in production environment."
|
||||
comment: str = "此皆正处于开发之中,切勿在生产环境中启用。"
|
||||
enable: bool = False
|
||||
hosts: List[SatoriNodeConfig] = [SatoriNodeConfig()]
|
||||
|
||||
|
||||
class BasicConfig(BaseModel):
|
||||
host: str = "127.0.0.1"
|
||||
port: int = 20216
|
||||
port: int = 20247
|
||||
superusers: list[str] = []
|
||||
command_start: list[str] = ["/", ""]
|
||||
nickname: list[str] = [f"LiteyukiBot-{random_hex_string(6)}"]
|
||||
nickname: list[str] = [f"灵温-{random_hex_string(6)}"]
|
||||
satori: SatoriConfig = SatoriConfig()
|
||||
data_path: str = "data/liteyuki"
|
||||
|
||||
|
||||
def load_from_yaml(file: str) -> dict:
|
||||
global config
|
||||
nonebot.logger.debug("Loading config from %s" % file)
|
||||
if not os.path.exists(file):
|
||||
nonebot.logger.warning(f"Config file {file} not found, created default config, please modify it and restart")
|
||||
nonebot.logger.warning(f"未找到配置文件 {file} ,已创建默认配置,请修改后重启。")
|
||||
with open(file, "w", encoding="utf-8") as f:
|
||||
yaml.dump(BasicConfig().dict(), f, default_flow_style=False)
|
||||
|
||||
@@ -46,7 +47,7 @@ def load_from_yaml(file: str) -> dict:
|
||||
conf = init_conf(yaml.load(f, Loader=yaml.FullLoader))
|
||||
config = conf
|
||||
if conf is None:
|
||||
nonebot.logger.warning(f"Config file {file} is empty, use default config. please modify it and restart")
|
||||
nonebot.logger.warning(f"配置文件 {file} 为空,已创建默认配置,请修改后重启。")
|
||||
conf = BasicConfig().dict()
|
||||
return conf
|
||||
|
||||
@@ -95,6 +96,8 @@ def init_conf(conf: dict) -> dict:
|
||||
|
||||
"""
|
||||
# 若command_start中无"",则添加必要命令头,开启alconna_use_command_start防止冲突
|
||||
if "" not in conf.get("command_start", []):
|
||||
conf["alconna_use_command_start"] = True
|
||||
# 以下内容由于issue #53 被注释
|
||||
# if "" not in conf.get("command_start", []):
|
||||
# conf["alconna_use_command_start"] = True
|
||||
return conf
|
||||
pass
|
||||
|
||||
+13
-15
@@ -20,8 +20,9 @@ class LiteyukiAPI:
|
||||
self.data = json.loads(f.read())
|
||||
self.liteyuki_id = self.data.get("liteyuki_id")
|
||||
self.report = load_from_yaml("config.yml").get("auto_report", True)
|
||||
|
||||
if self.report:
|
||||
nonebot.logger.info("Auto bug report is enabled")
|
||||
nonebot.logger.info("已启用自动上报")
|
||||
|
||||
@property
|
||||
def device_info(self) -> dict:
|
||||
@@ -37,10 +38,10 @@ class LiteyukiAPI:
|
||||
"python" : f"{platform.python_implementation()} {platform.python_version()}",
|
||||
"os" : f"{platform.system()} {platform.version()} {platform.machine()}",
|
||||
"cpu" : f"{psutil.cpu_count(logical=False)}c{psutil.cpu_count()}t{psutil.cpu_freq().current}MHz",
|
||||
"memory_total": f"{psutil.virtual_memory().total / 1024 / 1024 / 1024:.2f}GB",
|
||||
"memory_used" : f"{psutil.virtual_memory().used / 1024 / 1024 / 1024:.2f}GB",
|
||||
"memory_bot" : f"{psutil.Process(os.getpid()).memory_info().rss / 1024 / 1024:.2f}MB",
|
||||
"disk" : f"{psutil.disk_usage('/').total / 1024 / 1024 / 1024:.2f}GB"
|
||||
"memory_total": f"{psutil.virtual_memory().total / 1024 ** 3:.2f}吉字节",
|
||||
"memory_used" : f"{psutil.virtual_memory().used / 1024 ** 3:.2f}吉字节",
|
||||
"memory_bot" : f"{psutil.Process(os.getpid()).memory_info().rss / 1024 ** 2:.2f}兆字节",
|
||||
"disk" : f"{psutil.disk_usage('/').total / 1024 ** 3:.2f}吉字节"
|
||||
}
|
||||
|
||||
def bug_report(self, content: str):
|
||||
@@ -53,7 +54,7 @@ class LiteyukiAPI:
|
||||
|
||||
"""
|
||||
if self.report:
|
||||
nonebot.logger.warning(f"Reporting bug...: {content}")
|
||||
nonebot.logger.warning(f"正在上报查误:{content}")
|
||||
url = "https://api.liteyuki.icu/bug_report"
|
||||
data = {
|
||||
"liteyuki_id": self.liteyuki_id,
|
||||
@@ -62,11 +63,11 @@ class LiteyukiAPI:
|
||||
}
|
||||
resp = requests.post(url, json=data)
|
||||
if resp.status_code == 200:
|
||||
nonebot.logger.success(f"Bug report sent successfully, report_id: {resp.json().get('report_id')}")
|
||||
nonebot.logger.success(f"成功上报差误信息,报文ID为:{resp.json().get('report_id')}")
|
||||
else:
|
||||
nonebot.logger.error(f"Bug report failed: {resp.text}")
|
||||
nonebot.logger.error(f"差误上报错误:{resp.text}")
|
||||
else:
|
||||
nonebot.logger.warning(f"Bug report is disabled: {content}")
|
||||
nonebot.logger.warning(f"已禁用自动上报:{content}")
|
||||
|
||||
async def heartbeat_report(self):
|
||||
"""
|
||||
@@ -77,14 +78,11 @@ class LiteyukiAPI:
|
||||
url = "https://api.liteyuki.icu/heartbeat"
|
||||
data = {
|
||||
"liteyuki_id": self.liteyuki_id,
|
||||
"version": __VERSION__,
|
||||
"version" : __VERSION__,
|
||||
}
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(url, json=data) as resp:
|
||||
if resp.status == 200:
|
||||
nonebot.logger.success("Heartbeat sent successfully")
|
||||
nonebot.logger.success("心跳成功送达。")
|
||||
else:
|
||||
nonebot.logger.error(f"Heartbeat failed: {await resp.text()}")
|
||||
|
||||
|
||||
liteyuki_api = LiteyukiAPI()
|
||||
nonebot.logger.error(f"休克:{await resp.text()}")
|
||||
@@ -9,13 +9,12 @@ from .defines import *
|
||||
def auto_set_env(config: dict):
|
||||
dotenv.load_dotenv(".env")
|
||||
if os.getenv("DRIVER", None) is not None:
|
||||
print(os.getenv("DRIVER"))
|
||||
nonebot.logger.info("Driver already set in environment variable, skip auto configure.")
|
||||
nonebot.logger.info("Driver 已设入环境变量中,将跳过自动配置环节。")
|
||||
return
|
||||
if config.get("satori", {'enable': False}).get("enable", False):
|
||||
os.environ["DRIVER"] = get_driver_string(ASGI_DRIVER, HTTPX_DRIVER, WEBSOCKETS_DRIVER)
|
||||
nonebot.logger.info("Enable Satori, set driver to ASGI+HTTPX+WEBSOCKETS")
|
||||
nonebot.logger.info("已启用 Satori,将 driver 设为 ASGI+HTTPX+WEBSOCKETS")
|
||||
else:
|
||||
os.environ["DRIVER"] = get_driver_string(ASGI_DRIVER)
|
||||
nonebot.logger.info("Disable Satori, set driver to ASGI")
|
||||
nonebot.logger.info("已禁用 Satori,将 driver 设为 ASGI")
|
||||
return
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
from aiohttp import ClientSession
|
||||
|
||||
|
||||
async def simple_get(url: str) -> str:
|
||||
"""
|
||||
简单异步get请求
|
||||
Args:
|
||||
url:
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
async with ClientSession() as session:
|
||||
async with session.get(url) as resp:
|
||||
return await resp.text()
|
||||
from aiohttp import ClientSession
|
||||
|
||||
from .net import *
|
||||
from .file import *
|
||||
|
||||
|
||||
async def simple_get(url: str) -> str:
|
||||
"""
|
||||
简单异步get请求
|
||||
Args:
|
||||
url:
|
||||
|
||||
Returns:
|
||||
"""
|
||||
async with ClientSession() as session:
|
||||
async with session.get(url) as resp:
|
||||
return await resp.text()
|
||||
@@ -0,0 +1,29 @@
|
||||
import aiofiles
|
||||
|
||||
|
||||
async def write_file(
|
||||
file_path: str,
|
||||
content: str | bytes,
|
||||
mode: str = "w"
|
||||
):
|
||||
"""
|
||||
写入文件
|
||||
Args:
|
||||
mode: 写入模式
|
||||
file_path: 文件路径
|
||||
content: 内容
|
||||
"""
|
||||
async with aiofiles.open(file_path, mode) as f:
|
||||
await f.write(content)
|
||||
|
||||
|
||||
async def read_file(file_path: str, mode: str = "r") -> str:
|
||||
"""
|
||||
读取文件
|
||||
Args:
|
||||
file_path: 文件路径
|
||||
mode: 读取模式
|
||||
Returns:
|
||||
"""
|
||||
async with aiofiles.open(file_path, mode) as f:
|
||||
return await f.read()
|
||||
@@ -0,0 +1,12 @@
|
||||
async def fetch(url: str) -> str:
|
||||
"""
|
||||
异步get请求
|
||||
Args:
|
||||
url:
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
async with ClientSession() as session:
|
||||
async with session.get(url) as resp:
|
||||
return await resp.text()
|
||||
Reference in New Issue
Block a user