mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-14 12:17:48 +00:00
fix:国际服抽卡链接与指令更新冲突
This commit is contained in:
parent
0f32bfbdfa
commit
ddf24f6004
2 changed files with 125 additions and 70 deletions
|
|
@ -3,7 +3,7 @@ import { getAuthKey } from '../lib/authkey.js';
|
|||
import settings from '../lib/settings.js';
|
||||
import _ from 'lodash';
|
||||
import common from '../../../lib/common/common.js';
|
||||
import { anaylizeGachaLog, updateGachaLog } from '../lib/gacha.js';
|
||||
import { anaylizeGachaLog, updateGachaLog, updateGachaLog_os } from '../lib/gacha.js';
|
||||
import { getZZZGachaLink, getZZZGachaLogByAuthkey } from '../lib/gacha/core.js';
|
||||
import { gacha_type_meta_data } from '../lib/gacha/const.js';
|
||||
import { getQueryVariable } from '../utils/network.js';
|
||||
|
|
@ -127,7 +127,7 @@ export class GachaLog extends ZZZPlugin {
|
|||
if (/^(1[0-9])[0-9]{8}/i.test(uid)) {
|
||||
const { api, deviceFp } = await this.getAPI();
|
||||
this.reply('抽卡记录获取中请稍等...可能需要一段时间,请耐心等待');
|
||||
const { data, count } = await updateGachaLog(api, uid, deviceFp);
|
||||
const { data, count } = await updateGachaLog_os(api, uid, deviceFp);
|
||||
let msg = [];
|
||||
msg.push(`抽卡记录更新成功,共${Object.keys(data).length}个卡池`);
|
||||
for (const name in data) {
|
||||
|
|
|
|||
191
lib/gacha.js
191
lib/gacha.js
|
|
@ -38,8 +38,7 @@ export const updateGachaLog = async (authKey, uid, region, game_biz) => {
|
|||
// 新的抽卡数据
|
||||
let newCount = {};
|
||||
// 遍历所有池子
|
||||
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) {
|
||||
for (const name in gacha_type_meta_data) {
|
||||
if (!previousLog[name]) {
|
||||
// 如果没有数据,初始化为空数组
|
||||
previousLog[name] = [];
|
||||
|
|
@ -56,75 +55,131 @@ export const updateGachaLog = async (authKey, uid, region, game_biz) => {
|
|||
// 新数据
|
||||
const newData = [];
|
||||
// 遍历当前池子的所有类型
|
||||
for (const type of gacha_type[name]) {
|
||||
for (const type of gacha_type_meta_data[name]) {
|
||||
// 循环获取数据
|
||||
queryLabel: while (true) {
|
||||
if (/^(1[0-9])[0-9]{8}/i.test(uid)) {
|
||||
// 获取抽卡记录
|
||||
const log = await authKey.getFinalData('zzzGacha_Record', {
|
||||
deviceFp: region,
|
||||
type,
|
||||
endId,
|
||||
});
|
||||
if (!log || !log?.gacha_item_list || log?.gacha_item_list?.length === 0) {
|
||||
break;
|
||||
}
|
||||
// 遍历数据 (从最新的开始)
|
||||
for (let item of log.gacha_item_list) {
|
||||
item = {
|
||||
uid: uid,
|
||||
gacha_id: '0',
|
||||
gacha_type: '2',
|
||||
item_id: item.item_id,
|
||||
count: '1',
|
||||
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')}`,
|
||||
name: item.item_name,
|
||||
lang: 'zh-cn',
|
||||
item_type: item_type_os[item.item_type],
|
||||
rank_type: rarity_os[item.rarity],
|
||||
id: item.id,
|
||||
square_icon: '',
|
||||
};
|
||||
if (lastSaved && lastSaved.equals(item)) {
|
||||
// 如果数据相同,说明已经获取完毕
|
||||
break queryLabel;
|
||||
}
|
||||
// 添加到新数据中
|
||||
newData.push(item);
|
||||
// 当前池子新数据计数加一
|
||||
newCount[name]++;
|
||||
}
|
||||
// 更新页数和最后一个数据的 id
|
||||
endId = log.gacha_item_list[log.gacha_item_list.length - 1]?.id || endId;
|
||||
} else {
|
||||
// 获取抽卡记录
|
||||
const log = await getZZZGachaLogByAuthkey(
|
||||
authKey,
|
||||
type,
|
||||
type[0],
|
||||
page,
|
||||
endId,
|
||||
region,
|
||||
game_biz
|
||||
);
|
||||
if (!log || !log?.list || log?.list?.length === 0) {
|
||||
break;
|
||||
}
|
||||
// 遍历数据 (从最新的开始)
|
||||
for (const item of log.list) {
|
||||
if (lastSaved && lastSaved.equals(item)) {
|
||||
// 如果数据相同,说明已经获取完毕
|
||||
break queryLabel;
|
||||
}
|
||||
// 添加到新数据中
|
||||
newData.push(item);
|
||||
// 当前池子新数据计数加一
|
||||
newCount[name]++;
|
||||
}
|
||||
// 更新页数和最后一个数据的 id
|
||||
endId = log.list[log.list.length - 1]?.id || endId;
|
||||
page++;
|
||||
// 获取抽卡记录
|
||||
const log = await getZZZGachaLogByAuthkey(
|
||||
authKey,
|
||||
type,
|
||||
type[0],
|
||||
page,
|
||||
endId,
|
||||
region,
|
||||
game_biz
|
||||
);
|
||||
if (!log || !log?.list || log?.list?.length === 0) {
|
||||
break;
|
||||
}
|
||||
// 遍历数据 (从最新的开始)
|
||||
for (const item of log.list) {
|
||||
if (lastSaved && lastSaved.equals(item)) {
|
||||
// 如果数据相同,说明已经获取完毕
|
||||
break queryLabel;
|
||||
}
|
||||
// 添加到新数据中
|
||||
newData.push(item);
|
||||
// 当前池子新数据计数加一
|
||||
newCount[name]++;
|
||||
}
|
||||
// 更新页数和最后一个数据的 id
|
||||
endId = log.list[log.list.length - 1]?.id || endId;
|
||||
page++;
|
||||
// 防止请求过快
|
||||
await sleep(1000);
|
||||
}
|
||||
}
|
||||
// 合并新数据和之前的数据
|
||||
previousLog[name] = [...newData, ...previousLog[name]];
|
||||
}
|
||||
// 保存数据到文件
|
||||
saveGachaLog(uid, previousLog);
|
||||
// 返回数据
|
||||
return {
|
||||
data: previousLog,
|
||||
count: newCount,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 更新抽卡数据
|
||||
* @param {string} api 米游社api
|
||||
* @param {string} uid ZZZUID
|
||||
* @param {string} deviceFp 米游社指纹
|
||||
* @returns {Promise<{
|
||||
* data: {
|
||||
* [x: string]: SingleGachaLog[];
|
||||
* },
|
||||
* count: {
|
||||
* [x: string]: number;
|
||||
* }
|
||||
* }>} 更新后的抽卡数据
|
||||
*/
|
||||
export const updateGachaLog_os = async (api, uid, deviceFp) => {
|
||||
// 获取之前的抽卡数据
|
||||
let previousLog = getGachaLog(uid);
|
||||
if (!previousLog) {
|
||||
// 如果没有数据,初始化为空对象
|
||||
previousLog = {};
|
||||
}
|
||||
// 新的抽卡数据
|
||||
let newCount = {};
|
||||
// 遍历所有池子
|
||||
for (const name in gacha_type_meta_data_os) {
|
||||
if (!previousLog[name]) {
|
||||
// 如果没有数据,初始化为空数组
|
||||
previousLog[name] = [];
|
||||
}
|
||||
// 初始化新数据计数(当前池子)
|
||||
newCount[name] = 0;
|
||||
// 转换为 SingleGachaLog 对象
|
||||
previousLog[name] = previousLog[name].map(i => new SingleGachaLog(i));
|
||||
// 获取上一次保存的数据
|
||||
const lastSaved = previousLog[name]?.[0];
|
||||
// 初始化最后一个数据的 id
|
||||
let endId = '0';
|
||||
// 新数据
|
||||
const newData = [];
|
||||
// 遍历当前池子的所有类型
|
||||
for (const type of gacha_type_meta_data_os[name]) {
|
||||
// 循环获取数据
|
||||
queryLabel: while (true) {
|
||||
// 获取抽卡记录
|
||||
const log = await api.getFinalData('zzzGacha_Record', {
|
||||
deviceFp,
|
||||
type,
|
||||
endId,
|
||||
});
|
||||
if (!log || !log?.gacha_item_list || log?.gacha_item_list?.length === 0) {
|
||||
break;
|
||||
}
|
||||
// 遍历数据 (从最新的开始)
|
||||
for (let item of log.gacha_item_list) {
|
||||
item = {
|
||||
uid: uid,
|
||||
gacha_id: '0',
|
||||
gacha_type: '2',
|
||||
item_id: item.item_id,
|
||||
count: '1',
|
||||
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')}`,
|
||||
name: item.item_name,
|
||||
lang: 'zh-cn',
|
||||
item_type: item_type_os[item.item_type],
|
||||
rank_type: rarity_os[item.rarity],
|
||||
id: item.id,
|
||||
square_icon: '',
|
||||
};
|
||||
if (lastSaved && lastSaved.equals(item)) {
|
||||
// 如果数据相同,说明已经获取完毕
|
||||
break queryLabel;
|
||||
}
|
||||
// 添加到新数据中
|
||||
newData.push(item);
|
||||
// 当前池子新数据计数加一
|
||||
newCount[name]++;
|
||||
}
|
||||
// 更新页数和最后一个数据的 id
|
||||
endId = log.gacha_item_list[log.gacha_item_list.length - 1]?.id || endId;
|
||||
// 防止请求过快
|
||||
await sleep(1000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue