mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 13:17:32 +00:00
feature:支持Enka面板更新:%更新展柜面板
This commit is contained in:
parent
0fea67a389
commit
21b8915418
25 changed files with 36048 additions and 382 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue