From 79d5bed204f950bdcbe3e57481b1d37eb17b5fcb Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Mon, 5 Sep 2022 11:49:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E3=80=81=E5=85=B7=E4=BD=93=E5=86=85=E5=AE=B9=E8=AF=B7=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B#=E5=9B=BE=E9=89=B4=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++ adapter/mys.js | 1 - apps/index.js | 8 ++-- apps/sign.js | 13 ------ apps/user.js | 114 +++++++++++++++++++++++++++++++++++++-------- guoba.support.js | 2 +- model/gsCfg.js | 32 +------------ model/mys/utils.js | 68 ++++++++++++++++----------- model/user.js | 59 ++++++++++++++++++----- 9 files changed, 197 insertions(+), 108 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9561a7..e6028d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 1.2.0 +* 咕咕咕 +* 努力填坑中,速度缓慢咕 +* 新增指令`#我的stoken|#我的云ck` +* 新增操作发送`stoken`可以直接绑定 + * 具体格式 ****stuid=**********;stoken=**********;ltoken=**********;**** +* 初步适配锅巴插件 +* 新增指令`删除stoken|删除云(ck|token)` # 1.1.9 * 优化部分代码以及配置 * 新增指令`#更新抽卡记录` diff --git a/adapter/mys.js b/adapter/mys.js index 1dbde8e..1c152b9 100644 --- a/adapter/mys.js +++ b/adapter/mys.js @@ -10,7 +10,6 @@ class User { // 保存用户配置 async setCfg (path, value) { - console.log(this.id) let userCfg = await redis.get(`genshin:user-cfg:${this.id}`) userCfg = userCfg ? JSON.parse(userCfg) : {} lodash.set(userCfg, path, value) diff --git a/apps/index.js b/apps/index.js index bee5eed..6cc0b6b 100644 --- a/apps/index.js +++ b/apps/index.js @@ -23,8 +23,8 @@ import { currentVersion } from "../components/Changelog.js"; import { - rule as userRule, - userInfo,gclog + rule as userRule,delSign, + userInfo,gclog,mytoken,bindStoken } from "./user.js" import { rule as signRule, @@ -33,11 +33,11 @@ import { cookiesDocHelp, signlist,yunSignlist,yunAllSign, allMysSign,yunSign,sendyunTime,yuntoken,yunHelp, - allSign,bbsSeach,delSign + allSign,bbsSeach } from "./sign.js" export { updateRes,yunSignlist,delSign, - signlist,gclog, + signlist,gclog,mytoken,bindStoken, updateMiaoPlugin,userInfo, sign,bbsSeach, versionInfo,yunAllSign, diff --git a/apps/sign.js b/apps/sign.js index 5f68d16..cc90e4d 100644 --- a/apps/sign.js +++ b/apps/sign.js @@ -53,10 +53,6 @@ export const rule = { reg: "^#*云原神签到$", describe: "云原神签到" }, - // delSign:{ - // reg: "^#*删除(我的)*(stoken|云原神)$", - // describe: "删除云原神、stoken数据" - // }, yunAllSign: { reg: "^#云原神全部签到$", describe: "云原神全部签到" @@ -582,12 +578,3 @@ export async function yunHelp(e){ const yunDoc=async function(){ return await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").yunDoc } -export async function delSign(e){ - let msg=e.msg.replace(/#|删除|我的/g,""); - let url=msg=="云原神"?`${yunpath}`:`${YamlDataUrl}`; - console.log(e.uid) - if(await gsCfg.delSytk(url,e.user_id)){ - e.reply(`删除${msg}数据成功~\n期待您的下次使用`) - } - return true; -} \ No newline at end of file diff --git a/apps/user.js b/apps/user.js index d9e223d..5614dd4 100644 --- a/apps/user.js +++ b/apps/user.js @@ -26,9 +26,23 @@ export const rule = { gclog: { reg: "^#*更新抽卡记录$", describe: "更新抽卡记录" - } + }, + mytoken: { + reg: "^#*我的(stoken|云ck)$", + describe: "查询绑定数据" + }, + bindStoken: { + reg: "^(.*)stoken=(.*)$", + describe: "绑定stoken" + }, + delSign:{ + reg: "^#*删除(我的)*(stoken|(云原神|云ck))$", + describe: "删除云原神、stoken数据" + }, } const _path = process.cwd(); +const YamlDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/yaml`; +const yunpath=`${_path}/plugins/xiaoyao-cvs-plugin/data/yunToken/`; export async function userInfo(e, { render }) { @@ -58,31 +72,31 @@ export async function userInfo(e, { }) return true; } -let configData=gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config"); +let configData = gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config"); export async function gclog(e) { let user = new User(e); await user.cookie(e) let redis_Data = await redis.get(`xiaoyao:gclog:${e.user_id}`); - if(redis_Data){ - let time=redis_Data*1-Math.floor(Date.now()/1000); + if (redis_Data) { + let time = redis_Data * 1 - Math.floor(Date.now() / 1000); e.reply(`请求过快,请${time}秒后重试...`); return true; } let miHoYoApi = new MihoYoApi(e); - if(!e.cookies||e.cookies.includes("undefined")){ + if (!e.cookies || e.cookies.includes("undefined")) { e.reply("请先绑定stoken") return true; } let kkbody = await miHoYoApi.getbody("原神"); const objData = await miHoYoApi.getUserInfo(kkbody) let data = objData.data - e.region = e.uid[0]*1 == 5 ? "cn_qd01" : "cn_gf01" + e.region = e.uid[0] * 1 == 5 ? "cn_qd01" : "cn_gf01" let authkeyrow = await miHoYoApi.authkey(data); - if(!authkeyrow?.data){ - e.reply("authkey获取失败:"+authkeyrow.message) + if (!authkeyrow?.data) { + e.reply("authkey获取失败:" + authkeyrow.message) return true; } - let authkey=authkeyrow.data["authkey"] + let authkey = authkeyrow.data["authkey"] let postdata = { 'authkey_ver': '1', 'sign_type': '2', @@ -93,7 +107,7 @@ export async function gclog(e) { 'lang': 'zh-cn', 'device_type': 'mobile', 'plat_type': 'ios', - 'region': e.region, + 'region': e.region, 'authkey': encodeURIComponent(authkey), 'game_biz': 'hk4e_cn', 'gacha_type': "301", @@ -105,15 +119,15 @@ export async function gclog(e) { for (let item of Object.keys(postdata)) { url += `${item}=${postdata[item]}&` } - e.msg= url.substring(0, url.length - 1); - let sendMsg=[]; + e.msg = url.substring(0, url.length - 1); + let sendMsg = []; e.reply("抽卡记录获取中请稍等...") - e._reply=e.reply; + e._reply = e.reply; e.reply = (msg) => { sendMsg.push(msg) } - if(isV3){ - let gclog= (await import(`file:///${_path}/plugins/genshin/model/gachaLog.js`)).default + if (isV3) { + let gclog = (await import(`file:///${_path}/plugins/genshin/model/gachaLog.js`)).default await (new gclog(e)).logUrl() } else { let { @@ -122,10 +136,72 @@ export async function gclog(e) { e.isPrivate = true; await bing(e) } - await utils.replyMake(e,sendMsg,1) - let time=(configData.gclogEx||5)*60 - redis.set(`xiaoyao:gclog:${e.user_id}`, Math.floor(Date.now()/1000)+time, { //数据写入缓存避免重复请求 - EX: time + await utils.replyMake(e, sendMsg, 1) + let time = (configData.gclogEx || 5) * 60 + redis.set(`xiaoyao:gclog:${e.user_id}`, Math.floor(Date.now() / 1000) + time, { //数据写入缓存避免重复请求 + EX: time }); return true; } +export async function mytoken(e) { + if (!e.isPrivate) { + e.reply("请私聊发送") + return true; + } + let user = new User(e); + let msg = e.msg.replace(/#|我的/g, ""); + let ck, sendMsg; + if (msg === "stoken") { + await user.getCookie(e) + ck = await user.getStoken(e.user_id) + sendMsg = `stuid=${ck.stuid};stoken=${ck.stoken};ltoken=${ck.ltoken};`; + } else { + ck = await user.getyunToken(e); + sendMsg = `${ck.yuntoken}devId=${ck.devId}` + } + if (sendMsg.includes("undefined")) { + e.reply(`您暂未绑定${msg}`); + return true; + } + e.reply(sendMsg) + return true; +} +export async function bindStoken(e) { + let msg = e.msg; + let user = new User(e); + let miHoYoApi = new MihoYoApi(e); + miHoYoApi.cookies = msg; + let resObj = await miHoYoApi.getTasksList(); + if (!resObj?.data) { + await e.reply(`登录Stoken失效\n请重新获取~`); + 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 (var 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【#我的stoken】查看绑定信息' + msg += '\n【#删除stoken】删除绑定信息' + await e.reply(msg); + return true; +} + +export async function delSign(e){ + let user = new User(e); + e.msg=e.msg.replace(/#|删除|我的/g,""); + let url=e.msg=="stoken"?`${YamlDataUrl}`:`${yunpath}`; + await user.delSytk(url,e) + return true; +} diff --git a/guoba.support.js b/guoba.support.js index 3a197f9..64acafd 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -74,7 +74,7 @@ export function supportGuoba() { ], // 获取配置数据方法(用于前端填充显示数据) getConfigData() { - return lodash.omit(Cfg.merged(), 'jwt') + return Cfg.merged() }, // 设置配置的方法(前端点确定后调用的方法) setConfigData(data, {Result}) { diff --git a/model/gsCfg.js b/model/gsCfg.js index a356a8a..91628b7 100644 --- a/model/gsCfg.js +++ b/model/gsCfg.js @@ -12,7 +12,7 @@ import { import { isV3 } from '../components/Changelog.js'; - +import utils from './mys/utils.js'; const plugin = "xiaoyao-cvs-plugin" const pathPlugin=`./plugins/${plugin}/data/` /** @@ -22,18 +22,6 @@ const pathPlugin=`./plugins/${plugin}/data/` class GsCfg { constructor() { - } - async getyunToken(e) { - let file = `${yunpath}/${e.user_id}.yaml` - try { - let ck = fs.readFileSync(file, 'utf-8') - ck = YAML.parse(ck) - e.devId = ck.devId; - e.yuntoken = ck.yuntoken; - return ck - } catch (error) { - return "" - } } /** 通用yaml读取*/ getfileYaml(path, name) { @@ -122,24 +110,6 @@ class GsCfg { return {} } } - getStoken(userId) { - let file = `${YamlDataUrl}/${userId}.yaml` - try { - let ck = fs.readFileSync(file, 'utf-8') - ck = YAML.parse(ck) - if(ck?.uid){ - let datalist={}; - ck.userId=this.e.user_id - datalist[ck.uid]=ck; - ck=datalist - this.saveBingStoken(this.e.user_id,datalist) - } - return ck[this.e.uid]||{} - } catch (error) { - return {} - } - } - saveBingStoken(userId, data) { let file = `./plugins/${plugin}/data/yaml/${userId}.yaml` if (lodash.isEmpty(data)) { diff --git a/model/mys/utils.js b/model/mys/utils.js index 04ee53b..cf9d09d 100644 --- a/model/mys/utils.js +++ b/model/mys/utils.js @@ -9,42 +9,42 @@ export async function sleepAsync(sleepms) { } -export async function randomSleepAsync(){ +export async function randomSleepAsync() { let sleep = 2 * 1000 + _.random(3 * 1000); await sleepAsync(sleep); } -export function randomString(length){ - let randomStr = ''; - for (let i = 0; i < length; i++) { - randomStr += _.sample('abcdefghijklmnopqrstuvwxyz0123456789'); - } - return randomStr; +export function randomString(length) { + let randomStr = ''; + for (let i = 0; i < length; i++) { + randomStr += _.sample('abcdefghijklmnopqrstuvwxyz0123456789'); + } + return randomStr; } - /** - * 发送私聊消息,仅给好友发送 - * @param user_id qq号 - * @param msg 消息 - */ -export async function relpyPrivate (userId, msg) { - userId = Number(userId) - let friend = Bot.fl.get(userId) - if (friend) { - Bot.logger.mark(`发送好友消息[${friend.nickname}](${userId})`) - return await Bot.pickUser(userId).sendMsg(msg).catch((err) => { - Bot.logger.mark(err) - }) - } +/** + * 发送私聊消息,仅给好友发送 + * @param user_id qq号 + * @param msg 消息 + */ +export async function relpyPrivate(userId, msg) { + userId = Number(userId) + let friend = Bot.fl.get(userId) + if (friend) { + Bot.logger.mark(`发送好友消息[${friend.nickname}](${userId})`) + return await Bot.pickUser(userId).sendMsg(msg).catch((err) => { + Bot.logger.mark(err) + }) + } } -export async function replyMake(e,_msg,lenght){ +export async function replyMake(e, _msg, lenght) { let nickname = Bot.nickname; if (e.isGroup) { let info = await Bot.getGroupMemberInfo(e.group_id, Bot.uin) nickname = info.card || info.nickname } - let msgList=[]; - for(let [index,item] of Object.entries(_msg)){ - if(index { + if (!exists) { + return true; + } + let ck = fs.readFileSync(file, 'utf-8') + ck = YAML.parse(ck) + if(ck?.yuntoken){ + fs.unlinkSync(file); + }else if(ck){ + if(!ck[e.uid]) { + return true; + } + delete ck[e.uid]; + if(Object.keys(ck)==0){ + fs.unlinkSync(file); + }else{ + ck = YAML.stringify(ck) + fs.writeFileSync(file, ck, 'utf8') + } + } + e.reply(`已删除${e.msg}`) + return true; + }) + } }