2
0
mirror of https://github.com/ctrlcvs/xiaoyao-cvs-plugin.git synced 2024-12-23 03:20:52 +08:00

优化sk绑定逻辑

This commit is contained in:
Ctrlcvs 2022-11-10 23:38:34 +08:00
parent 46d98b64c3
commit df9e89d431
4 changed files with 62 additions and 50 deletions

View File

@ -1,3 +1,8 @@
# 1.2.5
* 优化绑定stoken逻辑
* 优化别名文件
* 新增指令`多体力`
* 用户可通过指令同时查询全部绑定的ck体力数据
# 1.2.4 # 1.2.4
* 新增`群体力推送` * 新增`群体力推送`
* 用户可通过`#开启、关闭体力推送` 来对体力推送进行操作 * 用户可通过`#开启、关闭体力推送` 来对体力推送进行操作

View File

@ -39,6 +39,10 @@ export const rule = {
export async function cloudSign(e){ export async function cloudSign(e){
let user = new User(e); let user = new User(e);
START = moment().unix(); START = moment().unix();
if(!e.yuntoken){
e.reply('尚未绑定云原神账号!')
return true;
}
let res= await user.cloudSign() let res= await user.cloudSign()
await replyMsg(e, res.message); await replyMsg(e, res.message);
return true; return true;

View File

@ -172,26 +172,8 @@ export async function bindLogin_ticket(e){
loginTicket:ckMap.get("login_ticket"), loginTicket:ckMap.get("login_ticket"),
}) })
if(res?.retcode===0){ if(res?.retcode===0){
if (res?.data) { e.stuid=stuid;
let datalist={} await user.seachUid(res)
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)
}
} }
} }
return false; return false;
@ -212,25 +194,8 @@ export async function bindStoken(e) {
return true; return true;
} }
await user.getCookie(e) await user.getCookie(e)
let sk = await utils.getCookieMap(msg) e.sk = await utils.getCookieMap(msg)
let data = {} await user.seachUid(res);
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);
return true; return true;
} }
export async function cloudToken(e) { export async function cloudToken(e) {

View File

@ -1,4 +1,4 @@
import YAML from 'yaml' import YAML from 'yaml'
import chokidar from 'chokidar' import chokidar from 'chokidar'
import miHoYoApi from "../model/mys/mihoyoApi.js" import miHoYoApi from "../model/mys/mihoyoApi.js"
import fs from 'node:fs' import fs from 'node:fs'
@ -85,10 +85,10 @@ export default class user {
return res return res
} }
async multiSign(forumData,isCk=false) { async multiSign(forumData, isCk = false) {
let upData = [], let upData = [],
message = ''; message = '';
if(isCk){ if (isCk) {
await this.cookie(this.e) await this.cookie(this.e)
} }
for (let forum of forumData) { for (let forum of forumData) {
@ -100,9 +100,12 @@ export default class user {
message += `**${forum.name}**\n` message += `**${forum.name}**\n`
res = await this.getData("userGameInfo", forum, false) res = await this.getData("userGameInfo", forum, false)
await utils.sleepAsync(3000) //等几毫秒免得请求太频繁了 await utils.sleepAsync(3000) //等几毫秒免得请求太频繁了
if(res.retcode===-100){ if (res.retcode === -100) {
message=`用户:${this.e.user_id}cookie失效` message = `用户:${this.e.user_id}cookie失效`
return {message,upData}; return {
message,
upData
};
} }
if (res?.data?.list?.length === 0 || !res?.data?.list) { if (res?.data?.list?.length === 0 || !res?.data?.list) {
message += `签到: 未绑定${forum.name}信息\n`; message += `签到: 未绑定${forum.name}信息\n`;
@ -358,14 +361,14 @@ export default class user {
if (isV3) { if (isV3) {
userIdList = (await gsCfg.getBingAllCk()).ckQQ userIdList = (await gsCfg.getBingAllCk()).ckQQ
} else { } else {
userIdList=NoteCookie; userIdList = NoteCookie;
} }
if (mysTask) { if (mysTask) {
e.reply(`米社自动签到任务进行中,请勿重复触发指令`) e.reply(`米社自动签到任务进行中,请勿重复触发指令`)
return false return false
} }
mysTask = true; mysTask = true;
let userIdkeys=Object.keys(userIdList); let userIdkeys = Object.keys(userIdList);
let tips = ['开始米社签到任务'] let tips = ['开始米社签到任务']
let time = userIdkeys.length * 25 + 5 + (userIdkeys.length / 3 * 60) let time = userIdkeys.length * 25 + 5 + (userIdkeys.length / 3 * 60)
let finishTime = moment().add(time, 's').format('MM-DD HH:mm:ss') let finishTime = moment().add(time, 's').format('MM-DD HH:mm:ss')
@ -425,8 +428,8 @@ export default class user {
user_id, user_id,
qq, qq,
isTask: true, isTask: true,
uid:userIdList[qq].uid, uid: userIdList[qq].uid,
cookie:userIdList[qq].cookie||userIdList[qq].ck, cookie: userIdList[qq].cookie || userIdList[qq].ck,
}; };
if (msg) { if (msg) {
e.msg = msg.replace(/全部|签到|米社/g, ""); e.msg = msg.replace(/全部|签到|米社/g, "");
@ -735,6 +738,41 @@ export default class user {
return {} 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") { async delSytk(path = yamlDataUrl, e, type = "stoken") {
await this.getCookie(e); await this.getCookie(e);
if (type != "stoken") { if (type != "stoken") {