From 67aecf153852d602ff0170089a401a64c33a07ad Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Tue, 16 Aug 2022 23:24:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD=E3=80=90#c?= =?UTF-8?q?k=E6=9F=A5=E8=AF=A2=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 + apps/index.js | 7 ++- apps/user.js | 46 +++++++++++++++ model/user.js | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 apps/user.js create mode 100644 model/user.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 66ae5cc..5c56c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.1.8 +* 新增指令`#ck查询` +* 可查询当前cookie绑定状态的签到信息以及米游币信息数据 # 1.1.7 * 新增指令`#米币查询` * 新增`道具图鉴`图鉴数据 diff --git a/apps/index.js b/apps/index.js index aef49ff..425362f 100644 --- a/apps/index.js +++ b/apps/index.js @@ -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 }; diff --git a/apps/user.js b/apps/user.js new file mode 100644 index 0000000..d3797a4 --- /dev/null +++ b/apps/user.js @@ -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; +} \ No newline at end of file diff --git a/model/user.js b/model/user.js new file mode 100644 index 0000000..92c12c2 --- /dev/null +++ b/model/user.js @@ -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 + } + } +}