feature:支持Enka面板更新:%更新展柜面板

This commit is contained in:
UCPr 2025-06-09 15:40:27 +08:00
parent 0fea67a389
commit 21b8915418
25 changed files with 36048 additions and 382 deletions

View file

@ -101,10 +101,10 @@ const helpData = [
items: [
{
title: '刷新角色面板',
desc: '刷新角色面板',
desc: '%更新展柜面板 通过Enka接口获取游戏内展柜角色无需CK',
needCK: true,
needSK: false,
commands: ['刷新面板', '更新面板', '面板刷新', '面板更新'],
commands: ['刷新面板', '更新面板', '刷新/更新展柜面板'],
},
{
title: '查看角色面板列表',
@ -115,10 +115,10 @@ const helpData = [
},
{
title: '查看角色面板',
desc: '查看角色详细面板信息',
desc: '查看角色详细面板/技能伤害信息',
needCK: false,
needSK: false,
commands: ['角色名+面板'],
commands: ['角色名+面板', '角色名+伤害'],
},
{
title: '查看角色面板图',

View file

@ -1,5 +1,8 @@
import { ZZZPlugin } from '../lib/plugin.js';
import { parsePlayerInfo, refreshPanelFromEnka } from '../model/Enka/enkaApi.js';
import { getCk } from '../lib/common.js';
import {
mergePanel,
getPanelList,
refreshPanel as refreshPanelFunction,
getPanelOrigin,
@ -20,7 +23,7 @@ export class Panel extends ZZZPlugin {
priority: _.get(settings.getConfig('priority'), 'panel', 70),
rule: [
{
reg: `${rulePrefix}(.*)面板(刷新|更新|列表)?$`,
reg: `${rulePrefix}(.*)面板(展柜)?(刷新|更新|列表)?$`,
fnc: 'handleRule',
},
{
@ -40,7 +43,7 @@ export class Panel extends ZZZPlugin {
}
async handleRule() {
if (!this.e.msg) return;
const reg = new RegExp(`${rulePrefix}(.*)面板(刷新|更新|列表)?$`);
const reg = new RegExp(`${rulePrefix}(.*?)(?:展柜)?面板(?:展柜)?(刷新|更新|列表)?$`);
const pre = this.e.msg.match(reg)[4]?.trim();
const suf = this.e.msg.match(reg)[5]?.trim();
if (['刷新', '更新'].includes(pre) || ['刷新', '更新'].includes(suf))
@ -57,19 +60,36 @@ export class Panel extends ZZZPlugin {
const panelSettings = settings.getConfig('panel');
const coldTime = _.get(panelSettings, 'interval', 300);
if (lastQueryTime && Date.now() - lastQueryTime < 1000 * coldTime) {
await this.reply(`${coldTime}秒内只能新一次,请稍后再试`);
await this.reply(`${coldTime}秒内只能新一次,请稍后再试`);
return false;
}
const { api, deviceFp } = await this.getAPI();
await redis.set(`ZZZ:PANEL:${uid}:LASTTIME`, Date.now());
await this.reply('正在刷新面板列表,请稍候...');
await this.getPlayerInfo();
const result = await refreshPanelFunction(api, deviceFp).catch(e => {
this.reply(e.message);
throw e;
});
const isEnka = this.e.msg.includes('展柜') || !(await getCk(this.e))
let result
if (isEnka) {
const data = await refreshPanelFromEnka(uid)
await redis.set(`ZZZ:PANEL:${uid}:LASTTIME`, Date.now());
if (typeof data === 'object') {
const { playerInfo, panelList } = data
if (!panelList.length) {
return this.reply('面板列表为空,请确保已在游戏中展示了对应角色');
}
result = await mergePanel(uid, panelList)
await this.getPlayerInfo(playerInfo)
} else if (typeof data === 'number'){
return this.reply(`Enka服务调用失败状态码${data}${data === 424 ? '\n版本更新后须等待一段时间才可正常使用enka服务' : ''}`);
}
} else {
const { api, deviceFp } = await this.getAPI();
await this.reply('正在更新面板列表,请稍候...');
await this.getPlayerInfo();
await redis.set(`ZZZ:PANEL:${uid}:LASTTIME`, Date.now());
result = await refreshPanelFunction(api, deviceFp).catch(e => {
this.reply(e.message);
throw e;
});
}
if (!result) {
await this.reply('面板列表刷新失败,请稍后再试');
await this.reply('面板列表更新失败,请稍后再试\n账号异常时可尝试%更新展柜面板所更新角色数据与实际不一致时请提issue');
return false;
}
const newChar = result.filter(item => item.isNew);
@ -79,14 +99,16 @@ export class Panel extends ZZZPlugin {
};
await this.render('panel/refresh.html', finalData);
}
async getCharPanelList() {
const uid = await this.getUID();
const result = getPanelList(uid);
if (!result) {
await this.reply('未找到面板数据,请先%刷新面板');
if (!result.length) {
await this.reply(`UID:${uid}无本地面板数据,请先%更新面板 或 %更新展柜面板`);
return false;
}
await this.getPlayerInfo();
const hasCk = !!(await getCk(this.e));
await this.getPlayerInfo(hasCk ? undefined : parsePlayerInfo({ uid }));
const timer = setTimeout(() => {
if (this?.reply) {
this.reply('查询成功,正在下载图片资源,请稍候。');
@ -123,7 +145,7 @@ export class Panel extends ZZZPlugin {
const name = match[4];
const data = getPanelOrigin(uid, name);
if (!data) {
await this.reply(`未找到角色${name}的面板信息,请先刷新面板`);
await this.reply(`未找到角色${name}的面板信息,请确保角色名称/别称存在且已更新面板`);
return;
}
let handler = this.e.runtime.handler || {};
@ -201,7 +223,7 @@ export class Panel extends ZZZPlugin {
const uid = await this.getUID();
const result = getPanelList(uid);
if (!result) {
await this.reply('未找到面板数据,请先%刷新面板');
await this.reply('未找到面板数据,请先%更新面板 或 %更新展柜面板');
return false;
}
await this.getPlayerInfo();