2
0
mirror of https://github.com/ctrlcvs/xiaoyao-cvs-plugin.git synced 2024-12-22 19:10:53 +08:00

更新版本号、具体内容请查看#图鉴版本

This commit is contained in:
Ctrlcvs 2022-09-05 11:49:06 +08:00
parent e67eda4ee6
commit 79d5bed204
9 changed files with 197 additions and 108 deletions

View File

@ -1,3 +1,11 @@
# 1.2.0
* 咕咕咕
* 努力填坑中,速度缓慢咕
* 新增指令`#我的stoken|#我的云ck`
* 新增操作发送`stoken`可以直接绑定
* 具体格式 ****stuid=**********;stoken=**********;ltoken=**********;****
* 初步适配锅巴插件
* 新增指令`删除stoken|删除云(ck|token)`
# 1.1.9 # 1.1.9
* 优化部分代码以及配置 * 优化部分代码以及配置
* 新增指令`#更新抽卡记录` * 新增指令`#更新抽卡记录`

View File

@ -10,7 +10,6 @@ class User {
// 保存用户配置 // 保存用户配置
async setCfg (path, value) { async setCfg (path, value) {
console.log(this.id)
let userCfg = await redis.get(`genshin:user-cfg:${this.id}`) let userCfg = await redis.get(`genshin:user-cfg:${this.id}`)
userCfg = userCfg ? JSON.parse(userCfg) : {} userCfg = userCfg ? JSON.parse(userCfg) : {}
lodash.set(userCfg, path, value) lodash.set(userCfg, path, value)

View File

@ -23,8 +23,8 @@ import {
currentVersion currentVersion
} from "../components/Changelog.js"; } from "../components/Changelog.js";
import { import {
rule as userRule, rule as userRule,delSign,
userInfo,gclog userInfo,gclog,mytoken,bindStoken
} from "./user.js" } from "./user.js"
import { import {
rule as signRule, rule as signRule,
@ -33,11 +33,11 @@ import {
cookiesDocHelp, cookiesDocHelp,
signlist,yunSignlist,yunAllSign, signlist,yunSignlist,yunAllSign,
allMysSign,yunSign,sendyunTime,yuntoken,yunHelp, allMysSign,yunSign,sendyunTime,yuntoken,yunHelp,
allSign,bbsSeach,delSign allSign,bbsSeach
} from "./sign.js" } from "./sign.js"
export { export {
updateRes,yunSignlist,delSign, updateRes,yunSignlist,delSign,
signlist,gclog, signlist,gclog,mytoken,bindStoken,
updateMiaoPlugin,userInfo, updateMiaoPlugin,userInfo,
sign,bbsSeach, sign,bbsSeach,
versionInfo,yunAllSign, versionInfo,yunAllSign,

View File

@ -53,10 +53,6 @@ export const rule = {
reg: "^#*云原神签到$", reg: "^#*云原神签到$",
describe: "云原神签到" describe: "云原神签到"
}, },
// delSign:{
// reg: "^#*删除(我的)*(stoken|云原神)$",
// describe: "删除云原神、stoken数据"
// },
yunAllSign: { yunAllSign: {
reg: "^#云原神全部签到$", reg: "^#云原神全部签到$",
describe: "云原神全部签到" describe: "云原神全部签到"
@ -582,12 +578,3 @@ export async function yunHelp(e){
const yunDoc=async function(){ const yunDoc=async function(){
return await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").yunDoc 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;
}

View File

@ -26,9 +26,23 @@ export const rule = {
gclog: { gclog: {
reg: "^#*更新抽卡记录$", reg: "^#*更新抽卡记录$",
describe: "更新抽卡记录" describe: "更新抽卡记录"
} },
mytoken: {
reg: "^#*我的(stoken|云ck)$",
describe: "查询绑定数据"
},
bindStoken: {
reg: "^(.*)stoken=(.*)$",
describe: "绑定stoken"
},
delSign:{
reg: "^#*删除(我的)*(stoken|(云原神|云ck))$",
describe: "删除云原神、stoken数据"
},
} }
const _path = process.cwd(); 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, { export async function userInfo(e, {
render render
}) { }) {
@ -58,31 +72,31 @@ export async function userInfo(e, {
}) })
return true; 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) { export async function gclog(e) {
let user = new User(e); let user = new User(e);
await user.cookie(e) await user.cookie(e)
let redis_Data = await redis.get(`xiaoyao:gclog:${e.user_id}`); let redis_Data = await redis.get(`xiaoyao:gclog:${e.user_id}`);
if(redis_Data){ if (redis_Data) {
let time=redis_Data*1-Math.floor(Date.now()/1000); let time = redis_Data * 1 - Math.floor(Date.now() / 1000);
e.reply(`请求过快,请${time}秒后重试...`); e.reply(`请求过快,请${time}秒后重试...`);
return true; return true;
} }
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 kkbody = await miHoYoApi.getbody("原神"); let kkbody = await miHoYoApi.getbody("原神");
const objData = await miHoYoApi.getUserInfo(kkbody) const objData = await miHoYoApi.getUserInfo(kkbody)
let data = objData.data 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); let authkeyrow = await miHoYoApi.authkey(data);
if(!authkeyrow?.data){ if (!authkeyrow?.data) {
e.reply("authkey获取失败"+authkeyrow.message) e.reply("authkey获取失败" + authkeyrow.message)
return true; return true;
} }
let authkey=authkeyrow.data["authkey"] let authkey = authkeyrow.data["authkey"]
let postdata = { let postdata = {
'authkey_ver': '1', 'authkey_ver': '1',
'sign_type': '2', 'sign_type': '2',
@ -105,15 +119,15 @@ export async function gclog(e) {
for (let item of Object.keys(postdata)) { for (let item of Object.keys(postdata)) {
url += `${item}=${postdata[item]}&` url += `${item}=${postdata[item]}&`
} }
e.msg= url.substring(0, url.length - 1); e.msg = url.substring(0, url.length - 1);
let sendMsg=[]; let sendMsg = [];
e.reply("抽卡记录获取中请稍等...") e.reply("抽卡记录获取中请稍等...")
e._reply=e.reply; e._reply = e.reply;
e.reply = (msg) => { e.reply = (msg) => {
sendMsg.push(msg) sendMsg.push(msg)
} }
if(isV3){ if (isV3) {
let gclog= (await import(`file:///${_path}/plugins/genshin/model/gachaLog.js`)).default let gclog = (await import(`file:///${_path}/plugins/genshin/model/gachaLog.js`)).default
await (new gclog(e)).logUrl() await (new gclog(e)).logUrl()
} else { } else {
let { let {
@ -122,10 +136,72 @@ export async function gclog(e) {
e.isPrivate = true; e.isPrivate = true;
await bing(e) await bing(e)
} }
await utils.replyMake(e,sendMsg,1) await utils.replyMake(e, sendMsg, 1)
let time=(configData.gclogEx||5)*60 let time = (configData.gclogEx || 5) * 60
redis.set(`xiaoyao:gclog:${e.user_id}`, Math.floor(Date.now()/1000)+time, { //数据写入缓存避免重复请求 redis.set(`xiaoyao:gclog:${e.user_id}`, Math.floor(Date.now() / 1000) + time, { //数据写入缓存避免重复请求
EX: time EX: time
}); });
return true; 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;
}

View File

@ -74,7 +74,7 @@ export function supportGuoba() {
], ],
// 获取配置数据方法(用于前端填充显示数据) // 获取配置数据方法(用于前端填充显示数据)
getConfigData() { getConfigData() {
return lodash.omit(Cfg.merged(), 'jwt') return Cfg.merged()
}, },
// 设置配置的方法(前端点确定后调用的方法) // 设置配置的方法(前端点确定后调用的方法)
setConfigData(data, {Result}) { setConfigData(data, {Result}) {

View File

@ -12,7 +12,7 @@ import {
import { import {
isV3 isV3
} from '../components/Changelog.js'; } from '../components/Changelog.js';
import utils from './mys/utils.js';
const plugin = "xiaoyao-cvs-plugin" const plugin = "xiaoyao-cvs-plugin"
const pathPlugin=`./plugins/${plugin}/data/` const pathPlugin=`./plugins/${plugin}/data/`
/** /**
@ -22,18 +22,6 @@ const pathPlugin=`./plugins/${plugin}/data/`
class GsCfg { class GsCfg {
constructor() { 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读取*/ /** 通用yaml读取*/
getfileYaml(path, name) { getfileYaml(path, name) {
@ -122,24 +110,6 @@ class GsCfg {
return {} 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) { saveBingStoken(userId, data) {
let file = `./plugins/${plugin}/data/yaml/${userId}.yaml` let file = `./plugins/${plugin}/data/yaml/${userId}.yaml`
if (lodash.isEmpty(data)) { if (lodash.isEmpty(data)) {

View File

@ -9,24 +9,24 @@ export async function sleepAsync(sleepms) {
} }
export async function randomSleepAsync(){ export async function randomSleepAsync() {
let sleep = 2 * 1000 + _.random(3 * 1000); let sleep = 2 * 1000 + _.random(3 * 1000);
await sleepAsync(sleep); await sleepAsync(sleep);
} }
export function randomString(length){ export function randomString(length) {
let randomStr = ''; let randomStr = '';
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
randomStr += _.sample('abcdefghijklmnopqrstuvwxyz0123456789'); randomStr += _.sample('abcdefghijklmnopqrstuvwxyz0123456789');
} }
return randomStr; return randomStr;
} }
/** /**
* 发送私聊消息仅给好友发送 * 发送私聊消息仅给好友发送
* @param user_id qq号 * @param user_id qq号
* @param msg 消息 * @param msg 消息
*/ */
export async function relpyPrivate (userId, msg) { export async function relpyPrivate(userId, msg) {
userId = Number(userId) userId = Number(userId)
let friend = Bot.fl.get(userId) let friend = Bot.fl.get(userId)
if (friend) { if (friend) {
@ -36,15 +36,15 @@ export async function relpyPrivate (userId, msg) {
}) })
} }
} }
export async function replyMake(e,_msg,lenght){ export async function replyMake(e, _msg, lenght) {
let nickname = Bot.nickname; let nickname = Bot.nickname;
if (e.isGroup) { if (e.isGroup) {
let info = await Bot.getGroupMemberInfo(e.group_id, Bot.uin) let info = await Bot.getGroupMemberInfo(e.group_id, Bot.uin)
nickname = info.card || info.nickname nickname = info.card || info.nickname
} }
let msgList=[]; let msgList = [];
for(let [index,item] of Object.entries(_msg)){ for (let [index, item] of Object.entries(_msg)) {
if(index<lenght){ if (index < lenght) {
continue; continue;
} }
msgList.push({ msgList.push({
@ -55,8 +55,22 @@ export async function replyMake(e,_msg,lenght){
} }
e._reply(await Bot.makeForwardMsg(msgList)); e._reply(await Bot.makeForwardMsg(msgList));
} }
export async function getCookieMap(cookie) {
let cookiePattern = /^(\S+)=(\S+)$/;
let cookieArray = cookie.replace(/\s*/g, "").split(";");
let cookieMap = new Map();
for (let item of cookieArray) {
let entry = item.split("=");
if (!entry[0]) continue;
cookieMap.set(entry[0], entry[1]);
}
return cookieMap;
}
export default { export default {
sleepAsync, sleepAsync,
randomSleepAsync,replyMake, randomSleepAsync,
randomString,relpyPrivate replyMake,
randomString,
relpyPrivate,
getCookieMap
} }

View File

@ -17,6 +17,7 @@ const RETRY_OPTIONS = {
maxTimeout: 10000 maxTimeout: 10000
}; };
const nameData = ["原神", "崩坏3", "崩坏2", "未定事件簿"]; const nameData = ["原神", "崩坏3", "崩坏2", "未定事件簿"];
const YamlDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/yaml`;
/** 配置文件 */ /** 配置文件 */
export default class user { export default class user {
constructor(e) { constructor(e) {
@ -74,17 +75,7 @@ export default class user {
} }
return sumData; return sumData;
} }
getCookieMap(cookie) {
let cookiePattern = /^(\S+)=(\S+)$/;
let cookieArray = cookie.replace(/\s*/g, "").split(";");
let cookieMap = new Map();
for (let item of cookieArray) {
let entry = item.split("=");
if (!entry[0]) continue;
cookieMap.set(entry[0], entry[1]);
}
return cookieMap;
}
getyunToken(e) { getyunToken(e) {
let file = `${this.yunPath}${e.user_id}.yaml` let file = `${this.yunPath}${e.user_id}.yaml`
try { try {
@ -109,7 +100,7 @@ export default class user {
e.reply("请先#绑定cookie\n发送【体力帮助】查看配置教程") e.reply("请先#绑定cookie\n发送【体力帮助】查看配置教程")
return false; return false;
} }
let stokens = miHoYoApi.getStoken(e.user_id) let stokens = this.getStoken(e.user_id)
if (!stokens) { if (!stokens) {
return true; return true;
} }
@ -154,4 +145,48 @@ export default class user {
skuid skuid
} }
} }
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
gsCfg.saveBingStoken(this.e.user_id, datalist)
}
return ck[this.e.uid] || {}
} catch (error) {
return {}
}
}
async delSytk(path,e){
await this.getCookie(e);
let file = `${path}/${e.user_id}.yaml`
fs.exists(file, (exists) => {
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;
})
}
} }