2
0
mirror of https://github.com/ctrlcvs/xiaoyao-cvs-plugin.git synced 2024-12-22 11:00:51 +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
* 优化部分代码以及配置
* 新增指令`#更新抽卡记录`

View File

@ -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)

View File

@ -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,

View File

@ -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;
}

View File

@ -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',
@ -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, { //数据写入缓存避免重复请求
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;
}

View File

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

View File

@ -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)) {

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);
await sleepAsync(sleep);
}
export function randomString(length){
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) {
export async function relpyPrivate(userId, msg) {
userId = Number(userId)
let friend = Bot.fl.get(userId)
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;
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<lenght){
let msgList = [];
for (let [index, item] of Object.entries(_msg)) {
if (index < lenght) {
continue;
}
msgList.push({
@ -55,8 +55,22 @@ export async function replyMake(e,_msg,lenght){
}
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 {
sleepAsync,
randomSleepAsync,replyMake,
randomString,relpyPrivate
randomSleepAsync,
replyMake,
randomString,
relpyPrivate,
getCookieMap
}

View File

@ -17,6 +17,7 @@ const RETRY_OPTIONS = {
maxTimeout: 10000
};
const nameData = ["原神", "崩坏3", "崩坏2", "未定事件簿"];
const YamlDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/yaml`;
/** 配置文件 */
export default class user {
constructor(e) {
@ -74,17 +75,7 @@ export default class user {
}
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) {
let file = `${this.yunPath}${e.user_id}.yaml`
try {
@ -109,7 +100,7 @@ export default class user {
e.reply("请先#绑定cookie\n发送【体力帮助】查看配置教程")
return false;
}
let stokens = miHoYoApi.getStoken(e.user_id)
let stokens = this.getStoken(e.user_id)
if (!stokens) {
return true;
}
@ -154,4 +145,48 @@ export default class user {
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;
})
}
}