mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-17 21:57:44 +00:00
按钮能力支持
This commit is contained in:
parent
800bc15007
commit
d390381a12
3 changed files with 161 additions and 12 deletions
48
apps/help.js
48
apps/help.js
|
|
@ -289,7 +289,38 @@ export class Help extends ZZZPlugin {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async help() {
|
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) {
|
if (this.e?.isMaster) {
|
||||||
|
buts.push([
|
||||||
|
{ text: '插件更新', callback: `%插件更新` },
|
||||||
|
{ text: '下载资源', callback: `%下载全部资源` }
|
||||||
|
]);
|
||||||
const _helpData = [
|
const _helpData = [
|
||||||
...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;
|
return false;
|
||||||
}
|
}
|
||||||
await this.render('help/index.html', {
|
|
||||||
helpData,
|
await this.e.reply([await this.render('help/index.html', {helpData },{retType:'base64'})
|
||||||
});
|
,segment.button(...buts)]);
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ export class Panel extends ZZZPlugin {
|
||||||
{ key: 'zzz.tool.panelList', fn: 'getCharPanelListTool' },
|
{ key: 'zzz.tool.panelList', fn: 'getCharPanelListTool' },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
global.zzzRoleList = [];
|
||||||
|
global.ifNewChar = false;
|
||||||
}
|
}
|
||||||
async handleRule() {
|
async handleRule() {
|
||||||
if (!this.e.msg) return;
|
if (!this.e.msg) return;
|
||||||
|
|
@ -57,27 +59,61 @@ export class Panel extends ZZZPlugin {
|
||||||
const panelSettings = settings.getConfig('panel');
|
const panelSettings = settings.getConfig('panel');
|
||||||
const coldTime = _.get(panelSettings, 'interval', 300);
|
const coldTime = _.get(panelSettings, 'interval', 300);
|
||||||
if (lastQueryTime && Date.now() - lastQueryTime < 1000 * coldTime) {
|
if (lastQueryTime && Date.now() - lastQueryTime < 1000 * coldTime) {
|
||||||
await this.reply(`${coldTime}秒内只能刷新一次,请稍后再试`);
|
await this.reply([
|
||||||
|
`你看,又急~${coldTime}秒内只能刷新一次,请稍后再试`,
|
||||||
|
segment.button([{ text: '再试一下', callback: '%更新面板' }])
|
||||||
|
]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const { api } = await this.getAPI();
|
const { api } = await this.getAPI();
|
||||||
await redis.set(`ZZZ:PANEL:${uid}:LASTTIME`, Date.now());
|
await redis.set(`ZZZ:PANEL:${uid}:LASTTIME`, Date.now());
|
||||||
await this.reply('正在刷新面板列表,请稍候...');
|
await this.reply('正在刷新面板列表,可能需要数分钟或者更长时间,请稍候...如需查看现有角色请使用%面板列表');
|
||||||
await this.getPlayerInfo();
|
await this.getPlayerInfo();
|
||||||
const result = await refreshPanelFunction(api).catch(e => {
|
const result = await refreshPanelFunction(api).catch(e => {
|
||||||
this.reply(e.message);
|
this.reply(e.message);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
if (!result) {
|
if (!result) {
|
||||||
await this.reply('面板列表刷新失败,请稍后再试');
|
global.zzzRoleList = [];
|
||||||
|
global.ifNewChar = false;
|
||||||
|
await this.reply([
|
||||||
|
'面板列表刷新失败,请稍后再试,可尝试绑定设备或扫码登录后再次查询',
|
||||||
|
segment.button([{ text: '再试一下', callback: '%更新面板' }])
|
||||||
|
]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const newChar = result.filter(item => item.isNew);
|
const newChar = result.filter(item => item.isNew);
|
||||||
|
global.ifNewChar = newChar.length > 0;
|
||||||
const finalData = {
|
const finalData = {
|
||||||
newChar: newChar.length,
|
newChar: newChar.length,
|
||||||
list: result,
|
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() {
|
async getCharPanelList() {
|
||||||
const uid = await this.getUID();
|
const uid = await this.getUID();
|
||||||
|
|
@ -123,6 +159,7 @@ export class Panel extends ZZZPlugin {
|
||||||
const name = match[4];
|
const name = match[4];
|
||||||
const data = getPanelOrigin(uid, name);
|
const data = getPanelOrigin(uid, name);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
global.zzzCurrentCharName = data.name_mi18n || name;
|
||||||
await this.reply(`未找到角色${name}的面板信息,请先刷新面板`);
|
await this.reply(`未找到角色${name}的面板信息,请先刷新面板`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -154,6 +191,7 @@ export class Panel extends ZZZPlugin {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
global.zzzCurrentCharName = data.name_mi18n || name;
|
||||||
await this.reply('数据为空');
|
await this.reply('数据为空');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +218,22 @@ export class Panel extends ZZZPlugin {
|
||||||
}) : needImg;
|
}) : needImg;
|
||||||
|
|
||||||
if (reply) {
|
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)
|
if (res?.message_id && parsedData.role_icon)
|
||||||
await redis.set(
|
await redis.set(
|
||||||
`ZZZ:PANEL:IMAGE:${res.message_id}`,
|
`ZZZ:PANEL:IMAGE:${res.message_id}`,
|
||||||
|
|
|
||||||
62
lain.support.js
Normal file
62
lain.support.js
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue