diff --git a/apps/bind.js b/apps/bind.js deleted file mode 100644 index 75eebed..0000000 --- a/apps/bind.js +++ /dev/null @@ -1,26 +0,0 @@ -import { rulePrefix } from '../lib/common.js'; -import { ZZZPlugin } from '../lib/plugin.js'; - -export class bind extends ZZZPlugin { - constructor() { - super({ - name: '[ZZZ-Plugin]Bind', - dsc: 'zzzbind', - event: 'message', - priority: 100, - rule: [ - { - reg: `^${rulePrefix}绑定(uid|UID)?(\\s)?[1-9][0-9]{7,9}$`, - fnc: 'bindUid', - }, - ], - }); - } - async bindUid() { - const uid = parseInt(this.e.msg.replace(/[^0-9]/gi, '')); - const user = this.e.user_id; - await redis.set(`ZZZ:UID:${user}`, uid); - this.reply(`绑定成功,当前绑定[zzz]uid:${uid}`, false); - return false; - } -} diff --git a/apps/note.js b/apps/note.js index 5b84fb6..796fd84 100644 --- a/apps/note.js +++ b/apps/note.js @@ -22,6 +22,7 @@ export class test extends ZZZPlugin { } async note(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]玩家信息获取失败'); diff --git a/lib/authkey.js b/lib/authkey.js index 277f745..12a775a 100644 --- a/lib/authkey.js +++ b/lib/authkey.js @@ -1,4 +1,3 @@ -// import User from "../../xiaoyao-cvs-plugin/model/user.js"; import fetch from 'node-fetch'; import MysZZZApi from './mysapi.js'; let User; @@ -12,7 +11,7 @@ try { * 此方法依赖逍遥插件 * @returns {Promise} */ -export async function getAuthKey(e, srUid, authAppid = 'csc') { +export async function getAuthKey(e, zzzUid, authAppid = 'csc') { if (!User) { throw new Error('未安装逍遥插件,无法自动刷新抽卡链接'); } @@ -21,7 +20,7 @@ export async function getAuthKey(e, srUid, authAppid = 'csc') { await user.getCookie(e); let ck = await user.getStoken(e.user_id); ck = `stuid=${ck.stuid};stoken=${ck.stoken};mid=${ck.mid};`; - let api = new MysZZZApi(srUid, ck); + let api = new MysZZZApi(zzzUid, ck); let type = 'zzzPayAuthKey'; switch (authAppid) { case 'csc': { diff --git a/lib/mysapi.js b/lib/mysapi.js index 4895650..2401350 100644 --- a/lib/mysapi.js +++ b/lib/mysapi.js @@ -5,13 +5,19 @@ import crypto from 'crypto'; import ZZZApiTool from './mysapi/tool.js'; // const DEVICE_ID = randomString(32).toUpperCase() const DEVICE_NAME = randomString(_.random(1, 10)); +const game_region = [ + 'prod_gf_cn', + 'prod_gf_cn', + 'prod_gf_us', + 'prod_gf_eu', + 'prod_gf_jp', + 'prod_gf_sg', +]; export default class MysZZZApi extends MysApi { constructor(uid, cookie, option = {}) { super(uid, cookie, option, true); this.uid = uid; this.server = this.getServer(); - // this.isSr = true - // this.server = 'hkrpg_cn' this.apiTool = new ZZZApiTool(uid, this.server); if (typeof this.cookie != 'string' && this.cookie) { let ck = @@ -25,23 +31,20 @@ export default class MysZZZApi extends MysApi { } getServer() { - switch (String(this.uid).slice(0, -8)) { - case '1': - case '2': - return 'prod_gf_cn'; // 官服 - case '5': - return 'prod_qd_cn'; // B服 - case '6': - return 'prod_official_usa'; // 美服 - case '7': - return 'prod_official_euro'; // 欧服 - case '8': - case '18': - return 'prod_official_asia'; // 亚服 - case '9': - return 'prod_official_cht'; // 港澳台服 + const _uid = this.uid.toString(); + if (_uid.length < 10) { + return game_region[this.game][0]; // 官服 + } + switch (_uid.slice(0, -8)) { + case '10': + return game_region[this.game][2]; // 美服 + case '15': + return game_region[this.game][3]; // 欧服 + case '13': + return game_region[this.game][4]; // 亚服 + case '17': + return game_region[this.game][5]; // 港澳台服 } - return 'prod_gf_cn'; } getUrl(type, data = {}) { diff --git a/lib/mysapi/tool.js b/lib/mysapi/tool.js index fbd57da..96d8f21 100644 --- a/lib/mysapi/tool.js +++ b/lib/mysapi/tool.js @@ -74,6 +74,10 @@ export default class ZZZApiTool { url: `${hostRecord}event/game_record_zzz/api/zzz/note`, query: `role_id=${this.uid}&server=${this.server}`, }, + zzzIndex: { + url: `${hostRecord}event/game_record_zzz/api/zzz/index`, + query: `role_id=${this.uid}&server=${this.server}`, + }, }, }; return urlMap[this.game]; diff --git a/lib/plugin.js b/lib/plugin.js index 66699e9..764447c 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -1,45 +1,24 @@ import MysZZZApi from './mysapi.js'; import { getCk } from './common.js'; import _ from 'lodash'; +import NoteUser from '../../genshin/model/mys/NoteUser.js'; export class ZZZPlugin extends plugin { - async miYoSummerGetUid() { - const key = `ZZZ:UID:${this.e.user_id}`; - const ck = await getCk(this.e); - if (!ck) return false; - let api = new MysZZZApi('', ck); - let userData = await api.getData('zzzUser'); - if (!userData?.data || _.isEmpty(userData.data.list)) return false; - userData = userData.data.list[0]; - let { game_uid: gameUid } = userData; - await redis.set(key, gameUid); - await redis.setEx( - `ZZZ:userData:${gameUid}`, - 60 * 60, - JSON.stringify(userData) - ); - return userData; - } - async getAPI() { - let user = this.e.user_id; - let ats = this.e.message.filter(m => m.type === 'at'); - if (ats.length > 0 && !e.atBot) { - user = ats[0].qq; - this.e.user_id = user; - this.User = new User(this.e); + let user = this.e; + if (this.e.at) { + user = this.e.at; } + this.User = new NoteUser(user); let uid = this.e.msg.match(/\d+/)?.[0]; - await this.miYoSummerGetUid(); - uid = - uid || (await redis.get(`ZZZ:UID:${user}`)) || this.e.user?.getUid('zzz'); + uid = uid || this.User?.getUid('zzz'); if (!uid) { - await this.reply('尚未绑定uid,请发送#zzz绑定uid进行绑定'); + await this.reply('uid为空,米游社查询请先绑定cookie,其他查询请携带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'); + await this.reply('尚未绑定cookie,请先绑定cookie'); return false; } diff --git a/model/avatar.js b/model/avatar.js index 1c937fc..a4c0735 100644 --- a/model/avatar.js +++ b/model/avatar.js @@ -187,25 +187,28 @@ export class ZZZAvatarInfo { */ export class ZZZUser { /** - * @param {string} game_biz - * @param {string} region - * @param {string} game_uid - * @param {string} nickname - * @param {number} level - * @param {boolean} is_chosen - * @param {string} region_name - * @param {boolean} is_official + * @param {{ + * game_biz: string; + * region: string; + * game_uid: string; + * nickname: string; + * level: number; + * is_chosen: boolean; + * region_name: string; + * is_official: boolean; + * }} data */ - constructor( - game_biz, - region, - game_uid, - nickname, - level, - is_chosen, - region_name, - is_official - ) { + constructor(data) { + const { + game_biz, + region, + game_uid, + nickname, + level, + is_chosen, + region_name, + is_official, + } = data; this.game_biz = game_biz; this.region = region; this.game_uid = game_uid; diff --git a/model/bangboo.js b/model/bangboo.js index 579ece9..7a4b30f 100644 --- a/model/bangboo.js +++ b/model/bangboo.js @@ -1,3 +1,23 @@ +/** + * @class + */ +export class Item { + /** + * @param {number} id + * @param {string} name + * @param {string} rarity + * @param {number} level + * @param {number} star + */ + constructor(id, name, rarity, level, star) { + this.id = id; + this.name = name; + this.rarity = rarity; + this.level = level; + this.star = star; + } +} + /** * @class */ diff --git a/model/gacha.js b/model/gacha.js index 5523112..3f379a5 100644 --- a/model/gacha.js +++ b/model/gacha.js @@ -47,13 +47,16 @@ export class SingleGachaLog { */ export class ZZZGachaLogResp { /** - * @param {string} page - * @param {string} size - * @param {SingleGachaLog[]} list - * @param {string} region - * @param {number} region_time_zone + * @param {{ + * page: string; + * size: string; + * list: SingleGachaLog[]; + * region: string; + * region_time_zone: number; + * }} data */ - constructor(page, size, list, region, region_time_zone) { + constructor(data) { + const { page, size, list, region, region_time_zone } = data; this.page = page; this.size = size; this.list = list; diff --git a/model/index.js b/model/index.js index 9558202..7486a57 100644 --- a/model/index.js +++ b/model/index.js @@ -49,35 +49,18 @@ export class Stats { */ export class ZZZIndexResp { /** - * @param {Stats} stats - * @param {Avatar[]} avatar_list - * @param {string} cur_head_icon_url - * @param {Buddy[]} buddy_list + * @param {{ + * stats: Stats; + * avatar_list: Avatar[]; + * cur_head_icon_url: string; + * buddy_list: Buddy[]; + * }} data */ - constructor(stats, avatar_list, cur_head_icon_url, buddy_list) { + constructor(data) { + const { stats, avatar_list, cur_head_icon_url, buddy_list } = data; this.stats = stats; this.avatar_list = avatar_list; this.cur_head_icon_url = cur_head_icon_url; this.buddy_list = buddy_list; } } - -/** - * @class - */ -export class Item { - /** - * @param {number} id - * @param {string} name - * @param {string} rarity - * @param {number} level - * @param {number} star - */ - constructor(id, name, rarity, level, star) { - this.id = id; - this.name = name; - this.rarity = rarity; - this.level = level; - this.star = star; - } -} diff --git a/model/note.js b/model/note.js index 6fafdb0..cdb23fa 100644 --- a/model/note.js +++ b/model/note.js @@ -77,7 +77,12 @@ export class Energy { */ export class ZZZNoteResp { /** - * @param {{ energy: Energy, vitality:Vitality, vhs_sale: VhsSale, card_sign: string }} data + * @param {{ + * energy: Energy; + * vitality:Vitality; + * vhs_sale: VhsSale; + * card_sign: string; + * }} data */ constructor(data) { const { energy, vitality, vhs_sale, card_sign } = data;