From b69b44b0f5c721802d8c71fa0d56199fb11cb7bf Mon Sep 17 00:00:00 2001 From: yysforget <1121504223@qq.com> Date: Thu, 18 Jul 2024 11:48:32 +0800 Subject: [PATCH] fix:panel --- lib/avatar.js | 2 +- resources/panel/panel.js | 106 --------------------------------------- 2 files changed, 1 insertion(+), 107 deletions(-) delete mode 100644 resources/panel/panel.js diff --git a/lib/avatar.js b/lib/avatar.js index c554332..4b5cb59 100644 --- a/lib/avatar.js +++ b/lib/avatar.js @@ -85,7 +85,7 @@ export const refreshPanel = async (e, api, uid, deviceFp) => { savePanelData(uid, finalData); // 格式化数据 finalData.forEach(item => { - item.isNew = newData.find(i => i.id === item.id); + item.isNew = !!newData.find(i => i.id === item.id); }); const formattedData = finalData.map(item => new ZZZAvatarInfo(item)); for (const item of formattedData) { diff --git a/resources/panel/panel.js b/resources/panel/panel.js deleted file mode 100644 index 75127b4..0000000 --- a/resources/panel/panel.js +++ /dev/null @@ -1,106 +0,0 @@ -import { ZZZPlugin } from '../lib/plugin.js' -import render from '../lib/render.js' -import { rulePrefix } from '../lib/common.js' -import { getPanelList, refreshPanel, getPanel } from '../lib/avatar.js' -import settings from '../lib/settings.js' -import _ from 'lodash' - -export class Panel extends ZZZPlugin { - constructor() { - super({ - name: '[ZZZ-Plugin]Panel', - dsc: 'zzzpanel', - event: 'message', - priority: _.get(settings.getConfig('priority'), 'panel', 70), - rule: [ - { - reg: `${rulePrefix}((刷新|更新)面板|面板(刷新|更新))$`, - fnc: 'refreshPanel', - }, - { - reg: `${rulePrefix}面板(列表)?$`, - fnc: 'getCharPanelList', - }, - { - reg: `${rulePrefix}(.+)面板$`, - fnc: 'getCharPanel', - }, - ], - }) - } - async refreshPanel() { - const uid = await this.getUID() - if (!uid) return - const lastQueryTime = await redis.get(`ZZZ:PANEL:${uid}:LASTTIME`) - const panelSettings = settings.getConfig('panel') - const coldTime = _.get(panelSettings, 'interval', 300) - if (lastQueryTime && Date.now() - lastQueryTime < 1000 * coldTime) { - await this.reply(`${coldTime}秒内只能刷新一次,请稍后再试`) - return - } - const { api, deviceFp } = await this.getAPI() - if (!api) return false - await redis.set(`ZZZ:PANEL:${uid}:LASTTIME`, Date.now()) - await this.reply('正在刷新面板列表,请稍候...') - await this.getPlayerInfo() - const result = await refreshPanel(this.e, api, uid, deviceFp) - if (!result) { - await this.reply('面板列表刷新失败,请稍后再试') - return - } - const newChar = result.filter((item) => item.isNew) - // let str = '面板列表获取成功,本次共刷新了' + newChar.length + '个角色:\n' - // for (const item of result) { - // str += item.name_mi18n + (item.isNew ? '(新)' : '') + '、' - // } - // str = str.slice(0, -1) - // str += '\n总计' + result.length + '个角色' - // await this.reply(str) - const finalData = { - uid: uid, - newChar: newChar.length, - list: result, - } - await render(this.e, 'panel/refresh.html', finalData) - } - async getCharPanelList() { - const uid = await this.getUID() - if (!uid) return false - const noteData = getPanelList(uid) - if (!noteData) return false - await this.getPlayerInfo() - let str = '面板列表获取成功,共计' + noteData.length + '个角色:' - for (const item of noteData) { - str += item.name_mi18n + '、' - } - str = str.slice(0, -1) - await this.reply(str) - // const finalData = { - // list: noteData, - // }; - // await render(this.e, 'panel/list.html', finalData); - } - async getCharPanel() { - const uid = await this.getUID() - if (!uid) return false - const reg = new RegExp(`${rulePrefix}(.+)面板$`) - const name = this.e.msg.match(reg)[4] - if (['刷新', '更新'].includes(name)) return this.getCharPanelList() - const data = getPanel(uid, name) - if (!data) { - await this.reply(`未找到角色${name}的面板信息`) - return - } - const timer = setTimeout(() => { - if (this?.reply) { - this.reply('查询成功,正在下载图片资源,请稍候。') - } - }, 3000) - await data.get_detail_assets() - clearTimeout(timer) - const finalData = { - charData: data, - } - await render(this.e, 'panel/card.html', finalData) - } -}