This commit is contained in:
bietiaop 2024-07-08 16:27:34 +08:00
parent 5d109ef51c
commit 4828a31163
11 changed files with 100 additions and 126 deletions

View file

@ -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;
}
}

View file

@ -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]玩家信息获取失败');

View file

@ -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<void>}
*/
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': {

View file

@ -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 = {}) {

View file

@ -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];

View file

@ -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;
}

View file

@ -187,16 +187,19 @@ 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(
constructor(data) {
const {
game_biz,
region,
game_uid,
@ -204,8 +207,8 @@ export class ZZZUser {
level,
is_chosen,
region_name,
is_official
) {
is_official,
} = data;
this.game_biz = game_biz;
this.region = region;
this.game_uid = game_uid;

View file

@ -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
*/

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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;