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

修正未绑定ck时,无法刷新ck的问题

This commit is contained in:
Ctrlcvs 2022-09-07 00:13:14 +08:00
parent 57489b68c0
commit bd35367007
2 changed files with 25 additions and 21 deletions

View File

@ -120,7 +120,6 @@ export async function checkAuth (e, cfg) {
/* 检查user ck */ /* 检查user ck */
let isCookieUser = await MysInfo.checkUidBing(uid) let isCookieUser = await MysInfo.checkUidBing(uid)
if (auth === 'cookie' && !isCookieUser) { if (auth === 'cookie' && !isCookieUser) {
e.reply('尚未绑定Cookie...')
return false return false
} }
e.selfUser = new User({ id: e.user_id, uid }) e.selfUser = new User({ id: e.user_id, uid })

View File

@ -18,6 +18,9 @@ import {
} from "oicq"; } from "oicq";
import YAML from 'yaml' import YAML from 'yaml'
import User from "../model/user.js" import User from "../model/user.js"
import {
checkAuth
} from "../adapter/mys.js"
export const rule = { export const rule = {
userInfo: { userInfo: {
reg: "^#*(ck|stoken|cookie|cookies|签到)查询$", reg: "^#*(ck|stoken|cookie|cookies|签到)查询$",
@ -35,18 +38,18 @@ export const rule = {
reg: "^(.*)stoken=(.*)$", reg: "^(.*)stoken=(.*)$",
describe: "绑定stoken" describe: "绑定stoken"
}, },
delSign:{ delSign: {
reg: "^#*删除(我的)*(stoken|(云原神|云ck))$", reg: "^#*删除(我的)*(stoken|(云原神|云ck))$",
describe: "删除云原神、stoken数据" describe: "删除云原神、stoken数据"
}, },
updCookie:{ updCookie: {
reg:"^#*(刷新|更新)(ck|cookie)$", reg: "^#*(刷新|更新)(ck|cookie)$",
describe:"刷新cookie" describe: "刷新cookie"
} }
} }
const _path = process.cwd(); const _path = process.cwd();
const YamlDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/yaml`; const YamlDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/yaml`;
const yunpath=`${_path}/plugins/xiaoyao-cvs-plugin/data/yunToken/`; const yunpath = `${_path}/plugins/xiaoyao-cvs-plugin/data/yunToken/`;
export async function userInfo(e, { export async function userInfo(e, {
render render
}) { }) {
@ -60,7 +63,7 @@ export async function userInfo(e, {
} }
let ck = ""; let ck = "";
if (e.cookie) { if (e.cookie) {
ck =await utils.getCookieMap(e.cookie); ck = await utils.getCookieMap(e.cookie);
ck = ck?.get("ltuid") ck = ck?.get("ltuid")
} }
return await Common.render(`user/userInfo`, { return await Common.render(`user/userInfo`, {
@ -186,8 +189,8 @@ export async function bindStoken(e) {
} }
await user.getCookie(e) await user.getCookie(e)
let sk = await utils.getCookieMap(msg) let sk = await utils.getCookieMap(msg)
let data={} let data = {}
data[e.uid]= { data[e.uid] = {
uid: e.uid, uid: e.uid,
userId: e.user_id, userId: e.user_id,
is_sign: true is_sign: true
@ -206,23 +209,25 @@ export async function bindStoken(e) {
return true; return true;
} }
export async function delSign(e){ export async function delSign(e) {
let user = new User(e); let user = new User(e);
e.msg=e.msg.replace(/#|删除|我的/g,""); e.msg = e.msg.replace(/#|删除|我的/g, "");
let url=e.msg=="stoken"?`${YamlDataUrl}`:`${yunpath}`; let url = e.msg == "stoken" ? `${YamlDataUrl}` : `${yunpath}`;
await user.delSytk(url,e) await user.delSytk(url, e)
return true; return true;
} }
export async function updCookie(e){ export async function updCookie(e) {
let user = new User(e); let user = new User(e);
await user.getCookie(e) await user.getCookie(e)
let userCk = (await checkAuth(e, "cookie"))
e.uid = userCk.uid
let miHoYoApi = new MihoYoApi(e); let miHoYoApi = new MihoYoApi(e);
if (!e.cookies || e.cookies.includes("undefined")) { if (!e.cookies || e.cookies.includes("undefined")) {
e.reply("请先绑定stoken") e.reply("请先绑定stoken")
return true; return true;
} }
let resObj=await miHoYoApi.updCookie(); let resObj = await miHoYoApi.updCookie();
if(!resObj?.data){ if (!resObj?.data) {
e.reply(`请求异常:${resObj.message}`) e.reply(`请求异常:${resObj.message}`)
return false; return false;
} }
@ -231,12 +236,12 @@ export async function updCookie(e){
e.reply = (msg) => { e.reply = (msg) => {
sendMsg.push(msg) sendMsg.push(msg)
} }
let sk = await utils.getCookieMap(e.cookie) let sk = await utils.getCookieMap(e.cookies)
let ck=resObj["data"]["cookie_token"]; let ck = resObj["data"]["cookie_token"];
e.msg=`ltoken=${sk.get("ltoken")};ltuid=${sk.get("ltuid")};cookie_token=${ck}; account_id=${sk.get("ltuid")};` e.msg = `ltoken=${sk.get("ltoken")};ltuid=${sk.get("stuid")};cookie_token=${ck}; account_id=${sk.get("stuid")};`
if (isV3) { if (isV3) {
let userck = (await import(`file:///${_path}/plugins/genshin/model/user.js`)).default let userck = (await import(`file:///${_path}/plugins/genshin/model/user.js`)).default
e.ck=e.msg; e.ck = e.msg;
await (new userck(e)).bing() await (new userck(e)).bing()
} else { } else {
let { let {