feat: 添加了网页监控面板
This commit is contained in:
@ -1,10 +1,32 @@
|
||||
from yaml import load, FullLoader
|
||||
import os
|
||||
|
||||
import nonebot
|
||||
import yaml
|
||||
from pydantic import BaseModel
|
||||
|
||||
config = None
|
||||
|
||||
|
||||
class BasicConfig(BaseModel):
|
||||
host: str = "127.0.0.1"
|
||||
port: int = 20216
|
||||
superusers: list[str] = []
|
||||
command_start: list[str] = ["/", ""]
|
||||
nickname: set[str] = {"Liteyuki"}
|
||||
|
||||
|
||||
def load_from_yaml(file: str) -> dict:
|
||||
nonebot.logger.debug("Loading config from %s" % file)
|
||||
global config
|
||||
if not os.path.exists(file):
|
||||
nonebot.logger.warning(f'Config file {file} not found, created default config, please modify it and restart')
|
||||
with open(file, 'w', encoding='utf-8') as f:
|
||||
yaml.dump(BasicConfig().dict(), f, default_flow_style=False)
|
||||
|
||||
with open(file, 'r', encoding='utf-8') as f:
|
||||
config = load(f, Loader=FullLoader)
|
||||
return config
|
||||
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')
|
||||
conf = BasicConfig().dict()
|
||||
return conf
|
||||
|
31
src/utils/tools.py
Normal file
31
src/utils/tools.py
Normal file
@ -0,0 +1,31 @@
|
||||
def convert_size(size: int, precision: int = 2, add_unit: bool = True, suffix: str = "iB") -> str:
|
||||
"""把字节数转换为人类可读的字符串,计算正负
|
||||
|
||||
Args:
|
||||
|
||||
add_unit: 是否添加单位,False后则suffix无效
|
||||
suffix: iB或B
|
||||
precision: 浮点数的小数点位数
|
||||
size (int): 字节数
|
||||
|
||||
Returns:
|
||||
|
||||
str: The human-readable string, e.g. "1.23 GB".
|
||||
"""
|
||||
is_negative = False
|
||||
if size < 0:
|
||||
is_negative = True
|
||||
size = -size
|
||||
|
||||
for unit in ["", "K", "M", "G", "T", "P", "E", "Z", "Y"]:
|
||||
if size < 1024:
|
||||
if add_unit:
|
||||
result = f"{size:.{precision}f} {unit}" + suffix
|
||||
return f"-{result}" if is_negative else result
|
||||
else:
|
||||
return f"{size:.{precision}f}"
|
||||
size /= 1024
|
||||
if add_unit:
|
||||
return f"{size:.{precision}f} Y" + suffix
|
||||
else:
|
||||
return f"{size:.{precision}f}"
|
Reference in New Issue
Block a user