From f0ef2bd624e0931aa8b98c7efc6231061e84d518 Mon Sep 17 00:00:00 2001 From: bietiaop <1527109126@qq.com> Date: Mon, 8 Jul 2024 17:01:24 +0800 Subject: [PATCH] fix: note --- apps/gachalog.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ apps/note.js | 7 +++---- lib/mysapi.js | 10 ++++----- lib/plugin.js | 10 ++++++--- 4 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 apps/gachalog.js diff --git a/apps/gachalog.js b/apps/gachalog.js new file mode 100644 index 0000000..609b0d3 --- /dev/null +++ b/apps/gachalog.js @@ -0,0 +1,53 @@ +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'; + +export class GachaLog extends ZZZPlugin { + constructor() { + super({ + name: '[ZZZ-Plugin]GachaLog', + dsc: 'zzzGachaLog', + event: 'message', + priority: 100, + rule: [ + { + reg: `${rulePrefix}抽卡记录$`, + fnc: 'gachaLog', + }, + ], + }); + } + async gachaLog(e) { + const { api, deviceFp } = await this.getAPI(); + if (!api) return false; + let userData = await api.getData('zzzUser'); + if (!userData?.data || _.isEmpty(userData.data.list)) { + await e.reply('[zzznote]玩家信息获取失败'); + return false; + } + userData = userData?.data?.list[0]; + let noteData = await api.getData('zzzNote', { deviceFp }); + noteData = await api.checkCode(e, noteData, 'zzzNote', {}); + if (!noteData || noteData.retcode !== 0) { + await e.reply('[zzznote]每日数据获取失败'); + return false; + } + noteData = noteData.data; + noteData = new ZZZNoteResp(noteData); + let avatar = this.e.bot.avatar; + // 头像 + if (this.e.member?.getAvatarUrl) { + avatar = await this.e.member.getAvatarUrl(); + } else if (this.e.friend?.getAvatarUrl) { + avatar = await this.e.friend.getAvatarUrl(); + } + const finalData = { + avatar, + player: userData, + note: noteData, + }; + await render(e, 'note/index.html', finalData); + } +} diff --git a/apps/note.js b/apps/note.js index 796fd84..d78d3cf 100644 --- a/apps/note.js +++ b/apps/note.js @@ -1,11 +1,10 @@ import { ZZZPlugin } from '../lib/plugin.js'; -import MysZZZApi from '../lib/mysapi.js'; -import { getCk } from '../lib/common.js'; import _ from 'lodash'; import render from '../lib/render.js'; import { ZZZNoteResp } from '../model/note.js'; +import { rulePrefix } from '../lib/common.js'; -export class test extends ZZZPlugin { +export class Note extends ZZZPlugin { constructor() { super({ name: '[ZZZ-Plugin]Note', @@ -14,7 +13,7 @@ export class test extends ZZZPlugin { priority: 100, rule: [ { - reg: `^#zzznote$`, + reg: `${rulePrefix}note$`, fnc: 'note', }, ], diff --git a/lib/mysapi.js b/lib/mysapi.js index 2401350..6cb320b 100644 --- a/lib/mysapi.js +++ b/lib/mysapi.js @@ -33,17 +33,17 @@ export default class MysZZZApi extends MysApi { getServer() { const _uid = this.uid.toString(); if (_uid.length < 10) { - return game_region[this.game][0]; // 官服 + return game_region[0]; // 官服 } switch (_uid.slice(0, -8)) { case '10': - return game_region[this.game][2]; // 美服 + return game_region[2]; // 美服 case '15': - return game_region[this.game][3]; // 欧服 + return game_region[3]; // 欧服 case '13': - return game_region[this.game][4]; // 亚服 + return game_region[4]; // 亚服 case '17': - return game_region[this.game][5]; // 港澳台服 + return game_region[5]; // 港澳台服 } } diff --git a/lib/plugin.js b/lib/plugin.js index 908ce0d..6eddf3d 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -4,20 +4,24 @@ import _ from 'lodash'; import NoteUser from '../../genshin/model/mys/NoteUser.js'; export class ZZZPlugin extends plugin { - async getAPI() { + async getUID() { let user = this.e; if (this.e.at) { user = this.e.at; } this.User = await NoteUser.create(user); - logger.mark(this.User); - logger.mark(this.User.getUid('zzz')); let uid = this.e.msg.match(/\d+/)?.[0]; uid = uid || this.User?.getUid('zzz'); if (!uid) { await this.reply('uid为空,米游社查询请先绑定cookie,其他查询请携带uid'); return false; } + return uid; + } + async getAPI() { + uid = await this.getUID(); + if (!uid) return false; + const ck = await getCk(this.e); if (!ck || Object.keys(ck).filter(k => ck[k].ck).length === 0) { await this.reply('尚未绑定cookie,请先绑定cookie');