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

修正V3ck查询多号无法识别问题,补充多个stoken添加逻辑具体待测

This commit is contained in:
Ctrlcvs 2022-08-18 23:15:49 +08:00
parent 6981780856
commit 001fccb53b
4 changed files with 82 additions and 56 deletions

View File

@ -122,7 +122,8 @@ export async function mysSign(e) {
} }
let iscount = ""; let iscount = "";
let miHoYoApi = new MihoYoApi(e); let miHoYoApi = new MihoYoApi(e);
if (Object.keys((await miHoYoApi.getStoken(e.user_id))).length == 0) { let stokens=await miHoYoApi.getStoken(e.user_id)
if (!stokens) {
e.reply("未读取到stoken请检查cookies是否包含login_ticket、以及云崽是否为最新版本V3、V2兼容") e.reply("未读取到stoken请检查cookies是否包含login_ticket、以及云崽是否为最新版本V3、V2兼容")
return true; return true;
} }
@ -231,7 +232,8 @@ export async function bbsSeach(e){
return true; return true;
} }
let miHoYoApi = new MihoYoApi(e); let miHoYoApi = new MihoYoApi(e);
if (Object.keys((await miHoYoApi.getStoken(e.user_id))).length == 0) { let stokens=await miHoYoApi.getStoken(e.user_id)
if (!stokens) {
let cookiesDoc = await getcookiesDoc() let cookiesDoc = await getcookiesDoc()
await replyMsg(e, "未读取到stoken请检查cookies是否包含login_ticket请先绑定stoken再查询~\n"+cookiesDoc); await replyMsg(e, "未读取到stoken请检查cookies是否包含login_ticket请先绑定stoken再查询~\n"+cookiesDoc);
return true; return true;
@ -291,8 +293,8 @@ async function cookie(e) {
e.reply("cookie失效请重新绑定~【教程】\n" + cookiesDoc) e.reply("cookie失效请重新绑定~【教程】\n" + cookiesDoc)
return false; return false;
} }
let stokens=miHoYoApi.getStoken(e.user_id)
if (Object.keys((await miHoYoApi.getStoken(e.user_id))).length != 0) { if (!stokens) {
return true; return true;
} }
if (!cookie.includes("login_ticket") && (isV3 && !skuid?.login_ticket)) { if (!cookie.includes("login_ticket") && (isV3 && !skuid?.login_ticket)) {
@ -347,8 +349,10 @@ export async function allMysSign() {
let stoken = await gsCfg.getBingStoken(); let stoken = await gsCfg.getBingStoken();
let isPushSign = await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").isPushSign let isPushSign = await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").isPushSign
//获取需要签到的用户 //获取需要签到的用户
for (let data of stoken) { for (let dataUid of stoken) {
let user_id = data.qq; for(let uuId in dataUid){
let data=dataUid[uuId]
let user_id = data.userId;
let e = { let e = {
user_id, user_id,
isTask: true isTask: true
@ -363,12 +367,13 @@ export async function allMysSign() {
} }
if (msg.includes("OK")) { //签到成功并且不是已签到的才推送 if (msg.includes("OK")) { //签到成功并且不是已签到的才推送
// msg = msg.replace("签到成功", "自动签到成功"); // msg = msg.replace("签到成功", "自动签到成功");
utils.relpyPrivate(user_id, msg + "\n自动签到成功"); utils.relpyPrivate(user_id, msg + "uid:"+uuId+"\n自动签到成功");
} }
}; };
await mysSign(e); await mysSign(e);
await utils.sleepAsync(10000); await utils.sleepAsync(10000);
} }
}
Bot.logger.mark(`米社米币签到任务完成`); Bot.logger.mark(`米社米币签到任务完成`);
return true return true
} }

View File

@ -148,9 +148,7 @@ class GsCfg {
const res = await Promise.all(promises) const res = await Promise.all(promises)
res.forEach((v,index) => { res.forEach((v,index) => {
let tmp = YAML.parse(v) let tmp = YAML.parse(v)
tmp["qq"]=files[index].split(".")[0]*1
ck.push(tmp) ck.push(tmp)
}) })
return ck return ck
} }
@ -170,7 +168,11 @@ class GsCfg {
let ck = fs.readFileSync(file, 'utf-8') let ck = fs.readFileSync(file, 'utf-8')
ck = YAML.parse(ck) ck = YAML.parse(ck)
for(let item in ck){ for(let item in ck){
let login_ticket=ck[item]?.login_ticket let login_ticket;
if(!ck[item].isMain){
continue;
}
login_ticket=ck[item]?.login_ticket
ck=ck[item].ck ck=ck[item].ck
return {ck,item,login_ticket}; return {ck,item,login_ticket};
} }
@ -187,7 +189,18 @@ class GsCfg {
fs.writeFileSync(file, yaml, 'utf8') fs.writeFileSync(file, yaml, 'utf8')
} }
} }
saveBingStoken(userId, data) {
let file = `./plugins/${plugin}/data/yaml/${userId}.yaml`
console.log(data)
console.log(file)
if (lodash.isEmpty(data)) {
fs.existsSync(file) && fs.unlinkSync(file)
} else {
let yaml = YAML.stringify(data)
fs.writeFileSync(file, yaml, 'utf8')
}
}
/** /**
* 原神角色id转换角色名字 * 原神角色id转换角色名字
*/ */

