mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-25 09:37:38 +00:00
🐛 修复 gacha_log 无法分析单抽五星的问题
This commit is contained in:
parent
c16aed1df3
commit
cf8e725a1f
@ -2,13 +2,14 @@ from utils.const import PROJECT_ROOT
|
||||
from aiofiles import open as async_open
|
||||
from httpx import AsyncClient, URL
|
||||
|
||||
GACHA_LOG_PAIMON_MOE_PATH = PROJECT_ROOT.joinpath("metadata/data/paimon_moe_zh.json")
|
||||
|
||||
|
||||
async def update_paimon_moe_zh(overwrite: bool = True):
|
||||
path = PROJECT_ROOT.joinpath("metadata/data/paimon_moe_zh.json")
|
||||
if not overwrite and path.exists():
|
||||
if not overwrite and GACHA_LOG_PAIMON_MOE_PATH.exists():
|
||||
return
|
||||
host = URL("https://raw.fastgit.org/MadeBaruna/paimon-moe/main/src/locales/items/zh.json")
|
||||
client = AsyncClient()
|
||||
text = (await client.get(host)).text
|
||||
async with async_open(path, mode="w", encoding="utf-8") as file:
|
||||
async with async_open(GACHA_LOG_PAIMON_MOE_PATH, mode="w", encoding="utf-8") as file:
|
||||
await file.write(text)
|
||||
|
@ -36,10 +36,14 @@ from modules.gacha_log.models import (
|
||||
UIGFInfo,
|
||||
UIGFItem,
|
||||
)
|
||||
from utils.const import PROJECT_ROOT
|
||||
|
||||
GACHA_LOG_PATH = PROJECT_ROOT.joinpath("data", "apihelper", "gacha_log")
|
||||
GACHA_LOG_PATH.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
class GachaLog:
|
||||
def __init__(self, gacha_log_path: Path):
|
||||
def __init__(self, gacha_log_path: Path = GACHA_LOG_PATH):
|
||||
self.gacha_log_path = gacha_log_path
|
||||
|
||||
@staticmethod
|
||||
@ -388,7 +392,7 @@ class GachaLog:
|
||||
four_star_avg = round((total - no_four_star) / four_star, 2) if four_star != 0 else 0
|
||||
# 四星最多
|
||||
four_star_name_list = [i.name for i in all_four]
|
||||
four_star_max = max(four_star_name_list, key=four_star_name_list.count)
|
||||
four_star_max = max(four_star_name_list, key=four_star_name_list.count) if four_star_name_list else ""
|
||||
four_star_max_count = four_star_name_list.count(four_star_max)
|
||||
return [
|
||||
[
|
||||
@ -421,7 +425,7 @@ class GachaLog:
|
||||
four_star_avg = round((total - no_four_star) / four_star, 2) if four_star != 0 else 0
|
||||
# 四星最多
|
||||
four_star_name_list = [i.name for i in all_four]
|
||||
four_star_max = max(four_star_name_list, key=four_star_name_list.count)
|
||||
four_star_max = max(four_star_name_list, key=four_star_name_list.count) if four_star_name_list else ""
|
||||
four_star_max_count = four_star_name_list.count(four_star_max)
|
||||
return [
|
||||
[
|
||||
|
@ -1,6 +1,5 @@
|
||||
import json
|
||||
from io import BytesIO
|
||||
from os import sep
|
||||
|
||||
import genshin
|
||||
from aiofiles import open as async_open
|
||||
@ -17,7 +16,7 @@ from core.plugin import Plugin, handler, conversation
|
||||
from core.template import TemplateService
|
||||
from core.user import UserService
|
||||
from core.user.error import UserNotFoundError
|
||||
from metadata.scripts.paimon_moe import update_paimon_moe_zh
|
||||
from metadata.scripts.paimon_moe import update_paimon_moe_zh, GACHA_LOG_PAIMON_MOE_PATH
|
||||
from modules.apihelper.hyperion import SignIn
|
||||
from modules.gacha_log.error import (
|
||||
GachaLogInvalidAuthkey,
|
||||
@ -38,9 +37,6 @@ from utils.helpers import get_genshin_client
|
||||
from utils.log import logger
|
||||
from utils.models.base import RegionEnum
|
||||
|
||||
GACHA_LOG_PATH = PROJECT_ROOT.joinpath("data", "apihelper", "gacha_log")
|
||||
GACHA_LOG_PAIMON_MOE_PATH = PROJECT_ROOT.joinpath("metadata/data/paimon_moe_zh.json")
|
||||
GACHA_LOG_PATH.mkdir(parents=True, exist_ok=True)
|
||||
INPUT_URL, INPUT_FILE, CONFIRM_DELETE = range(10100, 10103)
|
||||
|
||||
|
||||
@ -59,7 +55,7 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation):
|
||||
self.assets_service = assets
|
||||
self.cookie_service = cookie_service
|
||||
self.zh_dict = None
|
||||
self.gacha_log = GachaLog(GACHA_LOG_PATH)
|
||||
self.gacha_log = GachaLog()
|
||||
|
||||
async def __async_init__(self):
|
||||
await update_paimon_moe_zh(False)
|
||||
|
@ -29,6 +29,7 @@ class GetChat(Plugin):
|
||||
self.cookies_service = cookies_service
|
||||
self.user_service = user_service
|
||||
self.sign_service = sign_service
|
||||
self.gacha_log = GachaLog()
|
||||
|
||||
async def parse_group_chat(self, chat: Chat, admins: List[ChatMember]) -> str:
|
||||
text = f"群 ID:<code>{chat.id}</code>\n" f"群名称:<code>{chat.title}</code>\n"
|
||||
@ -93,7 +94,7 @@ class GetChat(Plugin):
|
||||
else:
|
||||
text += f"\n自动签到:未开启"
|
||||
with contextlib.suppress(Exception):
|
||||
gacha_log, status = await GachaLog.load_history_info(str(chat.id), str(uid))
|
||||
gacha_log, status = await self.gacha_log.load_history_info(str(chat.id), str(uid))
|
||||
if status:
|
||||
text += f"\n抽卡记录:"
|
||||
for key, value in gacha_log.item_list.items():
|
||||
|
Loading…
Reference in New Issue
Block a user