mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-15 12:47:48 +00:00
优化角色面板提示信息#135
This commit is contained in:
parent
e9d912f118
commit
80b39c9864
4 changed files with 35 additions and 14 deletions
|
|
@ -30,8 +30,10 @@ export class Damage extends ZZZPlugin {
|
|||
if (!match) return false
|
||||
const name = match[4]
|
||||
const data = getPanelOrigin(uid, name)
|
||||
if (!data) {
|
||||
return this.reply(`未找到角色${name}的面板信息,请先刷新面板`)
|
||||
if (data === false) {
|
||||
return this.reply(`角色${name}不存在,请确保角色名称/别称存在`)
|
||||
} else if (data === null) {
|
||||
return this.reply(`暂无角色${name}面板数据,请先%更新面板`)
|
||||
}
|
||||
const parsedData = formatPanelData(data)
|
||||
const calc = avatar_calc(parsedData)
|
||||
|
|
|
|||
|
|
@ -67,15 +67,20 @@ export class Panel extends ZZZPlugin {
|
|||
let result
|
||||
if (isEnka) {
|
||||
const data = await refreshPanelFromEnka(uid)
|
||||
await redis.set(`ZZZ:PANEL:${uid}:LASTTIME`, Date.now());
|
||||
.catch(err => err)
|
||||
if (data instanceof Error) {
|
||||
logger.warn(`Enka服务调用失败:`, data)
|
||||
return this.reply(`Enka服务调用失败:${data.message}`)
|
||||
}
|
||||
await redis.set(`ZZZ:PANEL:${uid}:LASTTIME`, Date.now())
|
||||
if (typeof data === 'object') {
|
||||
const { playerInfo, panelList } = data
|
||||
if (!panelList.length) {
|
||||
return this.reply('面板列表为空,请确保已在游戏中展示了对应角色');
|
||||
return this.reply('面板列表为空,请确保已于游戏中展示角色')
|
||||
}
|
||||
result = await mergePanel(uid, panelList)
|
||||
await this.getPlayerInfo(playerInfo)
|
||||
} else if (typeof data === 'number'){
|
||||
} else if (typeof data === 'number') {
|
||||
return this.reply(`Enka服务调用失败,状态码:${data}${data === 424 ? '\n版本更新后,须等待一段时间才可正常使用enka服务' : ''}`);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -144,9 +149,10 @@ export class Panel extends ZZZPlugin {
|
|||
if (!match) return false;
|
||||
const name = match[4];
|
||||
const data = getPanelOrigin(uid, name);
|
||||
if (!data) {
|
||||
await this.reply(`未找到角色${name}的面板信息,请确保角色名称/别称存在且已更新面板`);
|
||||
return;
|
||||
if (data === false) {
|
||||
return this.reply(`角色${name}不存在,请确保角色名称/别称存在`);
|
||||
} else if (data === null) {
|
||||
return this.reply(`暂无角色${name}面板数据,请先%更新面板`);
|
||||
}
|
||||
let handler = this.e.runtime.handler || {};
|
||||
|
||||
|
|
|
|||
|
|
@ -144,12 +144,12 @@ export const getPanelListOrigin = uid => {
|
|||
* 获取某个角色的面板数据
|
||||
* @param {string} uid
|
||||
* @param {string} name
|
||||
* @returns {ZZZAvatarInfo | null}
|
||||
* @returns {ZZZAvatarInfo | null | false}
|
||||
*/
|
||||
export const getPanel = (uid, name) => {
|
||||
// 通过名称(包括别名)获取角色 ID
|
||||
const id = char.aliasToID(name);
|
||||
if (!id) return null;
|
||||
if (!id) return false;
|
||||
const _data = getPanelData(uid);
|
||||
// 获取所有面板数据
|
||||
const data = _data.map(item => new ZZZAvatarInfo(item));
|
||||
|
|
@ -163,11 +163,11 @@ export const getPanel = (uid, name) => {
|
|||
* 获取某个角色的面板数据(原始数据)
|
||||
* @param {string} uid
|
||||
* @param {string} name
|
||||
* @returns {ZZZAvatarInfo | null}
|
||||
* @returns {ZZZAvatarInfo | null | false}
|
||||
*/
|
||||
export const getPanelOrigin = (uid, name) => {
|
||||
const id = char.aliasToID(name);
|
||||
if (!id) return null;
|
||||
if (!id) return false;
|
||||
const data = getPanelData(uid);
|
||||
// 通过 ID 获取角色数据
|
||||
const result = data.find(item => item.id === id);
|
||||
|
|
|
|||
|
|
@ -60,10 +60,23 @@ export async function refreshPanelFromEnka(uid) {
|
|||
logger.warn('Enka更新面板失败:获取面板数据失败')
|
||||
return res.status
|
||||
}
|
||||
if (!panelList.length)
|
||||
console.log('面板列表为空')
|
||||
return {
|
||||
playerInfo: parsePlayerInfo(data.PlayerInfo.SocialDetail),
|
||||
panelList: Enka2Mys(panelList)
|
||||
}
|
||||
}
|
||||
|
||||
// import fs from 'fs'
|
||||
// const uid = 11070609
|
||||
// const res = await fetch(`${EnkaApi}${uid}`, {
|
||||
// method: 'GET',
|
||||
// headers: {
|
||||
// 'User-Agent': 'ZZZ-Plugin/UCPr',
|
||||
// }
|
||||
// })
|
||||
// if (!res.ok) {
|
||||
// console.log(`Enka更新面板失败:${res.status} ${res.statusText}`)
|
||||
// }
|
||||
// const data = await res.json()
|
||||
// console.log(data)
|
||||
// fs.writeFileSync('enkaPanel1.json', JSON.stringify(data, null, 2))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue