11
This commit is contained in:
@@ -2,8 +2,8 @@ from datetime import datetime
|
||||
|
||||
from astrbot.api import logger
|
||||
|
||||
from .class_reqsest import APIClient
|
||||
from .cless_mysql import AsyncMySQL
|
||||
from .APIClient import APIClient
|
||||
from .AsyncMySQL import AsyncMySQL
|
||||
from .function_basic import load_template,extract_field,flatten_field,extract_fields,gold_to_string,plot_line_chart_base64
|
||||
|
||||
class JX3Function:
|
||||
@@ -2,8 +2,8 @@ from datetime import datetime
|
||||
import base64
|
||||
from astrbot.api import logger
|
||||
|
||||
from .class_reqsest import APIClient
|
||||
from .cless_mysql import AsyncMySQL
|
||||
from .APIClient import APIClient
|
||||
from .AsyncMySQL import AsyncMySQL
|
||||
from .function_basic import load_template,extract_field,flatten_field,extract_fields,gold_to_string,plot_line_chart_base64
|
||||
|
||||
class WZRYFunction:
|
||||
@@ -95,7 +95,7 @@ class WZRYFunction:
|
||||
# 需要提取的字段
|
||||
fields = ["gametime","killcnt","deadcnt","assistcnt","gameresult","mvpcnt","losemvp","mapName",
|
||||
"oldMasterMatchScore","newMasterMatchScore","usedTime","winNum","failNum","roleJobName","stars","desc",
|
||||
"gradeGame","heroIcon","godLikeCnt", "firstBlood","hero1TripleKillCnt","hero1UltraKillCnt","hero1RampageCnt"]
|
||||
"gradeGame","heroIcon","godLikeCnt", "firstBlood","hero1TripleKillCnt","hero1UltraKillCnt","hero1RampageCnt","evaluateUrlV3","mvpUrlV3"]
|
||||
# 处理返回数据
|
||||
try:
|
||||
# 获取数据
|
||||
@@ -103,8 +103,9 @@ class WZRYFunction:
|
||||
if not data:
|
||||
return_data["msg"] = "获取接口信息失败"
|
||||
return return_data
|
||||
# 提取字段
|
||||
result = extract_fields(data["list"], fields)
|
||||
result = result[:20]
|
||||
result = result[:25]
|
||||
# 数据处理
|
||||
for m in result:
|
||||
minutes = m["usedTime"] // 60
|
||||
@@ -112,13 +113,12 @@ class WZRYFunction:
|
||||
m["time_str"] = f"{minutes}:{seconds:02d}"
|
||||
|
||||
return_data["data"] = result
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"处理数据时出错: {e}")
|
||||
return_data["msg"] = "处理接口返回信息时出错"
|
||||
# 加载模板
|
||||
try:
|
||||
return_data["temp"] = load_template("temp_test.html")
|
||||
return_data["temp"] = load_template("wangzhezhanji.html")
|
||||
except FileNotFoundError as e:
|
||||
logger.error(f"加载模板失败: {e}")
|
||||
return_data["msg"] = "系统错误:模板文件不存在"
|
||||
@@ -127,40 +127,36 @@ class WZRYFunction:
|
||||
return return_data
|
||||
|
||||
async def ziliao(self, name: str):
|
||||
"""
|
||||
资料查询
|
||||
"""
|
||||
return_data = {
|
||||
"code": 0,
|
||||
"msg": "功能函数未执行",
|
||||
"data": {}
|
||||
}
|
||||
#id查询
|
||||
sql = "SELECT id FROM wzydid WHERE name = %s or id = %s"
|
||||
sqlid = await self.__db.fetch_one(sql, (name,name))
|
||||
#在配置文件中获取接口配置
|
||||
api_config = self.__api_config["wzry_ziliao"]
|
||||
#更新参数
|
||||
api_config["params"]["id"] = sqlid["id"]
|
||||
# 处理返回数据
|
||||
try:
|
||||
# 获取数据
|
||||
data = await self.__api.get(api_config["url"],api_config["params"])
|
||||
if not data:
|
||||
return_data["msg"] = "获取接口信息失败"
|
||||
# 查询 ID
|
||||
sql_id = await self._SELECT_ID(name)
|
||||
|
||||
if sql_id is None:
|
||||
return_data["msg"] = "未查询到该用户,请确认输入正确的昵称或营地ID"
|
||||
return return_data
|
||||
# 数据处理
|
||||
return_data["data"]["img_base64"] = base64.b64encode(data).decode('utf-8')
|
||||
api_config = self.__api_config["wzry_ziliao"]
|
||||
api_config["params"]["id"] = sql_id
|
||||
|
||||
try:
|
||||
data = await self.__api.get(api_config["url"], api_config["params"])
|
||||
# 转 base64
|
||||
return_data["data"]["img_base64"] = base64.b64encode(data).decode("utf-8")
|
||||
return_data["code"] = 200
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"处理数据时出错: {e}")
|
||||
return_data["msg"] = "处理接口返回信息时出错"
|
||||
|
||||
# 加载模板
|
||||
try:
|
||||
return_data["temp"] = load_template("wzry_zl.html")
|
||||
except FileNotFoundError as e:
|
||||
logger.error(f"加载模板失败: {e}")
|
||||
except FileNotFoundError:
|
||||
logger.error(f"加载模板失败")
|
||||
return_data["msg"] = "系统错误:模板文件不存在"
|
||||
|
||||
return return_data
|
||||
return_data["code"] = 200
|
||||
return return_data
|
||||
|
||||
@@ -8,9 +8,9 @@ from astrbot.api.star import Context, Star, register, StarTools
|
||||
from astrbot.api import logger
|
||||
from astrbot.api import AstrBotConfig
|
||||
|
||||
from .core.cless_mysql import AsyncMySQL
|
||||
from .core.cless_jx3 import JX3Function
|
||||
from .core.cless_wzry import WZRYFunction
|
||||
from .core.AsyncMySQL import AsyncMySQL
|
||||
from .core.JX3Function import JX3Function
|
||||
from .core.WZRYFunction import WZRYFunction
|
||||
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ class Jx3ApiPlugin(Star):
|
||||
pass
|
||||
|
||||
|
||||
@wz.command("用户列表")
|
||||
@wz.command("列表")
|
||||
async def wz_yingdilist(self, event: AstrMessageEvent):
|
||||
"""王者 用户列表"""
|
||||
try:
|
||||
@@ -304,7 +304,7 @@ class Jx3ApiPlugin(Star):
|
||||
logger.error(f"功能函数执行错误: {e}")
|
||||
yield event.plain_result("猪脑过载,请稍后再试")
|
||||
|
||||
@wz.command("添加用户")
|
||||
@wz.command("添加")
|
||||
async def wz_adduesr(self, event: AstrMessageEvent,id: str,name: str):
|
||||
"""王者 添加用户"""
|
||||
try:
|
||||
@@ -314,7 +314,7 @@ class Jx3ApiPlugin(Star):
|
||||
logger.error(f"功能函数执行错误: {e}")
|
||||
yield event.plain_result("猪脑过载,请稍后再试")
|
||||
|
||||
@wz.command("修改用户")
|
||||
@wz.command("修改")
|
||||
async def wz_updateuser(self, event: AstrMessageEvent,id: str,name: str):
|
||||
"""王者 修改用户"""
|
||||
try:
|
||||
@@ -324,7 +324,7 @@ class Jx3ApiPlugin(Star):
|
||||
logger.error(f"功能函数执行错误: {e}")
|
||||
yield event.plain_result("猪脑过载,请稍后再试")
|
||||
|
||||
@wz.command("删除用户")
|
||||
@wz.command("删除")
|
||||
async def wz_deleteuser(self, event: AstrMessageEvent,id: str):
|
||||
"""王者 删除用户"""
|
||||
try:
|
||||
@@ -341,18 +341,18 @@ class Jx3ApiPlugin(Star):
|
||||
try:
|
||||
data = await self.wzry.zhanji(name,option)
|
||||
# logger.info(f"王者荣耀战绩查询结果{data}")
|
||||
prompt = f"{data['data']}\n"
|
||||
prompt += f"以上数据是获取到的王者荣耀战绩信息,请根据这些数据生成一两句话的战绩总结,突出玩家的优势和特点,语言风格轻松幽默,适合在游戏群内分享。"
|
||||
#prompt = f"{data['data']}\n"
|
||||
#prompt += f"以上数据是获取到的王者荣耀战绩信息,请根据这些数据生成一两句话的战绩总结,突出玩家的优势和特点,语言风格轻松幽默,适合在游戏群内分享。"
|
||||
if data["code"] == 200:
|
||||
url = await self.html_render(data["temp"],{"data":data["data"]}, options={})
|
||||
yield event.image_result(url)
|
||||
else:
|
||||
yield event.plain_result(data["msg"])
|
||||
return
|
||||
provider_id = await self.context.get_current_chat_provider_id(umo=event.unified_msg_origin)
|
||||
llm_resp = await self.context.llm_generate(chat_provider_id=provider_id, prompt=prompt,)
|
||||
out = llm_resp.completion_text
|
||||
yield event.plain_result(f"{out}")
|
||||
#provider_id = await self.context.get_current_chat_provider_id(umo=event.unified_msg_origin)
|
||||
#llm_resp = await self.context.llm_generate(chat_provider_id=provider_id, prompt=prompt,)
|
||||
#out = llm_resp.completion_text
|
||||
#yield event.plain_result(f"{out}")
|
||||
except Exception as e:
|
||||
logger.error(f"功能函数执行错误: {e}")
|
||||
yield event.plain_result("猪脑过载,请稍后再试")
|
||||
@@ -363,7 +363,7 @@ class Jx3ApiPlugin(Star):
|
||||
"""王者 战绩 营地ID 对局类型"""
|
||||
try:
|
||||
data = await self.wzry.ziliao(name)
|
||||
# logger.info(f"输出结果{data}")
|
||||
logger.info(f"输出结果{data}")
|
||||
if data["code"] == 200:
|
||||
url = await self.html_render(data["temp"], data["data"], options={})
|
||||
yield event.image_result(url)
|
||||
|
||||
+19
-32
@@ -72,25 +72,6 @@
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* MVP 标签 */
|
||||
.mvp-tag-win {
|
||||
background: #b69f1c;
|
||||
color: white;
|
||||
padding: 4px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.mvp-tag-lose {
|
||||
background: #888;
|
||||
color: white;
|
||||
padding: 4px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 胜负标签 */
|
||||
.result-tag {
|
||||
padding: 6px 12px;
|
||||
@@ -148,7 +129,7 @@
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
/* 新增成就标签 - 优化显示 */
|
||||
/* 新增成就标签 */
|
||||
.achievement-tags {
|
||||
margin-top: 8px;
|
||||
display: flex;
|
||||
@@ -157,13 +138,13 @@
|
||||
}
|
||||
|
||||
.achievement-tags span {
|
||||
background: rgba(0, 0, 0, 0.6); /* 背景更深 */
|
||||
color: #fff; /* 白色文字 */
|
||||
font-weight: bold; /* 加粗文字 */
|
||||
padding: 6px 10px; /* 内边距更大 */
|
||||
border-radius: 14px; /* 圆角更明显 */
|
||||
font-size: 14px; /* 略大字体 */
|
||||
text-shadow: 0 1px 2px rgba(0,0,0,0.5); /* 文字阴影增强可读性 */
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
padding: 6px 10px;
|
||||
border-radius: 14px;
|
||||
font-size: 14px;
|
||||
text-shadow: 0 1px 2px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -188,12 +169,17 @@
|
||||
|
||||
<div class="content">
|
||||
|
||||
<!-- 右上角标签(MVP + 胜负) -->
|
||||
<!-- 右上角标签(evaluate + MVP PNG) -->
|
||||
<div class="tag-area">
|
||||
{% if m.mvpcnt == 1 %}
|
||||
<div class="mvp-tag-win">胜方 MVP</div>
|
||||
{% elif m.losemvp == 1 %}
|
||||
<div class="mvp-tag-lose">败方 MVP</div>
|
||||
|
||||
{% if m.evaluateUrlV3 %}
|
||||
<img src="{{ m.evaluateUrlV3 }}"
|
||||
style="height: 32px; border-radius: 6px;">
|
||||
{% endif %}
|
||||
|
||||
{% if m.mvpUrlV3 %}
|
||||
<img src="{{ m.mvpUrlV3 }}"
|
||||
style="height: 32px; border-radius: 6px;">
|
||||
{% endif %}
|
||||
|
||||
<div class="result-tag
|
||||
@@ -206,6 +192,7 @@
|
||||
{% else %}平局
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- 对局时间 + 对局类型 -->
|
||||
|
||||
@@ -72,25 +72,6 @@
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* MVP 标签 */
|
||||
.mvp-tag-win {
|
||||
background: #b69f1c;
|
||||
color: white;
|
||||
padding: 4px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.mvp-tag-lose {
|
||||
background: #888;
|
||||
color: white;
|
||||
padding: 4px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 胜负标签 */
|
||||
.result-tag {
|
||||
padding: 6px 12px;
|
||||
@@ -103,18 +84,35 @@
|
||||
.lose-tag { background: #d93939; }
|
||||
.draw-tag { background: #777; }
|
||||
|
||||
.info-line {
|
||||
margin-bottom: 8px;
|
||||
/* 对局时间 + 对局类型 */
|
||||
.info-line-time {
|
||||
font-size: 18px;
|
||||
color: #000;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
/* 段位 + 星星 */
|
||||
.rank-stars {
|
||||
font-size: 16px;
|
||||
color: #2ecc71;
|
||||
font-weight: bold;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
/* KDA 信息 */
|
||||
.kda-info {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #555;
|
||||
font-size: 15px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
/* 巅峰赛积分 */
|
||||
.master-score {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin: 8px 0;
|
||||
color: #056a3a;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
/* 评分显示 */
|
||||
@@ -122,7 +120,7 @@
|
||||
position: absolute;
|
||||
right: 16px;
|
||||
bottom: 16px;
|
||||
background: #ffd700; /* 金黄色背景突出 */
|
||||
background: #ffd700;
|
||||
color: #222;
|
||||
font-size: 20px;
|
||||
font-weight: 900;
|
||||
@@ -140,11 +138,13 @@
|
||||
}
|
||||
|
||||
.achievement-tags span {
|
||||
background: rgba(0,0,0,0.15);
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
color: #fff;
|
||||
padding: 4px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
padding: 6px 10px;
|
||||
border-radius: 14px;
|
||||
font-size: 14px;
|
||||
text-shadow: 0 1px 2px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -169,12 +169,17 @@
|
||||
|
||||
<div class="content">
|
||||
|
||||
<!-- 右上角标签(MVP + 胜负) -->
|
||||
<!-- 右上角标签(evaluate + MVP PNG) -->
|
||||
<div class="tag-area">
|
||||
{% if m.mvpcnt == 1 %}
|
||||
<div class="mvp-tag-win">胜方 MVP</div>
|
||||
{% elif m.losemvp == 1 %}
|
||||
<div class="mvp-tag-lose">败方 MVP</div>
|
||||
|
||||
{% if m.evaluateUrlV3 %}
|
||||
<img src="{{ m.evaluateUrlV3 }}"
|
||||
style="height: 32px; border-radius: 6px;">
|
||||
{% endif %}
|
||||
|
||||
{% if m.mvpUrlV3 %}
|
||||
<img src="{{ m.mvpUrlV3 }}"
|
||||
style="height: 32px; border-radius: 6px;">
|
||||
{% endif %}
|
||||
|
||||
<div class="result-tag
|
||||
@@ -187,22 +192,29 @@
|
||||
{% else %}平局
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="info-line">
|
||||
{{ m.gametime }} · {{ m.mapName }}<br>
|
||||
<!-- 对局时间 + 对局类型 -->
|
||||
<div class="info-line-time">
|
||||
{{ m.gametime }} · {{ m.mapName }}
|
||||
</div>
|
||||
|
||||
<!-- 段位 + 星星 -->
|
||||
<div class="rank-stars">
|
||||
{{ m.roleJobName }} · ⭐{{ m.stars }}
|
||||
</div>
|
||||
|
||||
<div class="info-line">
|
||||
击杀 {{ m.killcnt }} 死亡 {{ m.deadcnt }} 助攻 {{ m.assistcnt }} 时长 {{ m.time_str }}
|
||||
</div>
|
||||
|
||||
<!-- 巅峰赛积分放原评分位置 -->
|
||||
<!-- 巅峰赛积分(原 KDA 位置) -->
|
||||
<div class="master-score">
|
||||
巅峰赛积分 {{ m.oldMasterMatchScore }} → {{ m.newMasterMatchScore }}
|
||||
</div>
|
||||
|
||||
<!-- KDA 信息(原巅峰赛位置) -->
|
||||
<div class="kda-info">
|
||||
击杀 {{ m.killcnt }} 死亡 {{ m.deadcnt }} 助攻 {{ m.assistcnt }} 时长 {{ m.time_str }}
|
||||
</div>
|
||||
|
||||
<!-- 新增成就显示 -->
|
||||
<div class="achievement-tags">
|
||||
{% if m.godLikeCnt > 0 %}<span>超神 × {{ m.godLikeCnt }}</span>{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user