1
0
forked from bot/app

🥠修复状态缓存出错的问题

🧾规范化文言文本地化文本
This commit is contained in:
2024-07-15 02:07:15 +08:00
parent 7526ae13d7
commit 576d8c23b3
4 changed files with 100 additions and 66 deletions

View File

@ -17,8 +17,8 @@ from src.utils import satori_utils
from .counter_for_satori import satori_counter
from git import Repo
require("nonebot_plugin_apscheduler")
from nonebot_plugin_apscheduler import scheduler
# require("nonebot_plugin_apscheduler")
# from nonebot_plugin_apscheduler import scheduler
commit_hash = Repo(".").head.commit.hexsha
@ -63,27 +63,27 @@ data
- percent: float
- total: int
"""
status_card_cache = {} # lang -> bytes
# status_card_cache = {} # lang -> bytes
# 60s刷新一次
# 之前写的什么鬼玩意,这么重要的功能这样写???
@scheduler.scheduled_job("cron", second="*/40")
async def refresh_status_card():
nonebot.logger.debug("Refreshing status card cache.")
global status_card_cache
status_card_cache = {}
# bot_data = await get_bots_data()
# hardware_data = await get_hardware_data()
# liteyuki_data = await get_liteyuki_data()
# for lang in status_card_cache.keys():
# status_card_cache[lang] = await generate_status_card(
# bot_data,
# hardware_data,
# liteyuki_data,
# lang=lang,
# use_cache=False
# )
# @scheduler.scheduled_job("cron", second="*/40")
# async def refresh_status_card():
# nonebot.logger.debug("Refreshing status card cache.")
# global status_card_cache
# status_card_cache = {}
# bot_data = await get_bots_data()
# hardware_data = await get_hardware_data()
# liteyuki_data = await get_liteyuki_data()
# for lang in status_card_cache.keys():
# status_card_cache[lang] = await generate_status_card(
# bot_data,
# hardware_data,
# liteyuki_data,
# lang=lang,
# use_cache=False
# )
# 获取状态卡片

View File

@ -18,22 +18,35 @@ status_alc = on_alconna(
"process",
alias={"proc", "p", "进程"},
),
Subcommand(
"refresh",
alias={"refr", "r", "刷新"},
),
),
)
status_card_cache = {} # lang -> bytes
@status_alc.handle()
async def _(event: T_MessageEvent, bot: T_Bot):
ulang = get_user_lang(event_utils.get_user_id(event))
if ulang.lang_code not in status_card_cache.keys():
status_card_cache[ulang.lang_code] = await generate_status_card(
bot=await get_bots_data(),
hardware=await get_hardware_data(),
liteyuki=await get_liteyuki_data(),
lang=ulang.lang_code,
bot_id=bot.self_id,
global status_card_cache
if ulang.lang_code not in status_card_cache.keys() or (
ulang.lang_code in status_card_cache.keys()
and time.time() - status_card_cache[ulang.lang_code][1] > 60
):
status_card_cache[ulang.lang_code] = (
await generate_status_card(
bot=await get_bots_data(),
hardware=await get_hardware_data(),
liteyuki=await get_liteyuki_data(),
lang=ulang.lang_code,
bot_id=bot.self_id,
),
time.time(),
)
image = status_card_cache[ulang.lang_code]
image = status_card_cache[ulang.lang_code][0]
await status_alc.finish(UniMessage.image(raw=image))