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) { async note(e) {
const { api, deviceFp } = await this.getAPI(); const { api, deviceFp } = await this.getAPI();
if (!api) return false;
let userData = await api.getData('zzzUser'); let userData = await api.getData('zzzUser');
if (!userData?.data || _.isEmpty(userData.data.list)) { if (!userData?.data || _.isEmpty(userData.data.list)) {
await e.reply('[zzznote]玩家信息获取失败'); 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 fetch from 'node-fetch';
import MysZZZApi from './mysapi.js'; import MysZZZApi from './mysapi.js';
let User; let User;
@ -12,7 +11,7 @@ try {
* 此方法依赖逍遥插件 * 此方法依赖逍遥插件
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
export async function getAuthKey(e, srUid, authAppid = 'csc') { export async function getAuthKey(e, zzzUid, authAppid = 'csc') {
if (!User) { if (!User) {
throw new Error('未安装逍遥插件,无法自动刷新抽卡链接'); throw new Error('未安装逍遥插件,无法自动刷新抽卡链接');
} }
@ -21,7 +20,7 @@ export async function getAuthKey(e, srUid, authAppid = 'csc') {
await user.getCookie(e); await user.getCookie(e);
let ck = await user.getStoken(e.user_id); let ck = await user.getStoken(e.user_id);
ck = `stuid=${ck.stuid};stoken=${ck.stoken};mid=${ck.mid};`; 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'; let type = 'zzzPayAuthKey';
switch (authAppid) { switch (authAppid) {
case 'csc': { case 'csc': {

View file

@ -5,13 +5,19 @@ import crypto from 'crypto';
import ZZZApiTool from './mysapi/tool.js'; import ZZZApiTool from './mysapi/tool.js';
// const DEVICE_ID = randomString(32).toUpperCase() // const DEVICE_ID = randomString(32).toUpperCase()
const DEVICE_NAME = randomString(_.random(1, 10)); 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 { export default class MysZZZApi extends MysApi {
constructor(uid, cookie, option = {}) { constructor(uid, cookie, option = {}) {
super(uid, cookie, option, true); super(uid, cookie, option, true);
this.uid = uid; this.uid = uid;
this.server = this.getServer(); this.server = this.getServer();
// this.isSr = true
// this.server = 'hkrpg_cn'
this.apiTool = new ZZZApiTool(uid, this.server); this.apiTool = new ZZZApiTool(uid, this.server);
if (typeof this.cookie != 'string' && this.cookie) { if (typeof this.cookie != 'string' && this.cookie) {
let ck = let ck =
@ -25,23 +31,20 @@ export default class MysZZZApi extends MysApi {
} }
getServer() { getServer() {
switch (String(this.uid).slice(0, -8)) { const _uid = this.uid.toString();
case '1': if (_uid.length < 10) {
case '2': return game_region[this.game][0]; // 官服
return 'prod_gf_cn'; // 官服 }
case '5': switch (_uid.slice(0, -8)) {
return 'prod_qd_cn'; // B服 case '10':
case '6': return game_region[this.game][2]; // 美服
return 'prod_official_usa'; // 美服 case '15':
case '7': return game_region[this.game][3]; // 欧服
return 'prod_official_euro'; // 欧服 case '13':
case '8': return game_region[this.game][4]; // 亚服
case '18': case '17':
return 'prod_official_asia'; // 亚服 return game_region[this.game][5]; // 港澳台服
case '9':
return 'prod_official_cht'; // 港澳台服
} }
return 'prod_gf_cn';
} }
getUrl(type, data = {}) { getUrl(type, data = {}) {

View file

@ -74,6 +74,10 @@ export default class ZZZApiTool {
url: `${hostRecord}event/game_record_zzz/api/zzz/note`, url: `${hostRecord}event/game_record_zzz/api/zzz/note`,
query: `role_id=${this.uid}&server=${this.server}`, 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]; return urlMap[this.game];

View file

@ -1,45 +1,24 @@
import MysZZZApi from './mysapi.js'; import MysZZZApi from './mysapi.js';
import { getCk } from './common.js'; import { getCk } from './common.js';
import _ from 'lodash'; import _ from 'lodash';
import NoteUser from '../../genshin/model/mys/NoteUser.js';
export class ZZZPlugin extends plugin { 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() { async getAPI() {
let user = this.e.user_id; let user = this.e;
let ats = this.e.message.filter(m => m.type === 'at'); if (this.e.at) {
if (ats.length > 0 && !e.atBot) { user = this.e.at;
user = ats[0].qq;
this.e.user_id = user;
this.User = new User(this.e);
} }
this.User = new NoteUser(user);
let uid = this.e.msg.match(/\d+/)?.[0]; let uid = this.e.msg.match(/\d+/)?.[0];
await this.miYoSummerGetUid(); uid = uid || this.User?.getUid('zzz');
uid =
uid || (await redis.get(`ZZZ:UID:${user}`)) || this.e.user?.getUid('zzz');
if (!uid) { if (!uid) {
await this.reply('尚未绑定uid,请发送#zzz绑定uid进行绑定'); await this.reply('uid为空米游社查询请先绑定cookie其他查询请携带uid');
return false; return false;
} }
const ck = await getCk(this.e); const ck = await getCk(this.e);
if (!ck || Object.keys(ck).filter(k => ck[k].ck).length === 0) { if (!ck || Object.keys(ck).filter(k => ck[k].ck).length === 0) {
await this.reply('尚未绑定cookie请先使用逍遥插件绑定cookie'); await this.reply('尚未绑定cookie请先绑定cookie');
return false; return false;
} }

View file

@ -187,25 +187,28 @@ export class ZZZAvatarInfo {
*/ */
export class ZZZUser { export class ZZZUser {
/** /**
* @param {string} game_biz * @param {{
* @param {string} region * game_biz: string;
* @param {string} game_uid * region: string;
* @param {string} nickname * game_uid: string;
* @param {number} level * nickname: string;
* @param {boolean} is_chosen * level: number;
* @param {string} region_name * is_chosen: boolean;
* @param {boolean} is_official * region_name: string;
* is_official: boolean;
* }} data
*/ */
constructor( constructor(data) {
game_biz, const {
region, game_biz,
game_uid, region,
nickname, game_uid,
level, nickname,
is_chosen, level,
region_name, is_chosen,
is_official region_name,
) { is_official,
} = data;
this.game_biz = game_biz; this.game_biz = game_biz;
this.region = region; this.region = region;
this.game_uid = game_uid; 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 * @class
*/ */

View file

@ -47,13 +47,16 @@ export class SingleGachaLog {
*/ */
export class ZZZGachaLogResp { export class ZZZGachaLogResp {
/** /**
* @param {string} page * @param {{
* @param {string} size * page: string;
* @param {SingleGachaLog[]} list * size: string;
* @param {string} region * list: SingleGachaLog[];
* @param {number} region_time_zone * 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.page = page;
this.size = size; this.size = size;
this.list = list; this.list = list;

View file

@ -49,35 +49,18 @@ export class Stats {
*/ */
export class ZZZIndexResp { export class ZZZIndexResp {
/** /**
* @param {Stats} stats * @param {{
* @param {Avatar[]} avatar_list * stats: Stats;
* @param {string} cur_head_icon_url * avatar_list: Avatar[];
* @param {Buddy[]} buddy_list * 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.stats = stats;
this.avatar_list = avatar_list; this.avatar_list = avatar_list;
this.cur_head_icon_url = cur_head_icon_url; this.cur_head_icon_url = cur_head_icon_url;
this.buddy_list = buddy_list; 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 { 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) { constructor(data) {
const { energy, vitality, vhs_sale, card_sign } = data; const { energy, vitality, vhs_sale, card_sign } = data;