From d390381a1252e16c152904989f42c6b362cfaec6 Mon Sep 17 00:00:00 2001 From: xyz <15380362192@163.com> Date: Mon, 5 May 2025 22:09:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E9=92=AE=E8=83=BD=E5=8A=9B=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/help.js | 48 +++++++++++++++++++++++++++++++------ apps/panel.js | 63 +++++++++++++++++++++++++++++++++++++++++++++---- lain.support.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+), 12 deletions(-) create mode 100644 lain.support.js diff --git a/apps/help.js b/apps/help.js index a7ee45a..54b2cc3 100644 --- a/apps/help.js +++ b/apps/help.js @@ -289,7 +289,38 @@ export class Help extends ZZZPlugin { }); } async help() { + let buts = [ + [ + { text: '卡片', callback: `%card` }, + { text: '体力', callback: `%体力` }, + { text: '面板', callback: `%更新面板` }, + { text: '练度', callback: `%练度统计` } + ], + [ + { text: '抽卡', callback: `%抽卡记录` }, + { text: '月报', callback: `%月报` }, + { text: '深渊', callback: `%深渊` }, + { text: '强袭', callback: `%强袭` } + ], + [ + { text: '刷新', callback: `%刷新面板` }, + { text: '更新抽卡', callback: `%更新抽卡记录` }, + { text: '电量', callback: `%电量` }, + { text: '兑换码', callback: `%兑换码` } + ], + [ + { text: '绑UID', input: `%绑定uid` }, + { text: '扫码', callback: `#扫码登录` }, + { text: '绑定设备', callback: '%绑定设备' } + ],[ + {text: '项目地址',link:'https://github.com/ZZZure/ZZZeroUID'} + ] + ]; if (this.e?.isMaster) { + buts.push([ + { text: '插件更新', callback: `%插件更新` }, + { text: '下载资源', callback: `%下载全部资源` } + ]); const _helpData = [ ...helpData, { @@ -409,14 +440,17 @@ export class Help extends ZZZPlugin { ], }, ]; - await this.render('help/index.html', { - helpData: _helpData, - }); + + + await this.e.reply([await this.render('help/index.html', {helpData: _helpData, },{retType:'base64'}),segment.button(...buts)]); return false; } - await this.render('help/index.html', { - helpData, - }); - return false; + + await this.e.reply([await this.render('help/index.html', {helpData },{retType:'base64'}) +,segment.button(...buts)]); + return false; + + } + } diff --git a/apps/panel.js b/apps/panel.js index 7fb8e34..cd852e1 100644 --- a/apps/panel.js +++ b/apps/panel.js @@ -37,6 +37,8 @@ export class Panel extends ZZZPlugin { { key: 'zzz.tool.panelList', fn: 'getCharPanelListTool' }, ], }); + global.zzzRoleList = []; + global.ifNewChar = false; } async handleRule() { if (!this.e.msg) return; @@ -57,27 +59,61 @@ 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}秒内只能刷新一次,请稍后再试`, + segment.button([{ text: '再试一下', callback: '%更新面板' }]) +]); return false; } const { api } = await this.getAPI(); await redis.set(`ZZZ:PANEL:${uid}:LASTTIME`, Date.now()); - await this.reply('正在刷新面板列表,请稍候...'); + await this.reply('正在刷新面板列表,可能需要数分钟或者更长时间,请稍候...如需查看现有角色请使用%面板列表'); await this.getPlayerInfo(); const result = await refreshPanelFunction(api).catch(e => { this.reply(e.message); throw e; }); if (!result) { - await this.reply('面板列表刷新失败,请稍后再试'); + global.zzzRoleList = []; + global.ifNewChar = false; + await this.reply([ + '面板列表刷新失败,请稍后再试,可尝试绑定设备或扫码登录后再次查询', + segment.button([{ text: '再试一下', callback: '%更新面板' }]) +]); return false; } const newChar = result.filter(item => item.isNew); + global.ifNewChar = newChar.length > 0; const finalData = { newChar: newChar.length, list: result, }; - await this.render('panel/refresh.html', finalData); + const role_list = result.map(item => item.name_mi18n); + global.zzzRoleList = roleList; + let buttons = [[]]; +const nonChineseOrDigitRegex = /[^\u4E00-\u9FFF0-9]/g; + +for (const original_name of role_list) { + let currentRow = buttons[buttons.length - 1]; + const cleanedName = original_name.replace(nonChineseOrDigitRegex, ''); + const buttonText = cleanedName.length > 0 ? cleanedName[0] : ''; + const button = { text: buttonText, callback: `%${original_name}面板` }; + currentRow.push(button); + if (currentRow.length >= 6) { // 每行最多6个 + buttons.push([]); + } +} +// 处理空列表或最后一个空行 +if (buttons.length === 1 && buttons[0].length === 0) { + buttons[0] = [ // 默认按钮 + { text: "更新面板", callback: `%更新面板` }, + { text: "练度统计", callback: "%练度统计" } + ]; +} else if (buttons[buttons.length - 1].length === 0) { + buttons.pop(); +} +await this.reply([await this.render('panel/refresh.html', finalData, { retType: 'base64' }), segment.button(...buttons)]); + } async getCharPanelList() { const uid = await this.getUID(); @@ -123,6 +159,7 @@ export class Panel extends ZZZPlugin { const name = match[4]; const data = getPanelOrigin(uid, name); if (!data) { + global.zzzCurrentCharName = data.name_mi18n || name; await this.reply(`未找到角色${name}的面板信息,请先刷新面板`); return; } @@ -154,6 +191,7 @@ export class Panel extends ZZZPlugin { return false; } if (!data) { + global.zzzCurrentCharName = data.name_mi18n || name; await this.reply('数据为空'); return false; } @@ -180,7 +218,22 @@ export class Panel extends ZZZPlugin { }) : needImg; if (reply) { - const res = await this.reply(image); + let role = parsedData.name_mi18n; + let buts = [ + [{ text: '看看我的面板', callback: '%更新面板' }], + [ + { text: `${role}攻略`, callback: `%${role}攻略` }, + { text: `练度统计`, callback: `%练度统计` }, + { text: `${role}图鉴`, callback: `%${role}图鉴` } + ], + [ + { text: `电量`, callback: `%体力` }, + { text: `项目地址`, link: `https://github.com/ZZZure/ZZZeroUID` }, + { text: `伤害`, callback: `%${role}伤害` } + ], + ]; + const res = await this.reply([image, segment.button(...buts)]); + if (res?.message_id && parsedData.role_icon) await redis.set( `ZZZ:PANEL:IMAGE:${res.message_id}`, diff --git a/lain.support.js b/lain.support.js new file mode 100644 index 0000000..2a93baa --- /dev/null +++ b/lain.support.js @@ -0,0 +1,62 @@ + +export default class Button { + constructor() { + this.plugin = { + name: 'zzz-plugin-support-global', + dsc: 'zzz-plugin button support (uses global vars)', + priority: 50, // 确保在 Panel(70) 之后运行 + rule: [ + { reg: '#绝区零更新面板|#绝区零面板更新|#绝区零刷新面板|#绝区零面板刷新$', fnc: 'profile1' }, + { reg: '#绝区零(.*)面板(.*)$', fnc: 'handleRule' }, + ] + } + } + + profile1(e) { + const roleList = global.zzzRoleList || []; + const ifNewChar = global.ifNewChar || false; + + const button = []; + + const staticList = [ + { label: `更新面板`, callback: `%更新面板` }, + { label: '绑定UID', callback: `%绑定` }, + { label: '扫码绑定', callback: `#扫码登录` }, + { label: '绑定设备', callback: `%绑定设备帮助` }, + ]; + + button.push(...Bot.Button(staticList)); + + if (ifNewChar && roleList.length > 0) { + const charButtonList = roleList.map(role => ({ + label: role, callback: `%${role}面板` + })); + button.push(...Bot.Button(charButtonList, 4)); + } else { + } + + return button.length > 0 ? button : null; + } + + handleRule(e) { + let charName = ''; + if (global.zzzCurrentCharName) { + charName = global.zzzCurrentCharName; + } else { + return null; + } + } + + const buttonRows = [ + [{ label: `更新面板`, callback: `%更新面板` }], + [ + { label: `${charName}攻略`, callback: `%${charName}攻略` }, + { label: `练度统计`, callback: `%练度统计` }, + { label: `${charName}图鉴`, callback: `%${charName}图鉴` }, + ], + [{ label: `签到`, callback: `%签到` }, { label: `伤害`, callback: `%${charName}伤害` } { label: `电量`, callback: `%体力` }] // 可以合并常用的 + ]; + + return Bot.Button(buttonRows); + } +}