feat:国际服更新抽卡记录

This commit is contained in:
kissnavel 2025-11-30 20:56:51 +08:00
parent b0f887c8f0
commit cd5ad2457a
4 changed files with 113 additions and 38 deletions

View file

@ -124,7 +124,19 @@ export class GachaLog extends ZZZPlugin {
async refreshGachaLog() {
const uid = await this.getUID();
if (/^(1[0-9])[0-9]{8}/i.test(uid)) {
return this.reply('国际服不支持此功能');
const { api } = await this.getAPI();
this.reply('抽卡记录获取中请稍等...可能需要一段时间,请耐心等待');
const { data, count } = await updateGachaLog(api, uid);
let msg = [];
msg.push(`抽卡记录更新成功,共${Object.keys(data).length}个卡池`);
for (const name in data) {
msg.push(
`${name}新增${count[name] || 0}条记录,一共${data[name].length}条记录`
);
}
return this.reply(
await common.makeForwardMsg(this.e, msg.join('\n'), '抽卡记录更新成功')
);
}
if (!uid) return false;
const lastQueryTime = await redis.get(`ZZZ:GACHA:${uid}:LASTTIME`);

View file

@ -4,6 +4,9 @@ import { rank } from './convert.js';
import { getGachaLog, saveGachaLog } from './db.js';
import {
gacha_type_meta_data,
gacha_type_meta_data_os,
item_type_os,
rarity_os,
FLOORS_MAP,
HOMO_TAG,
EMOJI,
@ -11,6 +14,7 @@ import {
} from './gacha/const.js';
import { getLevelFromList } from './gacha/tool.js';
import { getZZZGachaLogByAuthkey } from './gacha/core.js';
import request from '../utils/request.js';
/**
* 更新抽卡数据
@ -35,7 +39,8 @@ export const updateGachaLog = async (authKey, uid, region, game_biz) => {
// 新的抽卡数据
let newCount = {};
// 遍历所有池子
for (const name in gacha_type_meta_data) {
let gacha_type = /^(1[0-9])[0-9]{8}/i.test(uid) ? gacha_type_meta_data_os : gacha_type_meta_data
for (const name in gacha_type) {
if (!previousLog[name]) {
// 如果没有数据,初始化为空数组
previousLog[name] = [];
@ -52,9 +57,43 @@ export const updateGachaLog = async (authKey, uid, region, game_biz) => {
// 新数据
const newData = [];
// 遍历当前池子的所有类型
for (const type of gacha_type_meta_data[name]) {
for (const type of gacha_type[name]) {
// 循环获取数据
queryLabel: while (true) {
if (/^(1[0-9])[0-9]{8}/i.test(uid)) {
const api = authKey;
// 获取抽卡记录
const sdk = api.getUrl('zzzGacha_Record', { type, endId } );
const res = await request(sdk.url, {
headers: sdk.headers,
method: 'get',
});
const log = await res.json();
if (!log || !log?.data?.gacha_item_list || log?.data?.gacha_item_list?.length === 0) {
break;
}
// 遍历数据 (从最新的开始)
for (let item of log.data.gacha_item_list) {
item = {
id: item.id,
item_type: item_type_os[item.item_type],
item_id: item.item_id,
name: item.item_name,
rank_type: rarity_os[item.rarity],
time: `${item.date.year}-${item.date.month.toString().padStart(2, '0')}-${item.date.day.toString().padStart(2, '0')} ${item.date.hour.toString().padStart(2, '0')}:${item.date.minute.toString().padStart(2, '0')}:${item.date.second.toString().padStart(2, '0')}`,
}
if (lastSaved && lastSaved.equals(item)) {
// 如果数据相同,说明已经获取完毕
break queryLabel;
}
// 添加到新数据中
newData.push(item);
// 当前池子新数据计数加一
newCount[name]++;
}
// 更新页数和最后一个数据的 id
endId = log.data.gacha_item_list[log.data.gacha_item_list.length - 1]?.id || endId;
} else {
// 获取抽卡记录
const log = await getZZZGachaLogByAuthkey(
authKey,
@ -82,6 +121,7 @@ export const updateGachaLog = async (authKey, uid, region, game_biz) => {
// 更新页数和最后一个数据的 id
endId = log.list[log.list.length - 1]?.id || endId;
page++;
}
// 防止请求过快
await sleep(1000);
}

View file

@ -6,6 +6,25 @@ export const gacha_type_meta_data = {
邦布频段: ['5001'],
};
export const gacha_type_meta_data_os = {
音擎频段: ['GACHA_TYPE_WEAPON_UP'],
独家频段: ['GACHA_TYPE_CHARACTER_UP'],
常驻频段: ['GACHA_TYPE_PERMANENT'],
邦布频段: ['GACHA_TYPE_BANGBOO'],
};
export const item_type_os = {
ITEM_TYPE_WEAPON: '音擎',
ITEM_TYPE_AVATAR: '代理人',
ITEM_TYPE_BANGBOO: '邦布',
};
export const rarity_os = {
B: '2',
A: '3',
S: '4',
};
// 欧非阈值
export const FLOORS_MAP = {
邦布频段: [50, 70],

View file

@ -74,16 +74,6 @@ export default class ZZZApiTool {
url: `${this.host}event/nap_ledger/month_info`,
query: `uid=${this.uid}&region=${this.server}`,
},
zzzAuthKey: {
url: `${this.host}binding/api/genAuthKey`,
body: {
auth_appid: 'webview_gacha',
game_biz: this.gameBiz,
game_uid: this.uid * 1,
region: this.server,
},
dsSalt: 'web',
},
};
}
@ -125,6 +115,16 @@ export default class ZZZApiTool {
},
noDs: true,
},
zzzAuthKey: {
url: `${this.host}binding/api/genAuthKey`,
body: {
auth_appid: 'webview_gacha',
game_biz: this.gameBiz,
game_uid: this.uid * 1,
region: this.server,
},
dsSalt: 'web',
},
deviceLogin: {
url: `${this.hostBbs}apihub/api/deviceLogin`,
body: {
@ -163,6 +163,10 @@ export default class ZZZApiTool {
},
noDs: true,
},
zzzGacha_Record: {
url: `${this.host}event/game_record_zzz/api/zzz/gacha_record`,
query: `lang=zh-cn&uid=${this.uid}&region=${this.server}&gacha_type=${data.type}&end_id=${data.endId}`,
}
}),
...this.zzzUrlMap,
},