mirror of
https://github.com/ctrlcvs/xiaoyao-cvs-plugin.git
synced 2024-12-22 19:10:53 +08:00
新增功能【#ck查询】
This commit is contained in:
parent
970357c79c
commit
67aecf1538
@ -1,3 +1,6 @@
|
||||
# 1.1.8
|
||||
* 新增指令`#ck查询`
|
||||
* 可查询当前cookie绑定状态的签到信息以及米游币信息数据
|
||||
# 1.1.7
|
||||
* 新增指令`#米币查询`
|
||||
* 新增`道具图鉴`图鉴数据
|
||||
|
@ -22,6 +22,10 @@ import {
|
||||
import {
|
||||
currentVersion
|
||||
} from "../components/Changelog.js";
|
||||
import {
|
||||
rule as userRule,
|
||||
userInfo
|
||||
} from "./user.js"
|
||||
import {
|
||||
rule as signRule,
|
||||
sign,
|
||||
@ -34,7 +38,7 @@ import {
|
||||
export {
|
||||
updateRes,yunSignlist,
|
||||
signlist,
|
||||
updateMiaoPlugin,
|
||||
updateMiaoPlugin,userInfo,
|
||||
sign,bbsSeach,
|
||||
versionInfo,yunAllSign,
|
||||
Note_appoint,
|
||||
@ -77,6 +81,7 @@ let rule = {
|
||||
reg: "#poke#",
|
||||
describe: "体力",
|
||||
},
|
||||
...userRule,
|
||||
...signRule,
|
||||
...adminRule
|
||||
};
|
||||
|
46
apps/user.js
Normal file
46
apps/user.js
Normal file
@ -0,0 +1,46 @@
|
||||
import MihoYoApi from "../model/mys/mihoyo-api.js"
|
||||
import utils from '../model/mys/utils.js';
|
||||
import promiseRetry from 'promise-retry';
|
||||
import {
|
||||
Cfg,
|
||||
Data
|
||||
} from "../components/index.js";
|
||||
import moment from 'moment';
|
||||
|
||||
import Common from "../components/Common.js";
|
||||
import {
|
||||
isV3
|
||||
} from '../components/Changelog.js';
|
||||
import gsCfg from '../model/gsCfg.js';
|
||||
import fs from "fs";
|
||||
import {
|
||||
segment
|
||||
} from "oicq";
|
||||
import YAML from 'yaml'
|
||||
import User from "../model/user.js"
|
||||
export const rule = {
|
||||
userInfo: {
|
||||
reg: "^#*(ck|stoken|cookie|cookies|签到)查询$",
|
||||
describe: "用户个人信息查询"
|
||||
},
|
||||
}
|
||||
export async function userInfo(e,{render}){
|
||||
let user=new User(e);
|
||||
e.reply("正在获取角色信息请稍等...")
|
||||
let sumData=await user.getCkData()
|
||||
let week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
|
||||
let day = moment(new Date()).format("yyyy年MM月DD日 HH:mm") + " " + week[new Date().getDay()];
|
||||
let ck= user.getCookieMap(e.cookie);
|
||||
return await Common.render(`user/userInfo`, {
|
||||
uid: e.user_id,
|
||||
ltuid:ck.get("ltuid"),
|
||||
save_id:e.user_id,
|
||||
day,
|
||||
sumData
|
||||
}, {
|
||||
e,
|
||||
render,
|
||||
scale: 1.2
|
||||
})
|
||||
return true;
|
||||
}
|
158
model/user.js
Normal file
158
model/user.js
Normal file
@ -0,0 +1,158 @@
|
||||
import YAML from 'yaml'
|
||||
import chokidar from 'chokidar'
|
||||
import MihoYoApi from "../model/mys/mihoyo-api.js"
|
||||
import fs from 'node:fs'
|
||||
import promiseRetry from 'promise-retry';
|
||||
import lodash from 'lodash'
|
||||
import gsCfg from './gsCfg.js';
|
||||
import {
|
||||
isV3
|
||||
} from '../components/Changelog.js';
|
||||
const _path = process.cwd();
|
||||
const plugin = "xiaoyao-cvs-plugin"
|
||||
const RETRY_OPTIONS = {
|
||||
retries: 3,
|
||||
minTimeout: 5000,
|
||||
maxTimeout: 10000
|
||||
};
|
||||
const nameData=["原神","崩坏3","崩坏2","未定事件簿"];
|
||||
/** 配置文件 */
|
||||
export default class user {
|
||||
constructor(e) {
|
||||
this.e=e;
|
||||
this.stokenPath=`./plugins/${plugin}/data/yaml/`
|
||||
this.yunPath=`./plugins/${plugin}/data/yunToken/`;
|
||||
this.getyunToken(this.e)
|
||||
}
|
||||
async getCkData(){
|
||||
let sumData={};
|
||||
await this.cookie(this.e)
|
||||
this.miHoYoApi = new MihoYoApi(this.e);
|
||||
let yunres = await promiseRetry((retry, number) => {
|
||||
return this.miHoYoApi.logyunGenshen().catch((e) => {
|
||||
return retry(e);
|
||||
});
|
||||
}, RETRY_OPTIONS);
|
||||
let mysres = await promiseRetry((retry, number) => {
|
||||
return this.miHoYoApi.getTasksList().catch((e) => {
|
||||
return retry(e);
|
||||
});
|
||||
}, RETRY_OPTIONS);
|
||||
|
||||
let yundata = yunres.data
|
||||
if(mysres.retcode===0){
|
||||
sumData["米游社"]={
|
||||
"米游币余额":mysres.data.total_points,
|
||||
"今日剩余可获取":mysres.data.can_get_points
|
||||
}
|
||||
}
|
||||
if(yunres.retcode===0){
|
||||
sumData["云原神"]={
|
||||
"今日可获取":yundata?.coin?.coin_num,
|
||||
"免费时长":yundata?.free_time?.free_time,
|
||||
"总时长":yundata.total_time
|
||||
}
|
||||
}
|
||||
for(let name of nameData){
|
||||
let resSign = await promiseRetry((retry, number) => {
|
||||
return this.miHoYoApi.honkai3rdSignTask(name).catch((e) => {
|
||||
return retry(e);
|
||||
});
|
||||
}, RETRY_OPTIONS);
|
||||
if(resSign?.upData){
|
||||
// console.log(resSign?.upData)
|
||||
for(let item of resSign?.upData){
|
||||
let num= lodash.random(0, 9999);
|
||||
item.upName=item.upName=="原神"?"ys":item.upName=="崩坏3"?"bh3":item.upName=="崩坏2"?"bh2":item.upName=="未定事件簿"?"wdy":""
|
||||
sumData[item.upName+""+num]={
|
||||
"uid":item.game_uid,
|
||||
"游戏昵称":item.nickname,
|
||||
"等级":item.level,
|
||||
"今日签到":item.is_sign?"已签到":"未签到"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
let ck = fs.readFileSync(file, 'utf-8')
|
||||
ck = YAML.parse(ck)
|
||||
this.e.devId = ck.devId;
|
||||
this.e.yuntoken = ck.yuntoken;
|
||||
return ck
|
||||
} catch (error) {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
async cookie(e) {
|
||||
let {
|
||||
cookie,
|
||||
uid,skuid
|
||||
} = await this.getCookie(e);
|
||||
let cookiesDoc = await this.getcookiesDoc();
|
||||
let miHoYoApi = new MihoYoApi(this.e);
|
||||
if (!cookie) {
|
||||
e.reply("cookie失效请重新绑定~【教程】\n" + cookiesDoc)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Object.keys((await miHoYoApi.getStoken(e.user_id))).length != 0) {
|
||||
return true;
|
||||
}
|
||||
if (!cookie.includes("login_ticket") && (isV3 && !skuid?.login_ticket)) {
|
||||
e.reply("米游社登录cookie不完整,请前往米游社通行证处重新获取cookie~\ncookies必须包含login_ticket【教程】 " + cookiesDoc)
|
||||
return false;
|
||||
}
|
||||
let flot = (await miHoYoApi.stoken(cookie, e));
|
||||
// console.log(flot)
|
||||
await utils.sleepAsync(1000); //延迟加载防止文件未生成
|
||||
if (!flot) {
|
||||
e.reply("登录失效请重新登录获取cookie发送机器人~")
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
async getcookiesDoc() {
|
||||
return await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").cookiesDoc
|
||||
}
|
||||
async getCookie(e) {
|
||||
let skuid, cookie, uid
|
||||
if (isV3) {
|
||||
skuid = await gsCfg.getBingCookie(e.user_id);
|
||||
cookie = skuid.ck;
|
||||
uid = skuid.item;
|
||||
} else {
|
||||
if (NoteCookie[e.user_id]) {
|
||||
cookie = NoteCookie[e.user_id].cookie;
|
||||
uid = NoteCookie[e.user_id].uid;
|
||||
skuid = NoteCookie[e.user_id];
|
||||
} else if (BotConfig.dailyNote && BotConfig.dailyNote[e.user_id]) {
|
||||
cookie = BotConfig.dailyNote[e.user_id].cookie;
|
||||
uid = BotConfig.dailyNote[e.user_id].uid;
|
||||
skuid = BotConfig.NoteCookie[e.user_id];
|
||||
}
|
||||
}
|
||||
this.e.uid = uid;
|
||||
this.e.cookie = cookie;
|
||||
return {
|
||||
cookie,
|
||||
uid,
|
||||
skuid
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user