From 1c2b6b3d3ea95e194126b9f5b9b1ce8726347313 Mon Sep 17 00:00:00 2001 From: yoimiya-kokomi <592981798@qq.com> Date: Mon, 4 Jul 2022 04:51:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E`#=E4=B8=8A=E4=BC=A0=E6=B7=B1?= =?UTF-8?q?=E6=B8=8A=E6=95=B0=E6=8D=AE`=E5=91=BD=E4=BB=A4=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=A7=92=E8=89=B2=20=E5=BA=94=E8=BE=BE=E3=80=81?= =?UTF-8?q?=E8=90=8D=E5=84=BF=20=E7=9A=84=E8=A7=92=E8=89=B2=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8F=8A=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++ apps/stat.js | 74 ++++++++++++++++++++++++++++-- components/Data.js | 18 ++++---- components/models/HutaoApi.js | 21 +++++++-- config/character_default.js | 6 ++- index.js | 8 +++- resources/help/help-cfg_default.js | 4 ++ resources/stat/abyss-pct.html | 5 +- resources/stat/abyss-team.html | 7 +-- resources/stat/character.html | 6 ++- 10 files changed, 130 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db958071..097aeb69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 1.8.4 + +* 新增`#上传深渊数据`命令 + * 可上传自己角色的深渊挑战数据及角色列表,不会上传其他信息 + * 上传数据用于`#角色持有率 #深渊出场率`等统计,可使统计更加及时准确 + * 数据统计及服务来自SG团队胡桃API +* 新增角色 派蒙、瑶瑶、白术、伐难、应达、散兵、女士、萍儿 的角色配置及图片 + # 1.8.3 * `#刻晴` 角色卡片功能升级 diff --git a/apps/stat.js b/apps/stat.js index 652b5467..d3361ec9 100644 --- a/apps/stat.js +++ b/apps/stat.js @@ -3,9 +3,8 @@ * * */ import { HutaoApi, Character } from "../components/models.js"; -import { Cfg } from "../components/index.js"; +import { Cfg, Data } from "../components/index.js"; import lodash from "lodash"; -import { segment } from "oicq"; import fs from "fs"; import Common from "../components/Common.js"; @@ -193,7 +192,6 @@ async function getTalentData(e, isUpdate = false) { export async function abyssTeam(e, { render }) { - let MysApi = await e.getMysApi({ auth: "cookie", // 所有用户均可查询 targetType: "self", // 被查询用户可以是任意用户 @@ -225,7 +223,6 @@ export async function abyssTeam(e, { render }) { avatarRet[avatar.id] = Math.min(avatar.level, avatar.weapon_level) * 100 + Math.max(avatar.a_original, avatar.e_original, avatar.q_original) * 1000 }); - let getTeamCfg = (str) => { let teams = str.split(","); teams.sort(); @@ -385,4 +382,73 @@ export async function abyssTeam(e, { render }) { teams: ret, avatars: avatarMap, }, { e, render, scale: 1.5 }); +} + +export async function uploadData(e) { + let MysApi = await e.getMysApi({ + auth: "cookie", + targetType: "self", + cookieType: "self", + action: "获取信息" + }); + if (!MysApi) return; + let ret = {}; + let uid = e.selfUser.uid; + try { + let resDetail = await MysApi.getCharacter(); + let resAbyss = await MysApi.getSpiralAbyss(1); + if (!resDetail || !resAbyss || !resDetail.avatars || resDetail.avatars.length <= 3) { + e.reply("角色信息获取失败"); + return true; + } + let playerAvatars = []; + lodash.forEach(resDetail.avatars || [], (avatar) => { + let tmp = Data.getData(avatar, "id,level,activedConstellationNum:actived_constellation_num") + tmp.weapon = Data.getData(avatar.weapon, "id,level,affixLevel:affix_level"); + let setMap = {}; + lodash.forEach(avatar.reliquaries, (ds) => { + setMap[ds.set.id] = setMap[ds.set.id] || 0; + setMap[ds.set.id]++; + }) + let reliquarySets = []; + lodash.forEach(setMap, (count, id) => { + reliquarySets.push({ id: id * 1, count }) + }); + tmp.reliquarySets = reliquarySets; + playerAvatars.push(tmp); + }) + let playerSpiralAbyssesLevels = []; + let getBattleData = function (ds) { + let avatars = []; + lodash.forEach(ds.avatars, (a) => { + avatars.push(a.id); + }) + return { + battleIndex: ds.index - 1 || 0, + avatarIds: avatars + } + } + lodash.forEach(resAbyss.floors || [], (floor) => { + lodash.forEach(floor.levels || [], (level) => { + playerSpiralAbyssesLevels.push({ + floorIndex: floor.index, + levelIndex: level.index, + star: level.star, + battles: [getBattleData(level.battles[0] || {}), getBattleData(level.battles[1] || {})] + }) + }) + }); + ret = await HutaoApi.upload({ + uid: uid.toString(), + playerAvatars, + playerSpiralAbyssesLevels + }); + } catch (err) { + } + if (ret && ret.retcode === 0) { + e.reply(`uid:${uid}本次深渊记录上传成功\n多谢支持,喵~`); + } else { + e.reply(`${ret.message || "上传失败"},请稍后重试...`); + } + return true; } \ No newline at end of file diff --git a/components/Data.js b/components/Data.js index 8b71142f..b92d4238 100644 --- a/components/Data.js +++ b/components/Data.js @@ -14,13 +14,13 @@ let Data = { nowPath = rootPath; pathList.forEach((name, idx) => { name = name.trim(); - if (!includeFile && idx <= pathList.length - 1) { - nowPath += name + "/"; - if (name) { - if (!fs.existsSync(nowPath)) { - fs.mkdirSync(nowPath); - } + // if (!includeFile && idx <= pathList.length - 1) { + nowPath += name + "/"; + if (name) { + if (!fs.existsSync(nowPath)) { + fs.mkdirSync(nowPath); } + // } } }) }, @@ -50,8 +50,10 @@ let Data = { } // 检查并创建目录 - Data.createDir(path, true); - return fs.writeFileSync(`${path}/${file}`, JSON.stringify(data, null, space)); + Data.createDir(_path, path, true); + console.log(data); + delete data._res; + return fs.writeFileSync(`${_path}/${path}/${file}`, JSON.stringify(data, null, space)); }, async importModule(path, file, rootPath = _path) { diff --git a/components/models/HutaoApi.js b/components/models/HutaoApi.js index c4764425..1e93870d 100644 --- a/components/models/HutaoApi.js +++ b/components/models/HutaoApi.js @@ -5,6 +5,7 @@ * */ import fetch from "node-fetch"; +import lodash from "lodash"; const host = "http://49.232.91.210:88/miaoPlugin/hutaoApi"; @@ -15,17 +16,18 @@ function getApi(api) { } let HutaoApi = { - async req(url, data) { + async req(url, param = {}) { let cacheData = await redis.get(`hutao:${url}`); - if (cacheData) { + if (cacheData && param.method !== "POST") { return JSON.parse(cacheData) } let response = await fetch(getApi(`${url}`), { - method: "GET", + ...param, + method: param.method || "GET", }); let retData = await response.json(); - if (retData && retData.data) { + if (retData && retData.data && param.method !== "POST") { let d = new Date(); retData.lastUpdate = `${d.toLocaleDateString()} ${d.toTimeString().substr(0, 5)}`; await redis.set(`hutao:${url}`, JSON.stringify(retData), { EX: 3600 }); @@ -44,6 +46,17 @@ let HutaoApi = { async getAbyssTeam() { return await HutaoApi.req("/Statistics/TeamCombination"); + }, + + async upload(data) { + let body = JSON.stringify(data); + return await HutaoApi.req("/Record/Upload", { + method: "POST", + headers: { + 'Content-Type': 'text/json; charset=utf-8', + }, + body + }); } }; diff --git a/config/character_default.js b/config/character_default.js index 20a0bb60..31966faf 100644 --- a/config/character_default.js +++ b/config/character_default.js @@ -23,7 +23,9 @@ export const customCharacters = { nvshi: ["女士", "炽热的炎之魔女", "炎之魔女"], baizhu: ["白术", "长生"], yaoyao: ["瑶瑶", "遥遥", "遥遥无期"], - fanan: ["伐难", "水夜叉"] + fanan: ["伐难", "水夜叉"], + yingda: ["应达", "火夜叉", "火鼠大将"], + ping: ["萍姥姥", "歌尘浪市真君", "歌尘浪市", "萍儿"] } /* @@ -32,7 +34,7 @@ export const customCharacters = { * */ export const wifeData = { // 老婆&女朋友:成女、少女 - girlfriend: "伐难, 女士", + girlfriend: "伐难, 女士, 萍姥姥", // 老公&男朋友:成男、少男 boyfriend: "散兵, 白术", diff --git a/index.js b/index.js index bef4ec34..c311ffac 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ export { import { wifeReg } from "./apps/character.js"; -import { consStat, abyssPct, abyssTeam } from "./apps/stat.js"; +import { consStat, abyssPct, abyssTeam, uploadData } from "./apps/stat.js"; import { wiki, calendar } from "./apps/wiki.js"; import { help, versionInfo } from "./apps/help.js"; import lodash from "lodash"; @@ -32,7 +32,8 @@ export { help, versionInfo, calendar, - profileCfg + profileCfg, + uploadData }; @@ -102,6 +103,9 @@ let rule = { reg: "^(#|喵喵)+(日历|日历列表)$", describe: "【#日历】 活动日历", }, + uploadData: { + reg: "^#上传深渊数据$" + }, ...adminRule }; diff --git a/resources/help/help-cfg_default.js b/resources/help/help-cfg_default.js index 3fc92c3c..a29f7d1e 100644 --- a/resources/help/help-cfg_default.js +++ b/resources/help/help-cfg_default.js @@ -107,6 +107,10 @@ export const helpList = [{ icon: 86, title: "#签到", desc: "米游社原神签到" + }, { + icon: 77, + title: "#上传深渊数据", + desc: "上传您的深渊数据用于数据统计" }] }, { group: "其他查询指令", diff --git a/resources/stat/abyss-pct.html b/resources/stat/abyss-pct.html index c533ab31..7f98644c 100644 --- a/resources/stat/abyss-pct.html +++ b/resources/stat/abyss-pct.html @@ -21,8 +21,9 @@
深渊出场率统计
diff --git a/resources/stat/abyss-team.html b/resources/stat/abyss-team.html index d8385ebd..4d7391d0 100644 --- a/resources/stat/abyss-team.html +++ b/resources/stat/abyss-team.html @@ -16,10 +16,11 @@
深渊配队说明
diff --git a/resources/stat/character.html b/resources/stat/character.html index 432ed91c..76c1fd10 100644 --- a/resources/stat/character.html +++ b/resources/stat/character.html @@ -29,9 +29,11 @@ return (num * 100).toFixed(2);
角色持有率说明