From 8440329fbc09d079e52096c98112b3537345a68e Mon Sep 17 00:00:00 2001 From: qsc Date: Tue, 30 Sep 2025 21:19:02 +0800 Subject: [PATCH] 11 --- core/cless_jx3.py | 22 +++++++++++++++++++--- core/function_basic.py | 22 +++++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/core/cless_jx3.py b/core/cless_jx3.py index 4d09c1c..daf9563 100644 --- a/core/cless_jx3.py +++ b/core/cless_jx3.py @@ -4,7 +4,7 @@ from astrbot.api import logger from .class_reqsest import APIClient from .cless_mysql import AsyncMySQL -from .function_basic import load_template, extract_field,flatten_field,extract_fields +from .function_basic import load_template, extract_field,flatten_field,extract_fields,gold_to_string class JX3Function: def __init__(self, api_config,db: AsyncMySQL ): @@ -383,7 +383,7 @@ class JX3Function: return processed - async def jiaoyihang(self,Name: str = "守缺式",server: str = "眉间雪"): + async def jiaoyihang(self,Name: str = "守缺式",server: str = "梦江南"): return_data = { "code": 0, "msg": "功能函数未执行", @@ -420,6 +420,22 @@ class JX3Function: if not data: return_data["msg"] = "未找到在售物品" return return_data - return_data["data"]=data + #提取需要的字段 + fieldsjyh = ["ItemId", "SampleSize", "LowestPrice", "AvgPrice", "Date"] + resultjyh = [{f: v[f] for f in fieldsjyh} for v in data.values()] + #合并表格数据 + # 先建立一个字典映射,加快查找 + map_result = {item["id"]: {"IconID": item["IconID"], "Name": item["Name"]} for item in result} + # 遍历 resultjyh,合并字段 + for item in resultjyh: + if item["ItemId"] in map_result: + item.update(map_result[item["ItemId"]]) + #处理数据 + for item in resultjyh: + item["LowestPrice"] = gold_to_string(item["LowestPrice"]) + item["AvgPrice"] = gold_to_string(item["AvgPrice"]) + item["IconID"] = f"https://icon.jx3box.com/icon/{item['IconID']}.png" + + return_data["data"]=resultjyh return_data["code"] = 200 return return_data diff --git a/core/function_basic.py b/core/function_basic.py index 41be761..8f70861 100644 --- a/core/function_basic.py +++ b/core/function_basic.py @@ -83,4 +83,24 @@ def extract_field(data_list, field_name): Returns: list: 提取出来的字段值列表 """ - return [item[field_name] for item in data_list if field_name in item] \ No newline at end of file + return [item[field_name] for item in data_list if field_name in item] + + +def gold_to_string(gold_amount): + """ + 将金钱数值转换为字符串表示形式 + + Args: + gold_amount (int): 金钱数值,单位为铜币 + + Returns: + str: 格式化后的金钱字符串,例如 "1金2银3铜" + """ + bricks = gold_amount // 100000000 if gold_amount else 0 + gold = (gold_amount % 100000000) // 10000 if gold_amount else 0 + silver = (gold_amount % 10000) // 100 if gold_amount else 0 + copper = gold_amount % 100 if gold_amount else 0 + + gold_str = f"{bricks}砖{gold}金{silver}银{copper}铜" if gold_amount else "无价格" + + return gold_str \ No newline at end of file