🐛 修复core信息的箭头无法显示

This commit is contained in:
KimigaiiWuyi 2025-03-10 07:14:47 +08:00
parent c5003d1e7b
commit 64eafa182c
3 changed files with 53 additions and 14 deletions

View File

@ -1,5 +1,5 @@
from pathlib import Path
from typing import Dict, List, Tuple, Union
from typing import Dict, List, Tuple, Union, Optional
from PIL import Image, ImageOps, ImageDraw
@ -149,7 +149,7 @@ async def draw_bar(text1: str, text2: str):
async def draw_badge(
title: str,
value: Union[str, int, float],
avg_value: int = 0,
avg_value: Optional[int] = None,
color: Tuple[int, int, int] = THEME_COLOR,
):
badge = Image.new('RGBA', (210, 150))
@ -170,33 +170,39 @@ async def draw_badge(
)
if isinstance(value, int) or isinstance(value, float) or value.isdigit():
value = number_to_chinese(float(value))
value_str = number_to_chinese(float(value))
else:
value_str = value
if avg_value != 0 and (isinstance(value, int) or isinstance(value, float)):
if value > avg_value * 1.2:
if avg_value is not None and (
isinstance(value, int) or isinstance(value, float)
):
if value >= avg_value * 1.2:
arrow = Image.open(TEXT_PATH / 'up.png')
x = get_font_x(core_font(46), value_str)
point = (92, 51)
badge.paste(
arrow,
(154, 23),
(95 + x // 2, 26),
arrow,
)
elif value < avg_value * 0.8:
elif value <= avg_value * 0.8:
arrow = Image.open(TEXT_PATH / 'down.png')
x = get_font_x(core_font(46), value_str)
point = (92, 51)
badge.paste(
arrow,
(154, 23),
(95 + x // 2, 26),
arrow,
)
else:
point = (105, 63)
point = (105, 51)
else:
point = (105, 63)
point = (105, 51)
badge_draw.text(
point,
value,
value_str,
BLACK,
core_font(46),
'mm',
@ -425,7 +431,7 @@ async def draw_curve(datas: Dict[Tuple[int, int, int], List[float]]):
img = Image.new('RGBA', (1400, 550))
img_draw = ImageDraw.Draw(img)
num = 20
num = 30
rad = 5
a_y = 375
a_x = 1200
@ -478,7 +484,7 @@ async def draw_curve_img(ev: Event):
_data = await gv.get_value_analysis(
ev.real_bot_id,
ev.bot_self_id,
20,
30,
)
result: Dict[Tuple[int, int, int], List[float]] = {

View File

@ -53,8 +53,13 @@ def get_disk_info():
else:
name = f"{round(total_gb, 1)}GB"
# 转换为TB 显示
used_gb = used_size / (1024**3)
used = f"{round(used_gb, 1)}GB"
if used_gb >= 1000:
used_tb = round(used_gb / 1024, 1)
used = f"{used_tb}TB"
else:
used = f"{round(used_gb, 1)}GB"
name = f"{used} / {name}"
# 使用根分区的使用率作为示例(可根据需求修改)

View File

@ -103,5 +103,33 @@ class GsCoreSubscribe:
task_name=task_name,
)
async def update_subscribe_message(
self,
subscribe_type: Literal['session', 'single'],
task_name: str,
event: Event,
extra_message: str,
):
sed = {}
upd = {}
for i in [
'bot_id',
'bot_self_id',
'user_type',
]:
sed[i] = event.__getattribute__(i)
if subscribe_type == 'session' and event.user_type == 'group':
sed['group_id'] = event.group_id
else:
sed['user_id'] = event.user_id
sed['task_name'] = task_name
sed['subscribe_type'] = subscribe_type
upd['extra_message'] = extra_message
await Subscribe.update_data_by_data(sed, upd)
gs_subscribe = GsCoreSubscribe()