From df9e89d431864cec083ba11c744d1c5ef72ed01b Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Thu, 10 Nov 2022 23:38:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96sk=E7=BB=91=E5=AE=9A=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ apps/sign.js | 4 ++++ apps/user.js | 43 ++++-------------------------------- model/user.js | 60 +++++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 62 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c28f0..287ba49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 1.2.5 +* 优化绑定stoken逻辑 +* 优化别名文件 +* 新增指令`多体力` + * 用户可通过指令同时查询全部绑定的ck体力数据 # 1.2.4 * 新增`群体力推送` * 用户可通过`#开启、关闭体力推送` 来对体力推送进行操作 diff --git a/apps/sign.js b/apps/sign.js index db82242..7988343 100644 --- a/apps/sign.js +++ b/apps/sign.js @@ -39,6 +39,10 @@ export const rule = { export async function cloudSign(e){ let user = new User(e); START = moment().unix(); + if(!e.yuntoken){ + e.reply('尚未绑定云原神账号!') + return true; + } let res= await user.cloudSign() await replyMsg(e, res.message); return true; diff --git a/apps/user.js b/apps/user.js index 4d05f5a..b88fa7f 100644 --- a/apps/user.js +++ b/apps/user.js @@ -172,26 +172,8 @@ export async function bindLogin_ticket(e){ loginTicket:ckMap.get("login_ticket"), }) if(res?.retcode===0){ - if (res?.data) { - let datalist={} - datalist[e.uid] = { - stuid:stuid, - stoken: res.data.list[0].token, - ltoken: res.data.list[1].token, - uid: e.uid, - userId: e.user_id, - is_sign: true - } - gsCfg.saveBingStoken(e.user_id, datalist) - let msg = 'stoken绑定成功您可通过下列指令进行操作:'; - msg += '\n【#米币查询】查询米游币余额' - msg += '\n【#mys原神签到】获取米游币' - msg += '\n【#更新抽卡记录】更新抽卡记录' - msg += '\n【#刷新ck】刷新失效cookie' - msg += '\n【#我的stoken】查看绑定信息' - msg += '\n【#删除stoken】删除绑定信息' - e.reply(msg) - } + e.stuid=stuid; + await user.seachUid(res) } } return false; @@ -212,25 +194,8 @@ export async function bindStoken(e) { return true; } await user.getCookie(e) - let sk = await utils.getCookieMap(msg) - let data = {} - data[e.uid] = { - uid: e.uid, - userId: e.user_id, - is_sign: true - }; - for (let item of sk.entries()) { - data[e.uid][item[0]] = item[1]; - } - await gsCfg.saveBingStoken(e.user_id, data) - msg = 'stoken绑定成功您可通过下列指令进行操作:'; - msg += '\n【#米币查询】查询米游币余额' - msg += '\n【#mys原神签到】获取米游币' - msg += '\n【#更新抽卡记录】更新抽卡记录' - msg += '\n【#刷新ck】刷新失效cookie' - msg += '\n【#我的stoken】查看绑定信息' - msg += '\n【#删除stoken】删除绑定信息' - await e.reply(msg); + e.sk = await utils.getCookieMap(msg) + await user.seachUid(res); return true; } export async function cloudToken(e) { diff --git a/model/user.js b/model/user.js index ba44389..c0c9e2c 100644 --- a/model/user.js +++ b/model/user.js @@ -1,4 +1,4 @@ - import YAML from 'yaml' +import YAML from 'yaml' import chokidar from 'chokidar' import miHoYoApi from "../model/mys/mihoyoApi.js" import fs from 'node:fs' @@ -84,11 +84,11 @@ export default class user { let res = await this.miHoYoApi.getData(type, data) return res } - - async multiSign(forumData,isCk=false) { + + async multiSign(forumData, isCk = false) { let upData = [], message = ''; - if(isCk){ + if (isCk) { await this.cookie(this.e) } for (let forum of forumData) { @@ -100,9 +100,12 @@ export default class user { message += `**${forum.name}**\n` res = await this.getData("userGameInfo", forum, false) await utils.sleepAsync(3000) //等几毫秒免得请求太频繁了 - if(res.retcode===-100){ - message=`用户:${this.e.user_id}:cookie失效` - return {message,upData}; + if (res.retcode === -100) { + message = `用户:${this.e.user_id}:cookie失效` + return { + message, + upData + }; } if (res?.data?.list?.length === 0 || !res?.data?.list) { message += `签到: 未绑定${forum.name}信息\n`; @@ -358,14 +361,14 @@ export default class user { if (isV3) { userIdList = (await gsCfg.getBingAllCk()).ckQQ } else { - userIdList=NoteCookie; + userIdList = NoteCookie; } if (mysTask) { e.reply(`米社自动签到任务进行中,请勿重复触发指令`) return false } mysTask = true; - let userIdkeys=Object.keys(userIdList); + let userIdkeys = Object.keys(userIdList); let tips = ['开始米社签到任务'] let time = userIdkeys.length * 25 + 5 + (userIdkeys.length / 3 * 60) let finishTime = moment().add(time, 's').format('MM-DD HH:mm:ss') @@ -425,8 +428,8 @@ export default class user { user_id, qq, isTask: true, - uid:userIdList[qq].uid, - cookie:userIdList[qq].cookie||userIdList[qq].ck, + uid: userIdList[qq].uid, + cookie: userIdList[qq].cookie || userIdList[qq].ck, }; if (msg) { e.msg = msg.replace(/全部|签到|米社/g, ""); @@ -735,6 +738,41 @@ export default class user { return {} } } + async seachUid(data) { + if (data?.data) { + let datalist = {} + let res; + if (this.e.sk) { + this.e.cookie = + `ltoken=${this.e.sk.get('ltoken')};ltuid=${this.e.sk.get('stuid')};cookie_token=${data.data.cookie_token}; account_id=${this.e.sk.get('stuid')};` + } else { + this.e.cookie = this.e.original_msg + } + res = await this.getData("userGameInfo", this.ForumData[1], false) + let uids=[] + for (let s of res.data.list) { + let uid = s.game_uid + uids.push(uid) + datalist[uid] = { + stuid: this.e?.sk?.get('stuid') || this.e.stuid, + stoken: this.e?.sk?.get('stoken') || data?.data?.list[0].token, + ltoken: this.e?.sk?.get('ltoken') || data?.data?.list[1].token, + uid: uid, + userId: this.e.user_id, + is_sign: true + } + await gsCfg.saveBingStoken(this.e.user_id, datalist) + } + let msg = `uid:${uids.join(',')}\nstoken绑定成功您可通过下列指令进行操作:`; + msg += '\n【#米币查询】查询米游币余额' + msg += '\n【#mys原神签到】获取米游币' + msg += '\n【#更新抽卡记录】更新抽卡记录' + msg += '\n【#刷新ck】刷新失效cookie' + msg += '\n【#我的stoken】查看绑定信息' + msg += '\n【#删除stoken】删除绑定信息' + this.e.reply(msg) + } + } async delSytk(path = yamlDataUrl, e, type = "stoken") { await this.getCookie(e); if (type != "stoken") {