diff --git a/apps/gachalog.js b/apps/gachalog.js index 2132b7d..6525e24 100644 --- a/apps/gachalog.js +++ b/apps/gachalog.js @@ -4,11 +4,13 @@ import { rulePrefix } from '../lib/common.js'; import { getAuthKey } from '../lib/authkey.js'; import settings from '../lib/settings.js'; import _ from 'lodash'; -import common from '../../../lib/common/common.js' +import common from '../../../lib/common/common.js'; import { anaylizeGachaLog, updateGachaLog, getZZZGachaLink, + gacha_type_meta_data, + getZZZGachaLogByAuthkey, } from '../lib/gacha.js'; import { getQueryVariable } from '../utils/network.js'; @@ -78,7 +80,7 @@ export class GachaLog extends ZZZPlugin { return false; } this.finish('gachaLog'); - this.getLog(key); + this.getLogWithOutUID(key); } async refreshGachaLog() { const uid = await this.getUID(); @@ -109,14 +111,53 @@ export class GachaLog extends ZZZPlugin { } this.reply('抽卡记录获取中请稍等...可能需要一段时间,请耐心等待'); const { data, count } = await updateGachaLog(key, uid); - let msg = [] - msg.push(`抽卡记录更新成功,共${Object.keys(data).length}个卡池`) + let msg = []; + msg.push(`抽卡记录更新成功,共${Object.keys(data).length}个卡池`); for (const name in data) { - msg.push(`${name}新增${count[name] || 0}条记录,一共${ - data[name].length - }条记录`); + msg.push( + `${name}新增${count[name] || 0}条记录,一共${data[name].length}条记录` + ); } - await this.reply(await common.makeForwardMsg(this.e,msg,'抽卡记录更新成功')); + await this.reply( + await common.makeForwardMsg(this.e, msg, '抽卡记录更新成功') + ); + return false; + } + async getLogWithOutUID(key) { + /** @type {string} */ + let uid; + queryLabel: for (const name in gacha_type_meta_data) { + for (const type of gacha_type_meta_data[name]) { + const log = await getZZZGachaLogByAuthkey( + key, + type, + type[0], + 1, + '0', + '1' + ); + if (log && log.list && log.list.length > 0) { + uid = log.list[0].uid; + break queryLabel; + } + } + } + if (!uid) { + await this.reply('未查询到uid,请检查链接是否正确'); + return false; + } + this.reply('抽卡记录获取中请稍等...可能需要一段时间,请耐心等待'); + const { data, count } = await updateGachaLog(key, uid); + let msg = []; + msg.push(`抽卡记录更新成功,共${Object.keys(data).length}个卡池`); + for (const name in data) { + msg.push( + `${name}新增${count[name] || 0}条记录,一共${data[name].length}条记录` + ); + } + await this.reply( + await common.makeForwardMsg(this.e, msg, '抽卡记录更新成功') + ); return false; } @@ -140,7 +181,7 @@ export class GachaLog extends ZZZPlugin { await render(this.e, 'gachalog/index.html', result); } async getGachaLink() { - if (!this.e.isPrivate||this.e.isGroup) { + if (!this.e.isPrivate || this.e.isGroup) { await this.reply('请私聊获取抽卡链接', false, { at: true }); return false; } diff --git a/lib/gacha.js b/lib/gacha.js index 4f8d7aa..9b91cdc 100644 --- a/lib/gacha.js +++ b/lib/gacha.js @@ -56,6 +56,7 @@ const NORMAL_LIST = [ * @param {string} initLogGachaBaseType * @param {number} page 页数 * @param {string} endId 最后一个数据的 id + * @param {string} size 页面数据大小 * @returns {Promise} 抽卡链接 */ export const getZZZGachaLink = async ( @@ -63,7 +64,8 @@ export const getZZZGachaLink = async ( gachaType = '2001', initLogGachaBaseType = '2', page = 1, - endId = '0' + endId = '0', + size = '20' ) => { // 暂时直接写死服务器为国服 const serverId = 'prod_gf_cn'; @@ -87,7 +89,7 @@ export const getZZZGachaLink = async ( gacha_type: gachaType, real_gacha_type: initLogGachaBaseType, page: page, - size: '20', + size: size, end_id: endId, }); // 完整链接 @@ -127,7 +129,6 @@ export const getZZZGachaLogByAuthkey = async ( }); // 获取数据 const data = await response.json(); - if (!data || !data?.data) return null; return new ZZZGachaLogResp(data.data); diff --git a/utils/network.js b/utils/network.js index dc67b11..a817abc 100644 --- a/utils/network.js +++ b/utils/network.js @@ -32,20 +32,9 @@ export async function findLowestLatencyUrl(urls) { } export function getQueryVariable(url, variable) { - try { - const _url = new URL(url); - var query = _url.search.substring(1); - var vars = query.split('&'); - for (var i = 0; i < vars.length; i++) { - var pair = vars[i].split('='); - if (pair[0] == variable) { - return pair[1]; - } - } - return null; - } catch (error) { - return null; - } + const searchParams = new URLSearchParams(url); + const key = searchParams.get(variable); + return key; } export async function fetchWithRetry(url, options, retry = 3) {