View File

@ -266,11 +266,10 @@ export default class MihoYoApi {
async stoken(cookie, e) { async stoken(cookie, e) {
this.e = e; this.e = e;
let stokens=Object.values(this.getStoken(e.user_id)) let datalist=this.getStoken(e.user_id)
if (stokens.length != 0) { if (datalist){
return true; return true;
} }
let datalist={};
const map = this.getCookieMap(cookie); const map = this.getCookieMap(cookie);
let loginTicket = map.get("login_ticket"); let loginTicket = map.get("login_ticket");
const loginUid = map.get("login_uid") ? map.get("login_uid") : map.get("ltuid"); const loginUid = map.get("login_uid") ? map.get("login_uid") : map.get("ltuid");
@ -307,18 +306,18 @@ export default class MihoYoApi {
stoken: data.data.list[0].token, stoken: data.data.list[0].token,
ltoken: data.data.list[1].token, ltoken: data.data.list[1].token,
uid: e.uid, uid: e.uid,
userId:this.e.user_id,
is_sign:true is_sign:true
} }
// gsCfg.saveBingStoken(e.user_id,datalist) gsCfg.saveBingStoken(e.user_id,datalist)
let yamlStr = YAML.stringify(datalist); // let yamlStr = YAML.stringify(datalist);
fs.writeFileSync(`${YamlDataUrl}/${e.user_id}.yaml`, yamlStr, 'utf8'); // fs.writeFileSync(`${YamlDataUrl}/${e.user_id}.yaml`, yamlStr, 'utf8');
return true; return true;
}); });
} }
).catch(function(err) { ).catch(function(err) {
return false; return false;
}); });
// console.log(datalist);
return true; return true;
} }
/** 米游社 api headers */ /** 米游社 api headers */
@ -415,7 +414,14 @@ export default class MihoYoApi {
try { try {
let ck = fs.readFileSync(file, 'utf-8') let ck = fs.readFileSync(file, 'utf-8')
ck = YAML.parse(ck) ck = YAML.parse(ck)
return ck if(ck?.uid){
let datalist={};
ck.userId=this.e.user_id
datalist[ck.uid]=ck;
ck=datalist
gsCfg.saveBingStoken(this.e.user_id,datalist)
}
return ck[this.e.uid]
} catch (error) { } catch (error) {
return {} return {}
} }

View File

@ -58,7 +58,8 @@ export default class user {
// console.log(resSign?.upData) // console.log(resSign?.upData)
for (let item of resSign?.upData) { for (let item of resSign?.upData) {
let num = lodash.random(0, 9999); let num = lodash.random(0, 9999);
item.upName=item.upName=="原神"?"ys":item.upName=="崩坏3"?"bh3":item.upName=="崩坏2"?"bh2":item.upName=="未定事件簿"?"wdy":"" item.upName = item.upName == "原神" ? "ys" : item.upName == "崩坏3" ? "bh3" : item.upName ==
"崩坏2" ? "bh2" : item.upName == "未定事件簿" ? "wdy" : ""
sumData[item.upName + "" + num] = { sumData[item.upName + "" + num] = {
"uid": item.game_uid, "uid": item.game_uid,
"游戏昵称": item.nickname, "游戏昵称": item.nickname,
@ -99,7 +100,8 @@ export default class user {
async cookie(e) { async cookie(e) {
let { let {
cookie, cookie,
uid,skuid uid,
skuid
} = await this.getCookie(e); } = await this.getCookie(e);
let cookiesDoc = await this.getcookiesDoc(); let cookiesDoc = await this.getcookiesDoc();
let miHoYoApi = new MihoYoApi(this.e); let miHoYoApi = new MihoYoApi(this.e);
@ -107,8 +109,8 @@ export default class user {
e.reply("请先#绑定cookie\n发送【体力帮助】查看配置教程") e.reply("请先#绑定cookie\n发送【体力帮助】查看配置教程")
return false; return false;
} }
let stokens = miHoYoApi.getStoken(e.user_id)
if (Object.keys((await miHoYoApi.getStoken(e.user_id))).length != 0) { if (!stokens) {
return true; return true;
} }
if (!cookie.includes("login_ticket") && (isV3 && !skuid?.login_ticket)) { if (!cookie.includes("login_ticket") && (isV3 && !skuid?.login_ticket)) {