fix: 通过抽卡链接更新记录#20

This commit is contained in:
bietiaop 2024-07-30 22:33:32 +08:00
parent e402889dc5
commit 2c745c256e
3 changed files with 57 additions and 26 deletions

View file

@ -4,11 +4,13 @@ import { rulePrefix } from '../lib/common.js';
import { getAuthKey } from '../lib/authkey.js'; import { getAuthKey } from '../lib/authkey.js';
import settings from '../lib/settings.js'; import settings from '../lib/settings.js';
import _ from 'lodash'; import _ from 'lodash';
import common from '../../../lib/common/common.js' import common from '../../../lib/common/common.js';
import { import {
anaylizeGachaLog, anaylizeGachaLog,
updateGachaLog, updateGachaLog,
getZZZGachaLink, getZZZGachaLink,
gacha_type_meta_data,
getZZZGachaLogByAuthkey,
} from '../lib/gacha.js'; } from '../lib/gacha.js';
import { getQueryVariable } from '../utils/network.js'; import { getQueryVariable } from '../utils/network.js';
@ -78,7 +80,7 @@ export class GachaLog extends ZZZPlugin {
return false; return false;
} }
this.finish('gachaLog'); this.finish('gachaLog');
this.getLog(key); this.getLogWithOutUID(key);
} }
async refreshGachaLog() { async refreshGachaLog() {
const uid = await this.getUID(); const uid = await this.getUID();
@ -109,14 +111,53 @@ export class GachaLog extends ZZZPlugin {
} }
this.reply('抽卡记录获取中请稍等...可能需要一段时间,请耐心等待'); this.reply('抽卡记录获取中请稍等...可能需要一段时间,请耐心等待');
const { data, count } = await updateGachaLog(key, uid); const { data, count } = await updateGachaLog(key, uid);
let msg = [] let msg = [];
msg.push(`抽卡记录更新成功,共${Object.keys(data).length}个卡池`) msg.push(`抽卡记录更新成功,共${Object.keys(data).length}个卡池`);
for (const name in data) { for (const name in data) {
msg.push(`${name}新增${count[name] || 0}条记录,一共${ msg.push(
data[name].length `${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; return false;
} }
@ -140,7 +181,7 @@ export class GachaLog extends ZZZPlugin {
await render(this.e, 'gachalog/index.html', result); await render(this.e, 'gachalog/index.html', result);
} }
async getGachaLink() { async getGachaLink() {
if (!this.e.isPrivate||this.e.isGroup) { if (!this.e.isPrivate || this.e.isGroup) {
await this.reply('请私聊获取抽卡链接', false, { at: true }); await this.reply('请私聊获取抽卡链接', false, { at: true });
return false; return false;
} }

View file

@ -56,6 +56,7 @@ const NORMAL_LIST = [
* @param {string} initLogGachaBaseType * @param {string} initLogGachaBaseType
* @param {number} page 页数 * @param {number} page 页数
* @param {string} endId 最后一个数据的 id * @param {string} endId 最后一个数据的 id
* @param {string} size 页面数据大小
* @returns {Promise<string>} 抽卡链接 * @returns {Promise<string>} 抽卡链接
*/ */
export const getZZZGachaLink = async ( export const getZZZGachaLink = async (
@ -63,7 +64,8 @@ export const getZZZGachaLink = async (
gachaType = '2001', gachaType = '2001',
initLogGachaBaseType = '2', initLogGachaBaseType = '2',
page = 1, page = 1,
endId = '0' endId = '0',
size = '20'
) => { ) => {
// 暂时直接写死服务器为国服 // 暂时直接写死服务器为国服
const serverId = 'prod_gf_cn'; const serverId = 'prod_gf_cn';
@ -87,7 +89,7 @@ export const getZZZGachaLink = async (
gacha_type: gachaType, gacha_type: gachaType,
real_gacha_type: initLogGachaBaseType, real_gacha_type: initLogGachaBaseType,
page: page, page: page,
size: '20', size: size,
end_id: endId, end_id: endId,
}); });
// 完整链接 // 完整链接
@ -127,7 +129,6 @@ export const getZZZGachaLogByAuthkey = async (
}); });
// 获取数据 // 获取数据
const data = await response.json(); const data = await response.json();
if (!data || !data?.data) return null; if (!data || !data?.data) return null;
return new ZZZGachaLogResp(data.data); return new ZZZGachaLogResp(data.data);

View file

@ -32,20 +32,9 @@ export async function findLowestLatencyUrl(urls) {
} }
export function getQueryVariable(url, variable) { export function getQueryVariable(url, variable) {
try { const searchParams = new URLSearchParams(url);
const _url = new URL(url); const key = searchParams.get(variable);
var query = _url.search.substring(1); return key;
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;
}
} }
export async function fetchWithRetry(url, options, retry = 3) { export async function fetchWithRetry(url, options, retry = 3) {