MCPcopy Create free account
hub / github.com/chavyleung/scripts / performTreasureAction

Function performTreasureAction

zsfc/zsfc.treasure.js:266–325  ·  view source on GitHub ↗

* @description 异步执行寻宝操作。 * @param {string} action - 操作动作,可以是 "start" 或 "end"。 * @returns {Promise } - 包含操作结果的相关信息的 Promise 对象。

(action)

Source from the content-addressed store, hash-verified

264 * @returns {Promise<object>} - 包含操作结果的相关信息的 Promise 对象。
265 */
266async function performTreasureAction(action) {
267 let isEnding = 0;
268 let timeRemaining = 0;
269 let remainingTimes = 1;
270 let digTreasureData = {};
271
272 const options = {
273 url:`https://bang.qq.com/app/speed/treasure/ajax/${action}DigTreasure`,
274 headers: {
275 "Referer": "https://bang.qq.com/app/speed/treasure/index",
276 "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}`
277 },
278 body: $.queryStr({
279 "mapId": $.mapData.mapId,
280 "starId": $.mapData.starId,
281 // 普通寻宝1 600s -- 快捷寻宝2 10s
282 "type": $.mapData.isVip ? 2 : 1,
283 "areaId": $.read(`zsfc_areaId`),
284 "roleId": $.read(`zsfc_roleId`),
285 "userId": $.read(`zsfc_userId`),
286 "uin": $.read(`zsfc_roleId`),
287 "token": $.read(`zsfc_token`)
288 })
289 };
290
291 // 发送 POST 异步请求并返回一个 Promise 对象
292 return new Promise(resolve => {
293 $.post(options, (error, response, data) => {
294 if (data) {
295 const body = $.toObj(data);
296 if (action === "start") {
297 if (body.msg.includes(`用完`)) {
298 remainingTimes = 0;
299 } else {
300 const targetTimestamp = new Date(body.data.time).getTime();
301 const tenMinutesLaterTimestamp = targetTimestamp + 10 * 60 * 1000;
302 if (Date.now() > tenMinutesLaterTimestamp) {
303 isEnding = 1;
304 } else {
305 timeRemaining = parseInt((tenMinutesLaterTimestamp - Date.now()) / 1000);
306 }
307 }
308 } else {
309 remainingTimes = body.data.todaycanTimes - body.data.todayTimes
310 }
311
312 digTreasureData = {
313 ending: isEnding,
314 timeLeft: timeRemaining,
315 todaycanTimes: remainingTimes
316 };
317 } else {
318 $.log(`❌ 寻宝时发生错误`);
319 $.log($.toStr(error));
320 }
321
322 resolve(digTreasureData);
323 });

Callers 1

zsfc.treasure.jsFile · 0.85

Calls 5

queryStrMethod · 0.45
postMethod · 0.45
toObjMethod · 0.45
logMethod · 0.45
toStrMethod · 0.45

Tested by

no test coverage detected