feat: base panel

This commit is contained in:
bietiaop 2024-07-12 02:43:32 +08:00
parent cbef7478c2
commit ac0c3d0d6c
12 changed files with 361 additions and 149 deletions

View file

@ -1,5 +1,4 @@
import { ZZZPlugin } from '../lib/plugin.js';
import _ from 'lodash';
import render from '../lib/render.js';
import { rulePrefix } from '../lib/common.js';
import { ZZZIndexResp } from '../model/index.js';
@ -23,25 +22,27 @@ export class Card extends ZZZPlugin {
const { api, deviceFp } = await this.getAPI();
if (!api) return false;
await this.getPlayerInfo();
let indexData = await api.getData('zzzIndex', { deviceFp });
indexData = await api.checkCode(this.e, indexData, 'zzzIndex', {});
if (!indexData || indexData.retcode !== 0) {
await this.reply('[zzznote]Index数据获取失败');
return false;
}
indexData = indexData.data;
const indexData = await api.getFinalData(this.e, 'zzzIndex', { deviceFp });
if (!indexData) return false;
let zzzAvatarList = await api.getData('zzzAvatarList', { deviceFp });
indexData.avatar_list = zzzAvatarList.data.avatar_list;
let zzzAvatarList = await api.getFinalData(this.e, 'zzzAvatarList', {
deviceFp,
});
if (!zzzAvatarList) return false;
indexData.avatar_list = zzzAvatarList.avatar_list;
let zzzBuddyList = await api.getData('zzzBuddyList', { deviceFp });
indexData.buddy_list = zzzBuddyList.data.list;
let zzzBuddyList = await api.getFinalData(this.e, 'zzzBuddyList', {
deviceFp,
});
if (!zzzBuddyList) return false;
indexData.buddy_list = zzzBuddyList.list;
indexData = new ZZZIndexResp(indexData);
this.e.playerCard.player.region_name = indexData.stats.world_level_name;
await indexData.get_assets();
const finalIndexData = new ZZZIndexResp(indexData);
this.e.playerCard.player.region_name =
finalIndexData.stats.world_level_name;
await finalIndexData.get_assets();
const data = {
card: indexData,
card: finalIndexData,
};
await render(this.e, 'card/index.html', data);
}

View file

@ -1,5 +1,4 @@
import { ZZZPlugin } from '../lib/plugin.js';
import _ from 'lodash';
import render from '../lib/render.js';
import { rulePrefix } from '../lib/common.js';
import { getAuthKey } from '../lib/authkey.js';

View file

@ -1,5 +1,4 @@
import { ZZZPlugin } from '../lib/plugin.js';
import _ from 'lodash';
import { rulePrefix } from '../lib/common.js';
export class Help extends ZZZPlugin {

View file

@ -1,5 +1,4 @@
import { ZZZPlugin } from '../lib/plugin.js';
import _ from 'lodash';
import render from '../lib/render.js';
import { ZZZNoteResp } from '../model/note.js';
import { rulePrefix } from '../lib/common.js';
@ -23,14 +22,11 @@ export class Note extends ZZZPlugin {
const { api, deviceFp } = await this.getAPI();
if (!api) return false;
await this.getPlayerInfo();
let noteData = await api.getData('zzzNote', { deviceFp });
noteData = await api.checkCode(this.e, noteData, 'zzzNote', {});
if (!noteData || noteData.retcode !== 0) {
await this.reply('[zzznote]每日数据获取失败');
return false;
}
noteData = noteData.data;
noteData = new ZZZNoteResp(noteData);
const noteResponse = await api.getFinalData(this.e, 'zzzNote', {
deviceFp,
});
if (!noteResponse) return false;
const noteData = new ZZZNoteResp(noteResponse);
const finalData = {
note: noteData,
};

View file

@ -1,8 +1,7 @@
import { ZZZPlugin } from '../lib/plugin.js';
import _ from 'lodash';
import render from '../lib/render.js';
import { ZZZNoteResp } from '../model/note.js';
import { rulePrefix } from '../lib/common.js';
import { getPanelList, refreshPanel, getPanel } from '../lib/avatar.js';
export class Panel extends ZZZPlugin {
constructor() {
@ -16,25 +15,60 @@ export class Panel extends ZZZPlugin {
reg: `${rulePrefix}((刷新|更新)面板|面板(刷新|更新))$`,
fnc: 'refreshPanel',
},
{
reg: `${rulePrefix}面板列表$`,
fnc: 'getPanelList',
},
{
reg: `${rulePrefix}(.+)面板$`,
fnc: 'getPanel',
},
],
});
}
async refreshPanel() {
const { api, deviceFp } = await this.getAPI();
if (!api) return false;
await this.reply('TODO');
// await this.getPlayerInfo();
// let noteData = await api.getData('zzzNote', { deviceFp });
// noteData = await api.checkCode(this.e, noteData, 'zzzNote', {});
// if (!noteData || noteData.retcode !== 0) {
// await this.reply('[zzznote]每日数据获取失败');
// return false;
// }
// noteData = noteData.data;
// noteData = new ZZZNoteResp(noteData);
const { api, deviceFp, uid } = await this.getAPI();
if (!api || !uid) return false;
await this.getPlayerInfo();
const result = await refreshPanel(this.e, api, uid, deviceFp);
const newChar = result.filter(item => item.isNew);
let str = '面板列表获取成功,本次共刷新了' + newChar.length + '个角色:';
for (const item of result) {
str += '\n' + item.name_mi18n;
}
str += '\n总计' + result.length + '个角色';
await this.reply(str);
// const finalData = {
// note: noteData,
// list: noteData,
// };
// await render(this.e, 'note/index.html', finalData);
// await render(this.e, 'panel/refresh.html', finalData);
}
async getPanelList() {
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 += '\n' + item.name_mi18n;
}
await this.reply(str);
// const finalData = {
// list: noteData,
// };
// await render(this.e, 'panel/list.html', finalData);
}
async getPanel() {
const uid = await this.getUID();
if (!uid) return false;
const reg = new RegExp(`${rulePrefix}(.+)面板$`);
const name = this.e.msg.match(reg)[4];
const data = getPanel(uid, name);
await this.reply(JSON.stringify(data, null, 2));
// const finalData = {
// list: noteData,
// };
// await render(this.e, 'panel/list.html', finalData);
}
}