2022-08-16 23:24:54 +08:00
|
|
|
|
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'
|
2022-08-17 08:06:58 +08:00
|
|
|
|
import utils from '../model/mys/utils.js';
|
2022-08-16 23:24:54 +08:00
|
|
|
|
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
|
|
|
|
|
};
|
2022-08-18 23:15:49 +08:00
|
|
|
|
const nameData = ["原神", "崩坏3", "崩坏2", "未定事件簿"];
|
2022-08-16 23:24:54 +08:00
|
|
|
|
/** 配置文件 */
|
|
|
|
|
export default class user {
|
|
|
|
|
constructor(e) {
|
2022-08-18 23:15:49 +08:00
|
|
|
|
this.e = e;
|
|
|
|
|
this.stokenPath = `./plugins/${plugin}/data/yaml/`
|
|
|
|
|
this.yunPath = `./plugins/${plugin}/data/yunToken/`;
|
2022-08-16 23:24:54 +08:00
|
|
|
|
this.getyunToken(this.e)
|
|
|
|
|
}
|
2022-08-18 23:15:49 +08:00
|
|
|
|
async getCkData() {
|
|
|
|
|
let sumData = {};
|
2022-08-16 23:24:54 +08:00
|
|
|
|
await this.cookie(this.e)
|
|
|
|
|
this.miHoYoApi = new MihoYoApi(this.e);
|
2022-08-18 23:15:49 +08:00
|
|
|
|
if (this.e.yuntoken) {
|
2022-08-17 23:12:40 +08:00
|
|
|
|
let yunres = await this.miHoYoApi.logyunGenshen();
|
2022-08-16 23:44:24 +08:00
|
|
|
|
let yundata = yunres.data
|
2022-08-18 23:15:49 +08:00
|
|
|
|
if (yunres.retcode === 0) {
|
|
|
|
|
sumData["云原神"] = {
|
|
|
|
|
"今日可获取": yundata?.coin?.coin_num,
|
|
|
|
|
"免费时长": yundata?.free_time?.free_time,
|
|
|
|
|
"总时长": yundata.total_time
|
2022-08-16 23:44:24 +08:00
|
|
|
|
}
|
2022-08-16 23:24:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-18 23:15:49 +08:00
|
|
|
|
if (this.e.cookies) {
|
2022-08-17 23:12:40 +08:00
|
|
|
|
let mysres = await this.miHoYoApi.getTasksList();
|
2022-08-18 23:15:49 +08:00
|
|
|
|
if (mysres.retcode === 0) {
|
|
|
|
|
sumData["米游社"] = {
|
|
|
|
|
"米游币任务": mysres.data.can_get_points != 0 ? "未完成" : "已完成",
|
|
|
|
|
"米游币余额": mysres.data.total_points,
|
|
|
|
|
"今日剩余可获取": mysres.data.can_get_points
|
2022-08-16 23:44:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-18 23:15:49 +08:00
|
|
|
|
|
2022-08-16 23:44:24 +08:00
|
|
|
|
}
|
2022-08-18 23:15:49 +08:00
|
|
|
|
if (this.e.cookie) {
|
|
|
|
|
for (let name of nameData) {
|
2022-08-17 23:12:40 +08:00
|
|
|
|
let resSign = await this.miHoYoApi.honkai3rdSignTask(name);
|
2022-08-18 23:15:49 +08:00
|
|
|
|
if (resSign?.upData) {
|
2022-08-16 23:44:24 +08:00
|
|
|
|
// console.log(resSign?.upData)
|
2022-08-18 23:15:49 +08:00
|
|
|
|
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 ? "已签到" : "未签到",
|
|
|
|
|
"累计签到": item.total_sign_day + "天",
|
|
|
|
|
"今天奖励": item.awards
|
2022-08-16 23:44:24 +08:00
|
|
|
|
}
|
2022-08-16 23:24:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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,
|
2022-08-18 23:15:49 +08:00
|
|
|
|
uid,
|
|
|
|
|
skuid
|
2022-08-16 23:24:54 +08:00
|
|
|
|
} = await this.getCookie(e);
|
|
|
|
|
let cookiesDoc = await this.getcookiesDoc();
|
2022-08-18 23:15:49 +08:00
|
|
|
|
let miHoYoApi = new MihoYoApi(this.e);
|
2022-08-16 23:24:54 +08:00
|
|
|
|
if (!cookie) {
|
2022-08-17 08:00:28 +08:00
|
|
|
|
e.reply("请先#绑定cookie\n发送【体力帮助】查看配置教程")
|
2022-08-16 23:24:54 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-08-18 23:15:49 +08:00
|
|
|
|
let stokens = miHoYoApi.getStoken(e.user_id)
|
|
|
|
|
if (!stokens) {
|
2022-08-16 23:24:54 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (!cookie.includes("login_ticket") && (isV3 && !skuid?.login_ticket)) {
|
2022-08-17 21:51:22 +08:00
|
|
|
|
// e.reply("米游社登录cookie不完整,请前往米游社通行证处重新获取cookie~\ncookies必须包含login_ticket【教程】 " + cookiesDoc)
|
2022-08-16 23:24:54 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
2022-08-18 23:15:49 +08:00
|
|
|
|
async getcookiesDoc() {
|
2022-08-16 23:24:54 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|