2022-04-04 21:36:44 +00:00
|
|
|
|
/*
|
|
|
|
|
* 胡桃数据库的统计
|
|
|
|
|
*
|
|
|
|
|
* */
|
|
|
|
|
import { HutaoApi, Character } from "../components/models.js";
|
2022-07-03 20:51:27 +00:00
|
|
|
|
import { Cfg, Data } from "../components/index.js";
|
2022-04-04 21:36:44 +00:00
|
|
|
|
import lodash from "lodash";
|
2022-05-04 20:53:20 +00:00
|
|
|
|
import fs from "fs";
|
2022-05-22 13:10:10 +00:00
|
|
|
|
import Common from "../components/Common.js";
|
2022-04-04 21:36:44 +00:00
|
|
|
|
|
|
|
|
|
export async function consStat(e, { render }) {
|
2022-04-09 21:33:21 +00:00
|
|
|
|
if (Cfg.isDisable(e, "wiki.abyss")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-04-04 21:36:44 +00:00
|
|
|
|
|
|
|
|
|
let consData = await HutaoApi.getCons();
|
2022-06-21 22:07:12 +00:00
|
|
|
|
|
2022-04-04 21:36:44 +00:00
|
|
|
|
if (!consData) {
|
2022-05-05 10:10:29 +00:00
|
|
|
|
e.reply("角色持有数据获取失败,请稍后重试~");
|
2022-04-04 21:36:44 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let msg = e.msg;
|
|
|
|
|
|
|
|
|
|
let mode = /持有/.test(msg) ? "char" : "cons";
|
|
|
|
|
|
|
|
|
|
let conNum = -1;
|
|
|
|
|
if (mode === "cons") {
|
|
|
|
|
lodash.forEach([/0|零/, /1|一/, /2|二/, /3|三/, /4|四/, /5|五/, /6|六|满/], (reg, idx) => {
|
|
|
|
|
if (reg.test(msg)) {
|
|
|
|
|
conNum = idx;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!consData && !consData.data) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 22:07:12 +00:00
|
|
|
|
let data = consData.data;
|
|
|
|
|
|
|
|
|
|
let Lumine = lodash.filter(data, (ds) => ds.avatar === 10000007)[0] || {},
|
|
|
|
|
Aether = lodash.filter(data, (ds) => ds.avatar === 10000005)[0] || {};
|
|
|
|
|
|
|
|
|
|
Lumine.holdingRate = (1 - Aether.holdingRate) || Lumine.holdingRate;
|
|
|
|
|
|
2022-04-04 21:36:44 +00:00
|
|
|
|
let ret = [];
|
|
|
|
|
|
2022-06-21 22:07:12 +00:00
|
|
|
|
lodash.forEach(data, (ds) => {
|
2022-04-04 21:36:44 +00:00
|
|
|
|
let char = Character.get(ds.avatar);
|
|
|
|
|
|
|
|
|
|
let data = {
|
|
|
|
|
name: char.name || ds.avatar,
|
|
|
|
|
star: char.star || 3,
|
|
|
|
|
hold: ds.holdingRate
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (mode === "char") {
|
|
|
|
|
data.cons = lodash.map(ds.rate, (c) => {
|
|
|
|
|
c.value = c.value * ds.holdingRate;
|
|
|
|
|
return c;
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
data.cons = ds.rate
|
|
|
|
|
}
|
2022-06-06 20:59:47 +00:00
|
|
|
|
data.cons = lodash.sortBy(data.cons, ['id'])
|
2022-04-04 21:36:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret.push(data);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (conNum > -1) {
|
|
|
|
|
ret = lodash.sortBy(ret, [`cons[${conNum}].value`]);
|
|
|
|
|
ret.reverse();
|
|
|
|
|
} else {
|
|
|
|
|
ret = lodash.sortBy(ret, ['hold']);
|
|
|
|
|
}
|
2022-05-22 13:10:10 +00:00
|
|
|
|
//渲染图像
|
|
|
|
|
return await Common.render("stat/character", {
|
2022-04-04 21:36:44 +00:00
|
|
|
|
chars: ret,
|
|
|
|
|
abbr: Character.getAbbr(),
|
|
|
|
|
mode: mode,
|
|
|
|
|
conNum,
|
|
|
|
|
lastUpdate: consData.lastUpdate,
|
|
|
|
|
pct: function (num) {
|
|
|
|
|
return (num * 100).toFixed(2);
|
2022-04-09 21:33:21 +00:00
|
|
|
|
},
|
2022-05-22 13:10:10 +00:00
|
|
|
|
}, { e, render, scale: 1.5 });
|
2022-04-04 21:36:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function abyssPct(e, { render }) {
|
2022-04-09 21:33:21 +00:00
|
|
|
|
|
|
|
|
|
if (Cfg.isDisable(e, "wiki.abyss")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 21:36:44 +00:00
|
|
|
|
let abyssData = await HutaoApi.getAbyssPct();
|
|
|
|
|
if (!abyssData) {
|
2022-05-05 10:10:29 +00:00
|
|
|
|
e.reply("深渊出场数据获取失败,请稍后重试~");
|
2022-04-04 21:36:44 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let ret = [], chooseFloor = -1, msg = e.msg;
|
|
|
|
|
|
|
|
|
|
const floorName = {
|
|
|
|
|
"12": "十二层",
|
|
|
|
|
"11": "十一层",
|
|
|
|
|
"10": "十层",
|
|
|
|
|
"9": "九层"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 匹配深渊楼层信息
|
|
|
|
|
lodash.forEach(floorName, (cn, num) => {
|
|
|
|
|
let reg = new RegExp(`${cn}|${num}`);
|
|
|
|
|
if (reg.test(msg)) {
|
|
|
|
|
chooseFloor = num;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-29 20:40:06 +00:00
|
|
|
|
let data = abyssData.data;
|
|
|
|
|
data = lodash.sortBy(data, "floor");
|
|
|
|
|
|
|
|
|
|
lodash.forEach(data, (floorData) => {
|
2022-04-04 21:36:44 +00:00
|
|
|
|
let floor = {
|
|
|
|
|
floor: floorData.floor,
|
|
|
|
|
};
|
|
|
|
|
let avatars = [];
|
|
|
|
|
lodash.forEach(floorData.avatarUsage, (ds) => {
|
|
|
|
|
let char = Character.get(ds.id);
|
|
|
|
|
if (char) {
|
|
|
|
|
avatars.push({
|
|
|
|
|
name: char.name,
|
2022-06-06 20:59:47 +00:00
|
|
|
|
star: char.star,
|
2022-04-09 21:33:21 +00:00
|
|
|
|
value: ds.value * 8
|
2022-04-04 21:36:44 +00:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
avatars = lodash.sortBy(avatars, "value", ["asc"]);
|
|
|
|
|
avatars.reverse();
|
|
|
|
|
if (chooseFloor === -1) {
|
|
|
|
|
avatars = avatars.slice(0, 14);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret.push({
|
|
|
|
|
floor: floorData.floor,
|
|
|
|
|
avatars
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
|
2022-05-22 13:10:10 +00:00
|
|
|
|
return await Common.render("stat/abyss-pct", {
|
2022-04-04 21:36:44 +00:00
|
|
|
|
abyss: ret,
|
|
|
|
|
floorName,
|
|
|
|
|
chooseFloor,
|
|
|
|
|
lastUpdate: abyssData.lastUpdate,
|
|
|
|
|
pct: function (num) {
|
|
|
|
|
return (num * 100).toFixed(2);
|
2022-04-09 21:33:21 +00:00
|
|
|
|
},
|
2022-05-22 13:10:10 +00:00
|
|
|
|
}, { e, render, scale: 1.5 });
|
2022-04-04 21:36:44 +00:00
|
|
|
|
|
2022-05-04 20:53:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getTalentData(e, isUpdate = false) {
|
|
|
|
|
|
|
|
|
|
// 技能查询缓存
|
|
|
|
|
let cachePath = `./data/cache/`;
|
|
|
|
|
if (!fs.existsSync(cachePath)) {
|
|
|
|
|
fs.mkdirSync(cachePath);
|
|
|
|
|
}
|
|
|
|
|
cachePath += "talentList/";
|
|
|
|
|
if (!fs.existsSync(cachePath)) {
|
|
|
|
|
fs.mkdirSync(cachePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let avatarRet = [];
|
|
|
|
|
let uid = e.selfUser.uid;
|
|
|
|
|
|
|
|
|
|
let hasCache = await redis.get(`cache:uid-talent-new:${uid}`);
|
|
|
|
|
if (hasCache) {
|
|
|
|
|
// 有缓存优先使用缓存
|
|
|
|
|
let jsonRet = fs.readFileSync(cachePath + `${uid}.json`, "utf8");
|
|
|
|
|
avatarRet = JSON.parse(jsonRet);
|
|
|
|
|
return avatarRet;
|
|
|
|
|
} else if (!isUpdate) {
|
|
|
|
|
e.noReplyTalentList = true;
|
|
|
|
|
await YunzaiApps.mysInfo.talentList(e);
|
|
|
|
|
return await getTalentData(e, true);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function abyssTeam(e, { render }) {
|
|
|
|
|
|
|
|
|
|
let MysApi = await e.getMysApi({
|
|
|
|
|
auth: "cookie", // 所有用户均可查询
|
|
|
|
|
targetType: "self", // 被查询用户可以是任意用户
|
|
|
|
|
cookieType: "self" // cookie可以是任意可用cookie
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!MysApi || !MysApi.selfUser || !MysApi.selfUser.uid) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let abyssData = await HutaoApi.getAbyssTeam();
|
|
|
|
|
if (!abyssData || !abyssData.data) {
|
2022-05-05 10:10:29 +00:00
|
|
|
|
e.reply("深渊组队数据获取失败,请稍后重试~");
|
2022-05-04 20:53:20 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
abyssData = abyssData.data;
|
|
|
|
|
let talentData = await getTalentData(e);
|
|
|
|
|
if (!talentData || talentData.length === 0) {
|
2022-05-05 10:10:29 +00:00
|
|
|
|
e.reply("暂时未能获得角色的练度信息,请使用【#练度统计】命令尝试手工获取...");
|
2022-05-04 20:53:20 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let avatarRet = {};
|
|
|
|
|
let data = {};
|
|
|
|
|
|
|
|
|
|
let noAvatar = {};
|
|
|
|
|
|
|
|
|
|
lodash.forEach(talentData, (avatar) => {
|
|
|
|
|
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();
|
|
|
|
|
let teamMark = 0;
|
|
|
|
|
lodash.forEach(teams, (a) => {
|
|
|
|
|
if (!avatarRet[a]) {
|
|
|
|
|
teamMark = -1;
|
|
|
|
|
noAvatar[a] = true;
|
|
|
|
|
}
|
|
|
|
|
if (teamMark !== -1) {
|
|
|
|
|
teamMark += avatarRet[a] * 1;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (teamMark === -1) {
|
|
|
|
|
teamMark = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
key: teams.join(","),
|
|
|
|
|
mark: teamMark
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let hasSame = function (team1, team2) {
|
|
|
|
|
for (let idx = 0; idx < team1.length; idx++) {
|
|
|
|
|
if (team2.includes(team1[idx])) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lodash.forEach(abyssData, (ds) => {
|
|
|
|
|
let floor = ds.level.floor;
|
|
|
|
|
if (!data[floor]) {
|
|
|
|
|
data[floor] = {
|
|
|
|
|
up: {},
|
|
|
|
|
down: {},
|
|
|
|
|
teams: []
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
lodash.forEach(ds.teams, (ds) => {
|
|
|
|
|
lodash.forEach(['up', 'down'], (halfKey) => {
|
|
|
|
|
let teamCfg = getTeamCfg(ds.id[`${halfKey}Half`]);
|
|
|
|
|
if (teamCfg) {
|
|
|
|
|
if (!data[floor][halfKey][teamCfg.key]) {
|
|
|
|
|
data[floor][halfKey][teamCfg.key] = {
|
|
|
|
|
count: 0,
|
|
|
|
|
mark: 0,
|
|
|
|
|
hasTeam: teamCfg.mark > 1
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
data[floor][halfKey][teamCfg.key].count += ds.value;
|
|
|
|
|
data[floor][halfKey][teamCfg.key].mark += ds.value * teamCfg.mark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let temp = [];
|
|
|
|
|
lodash.forEach(['up', 'down'], (halfKey) => {
|
|
|
|
|
lodash.forEach(data[floor][halfKey], (ds, team) => {
|
|
|
|
|
temp.push({
|
|
|
|
|
team,
|
|
|
|
|
teamArr: team.split(","),
|
|
|
|
|
half: halfKey,
|
|
|
|
|
count: ds.count,
|
|
|
|
|
mark: ds.mark,
|
|
|
|
|
mark2: 1,
|
|
|
|
|
hasTeam: ds.hasTeam
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
temp = lodash.sortBy(temp, "mark")
|
|
|
|
|
data[floor].teams = temp.reverse();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let ret = {};
|
|
|
|
|
|
|
|
|
|
lodash.forEach(data, (floorData, floor) => {
|
|
|
|
|
ret[floor] = {}
|
|
|
|
|
let ds = ret[floor];
|
|
|
|
|
lodash.forEach(floorData.teams, (t1) => {
|
|
|
|
|
if (t1.mark2 <= 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
lodash.forEach(floorData.teams, (t2) => {
|
|
|
|
|
if (t1.mark2 <= 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (t1.half === t2.half || t2.mark2 <= 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let teamKey = t1.half === "up" ? (t1.team + "+" + t2.team) : (t2.team + "+" + t1.team);
|
|
|
|
|
if (ds[teamKey]) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (hasSame(t1.teamArr, t2.teamArr)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ds[teamKey] = {
|
|
|
|
|
up: t1.half === "up" ? t1 : t2,
|
|
|
|
|
down: t1.half === "up" ? t2 : t1,
|
|
|
|
|
count: Math.min(t1.count, t2.count),
|
|
|
|
|
mark: t1.hasTeam && t2.hasTeam ? t1.mark + t2.mark : t1.count + t2.count // 如果不存在组队则进行评分惩罚
|
|
|
|
|
}
|
|
|
|
|
t1.mark2--;
|
|
|
|
|
t2.mark2--;
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
if (lodash.keys(ds).length >= 20) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
lodash.forEach(ret, (ds, floor) => {
|
|
|
|
|
ds = lodash.sortBy(lodash.values(ds), 'mark');
|
|
|
|
|
ds = ds.reverse();
|
|
|
|
|
ds = ds.slice(0, 4);
|
|
|
|
|
|
|
|
|
|
lodash.forEach(ds, (team) => {
|
|
|
|
|
team.up.teamArr = Character.sortIds(team.up.teamArr);
|
|
|
|
|
team.down.teamArr = Character.sortIds(team.down.teamArr);
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ret[floor] = ds;
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
let avatarMap = {};
|
|
|
|
|
|
|
|
|
|
lodash.forEach(talentData, (ds) => {
|
|
|
|
|
avatarMap[ds.id] = {
|
|
|
|
|
id: ds.id,
|
|
|
|
|
name: ds.name,
|
|
|
|
|
star: ds.rarity,
|
|
|
|
|
level: ds.level,
|
|
|
|
|
cons: ds.cons
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
lodash.forEach(noAvatar, (d, id) => {
|
|
|
|
|
let char = Character.get(id);
|
|
|
|
|
avatarMap[id] = {
|
|
|
|
|
id,
|
|
|
|
|
name: char.name,
|
|
|
|
|
star: char.star,
|
|
|
|
|
level: 0,
|
|
|
|
|
cons: 0,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2022-05-22 13:10:10 +00:00
|
|
|
|
return await Common.render("stat/abyss-team", {
|
2022-05-04 20:53:20 +00:00
|
|
|
|
teams: ret,
|
|
|
|
|
avatars: avatarMap,
|
2022-05-22 13:10:10 +00:00
|
|
|
|
}, { e, render, scale: 1.5 });
|
2022-07-03 20:51:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2022-07-07 23:02:25 +00:00
|
|
|
|
//Data.writeJson('/test-data', 'abyss.json', resAbyss);
|
2022-07-03 20:51:27 +00:00
|
|
|
|
if (!resDetail || !resAbyss || !resDetail.avatars || resDetail.avatars.length <= 3) {
|
|
|
|
|
e.reply("角色信息获取失败");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-07-07 23:02:25 +00:00
|
|
|
|
delete resDetail._res;
|
|
|
|
|
delete resAbyss._res;
|
|
|
|
|
ret = await HutaoApi.uploadData({
|
|
|
|
|
uid,
|
|
|
|
|
resDetail,
|
|
|
|
|
resAbyss
|
2022-07-03 20:51:27 +00:00
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
2022-07-07 23:02:25 +00:00
|
|
|
|
// console.log(err);
|
2022-07-03 20:51:27 +00:00
|
|
|
|
}
|
|
|
|
|
if (ret && ret.retcode === 0) {
|
2022-07-07 23:02:25 +00:00
|
|
|
|
let msg = [`uid:${uid}本次深渊记录上传成功,多谢支持,喵~`];
|
|
|
|
|
if (ret.data) {
|
|
|
|
|
let addMsg = function (title, ds) {
|
|
|
|
|
if (!ds && !ds.avatarId && !ds.percent) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let char = Character.get(ds.avatarId);
|
|
|
|
|
title = `${title}:${char.name} ${(ds.value / 10000).toFixed(1)}W,`;
|
|
|
|
|
if (ds.percent < 0.2) {
|
2022-07-08 00:04:47 +00:00
|
|
|
|
msg.push(`${title}少于${(Math.max(0.1, 100 - ds.percent * 100)).toFixed(1)}%的${char.name}用户`)
|
2022-07-07 23:02:25 +00:00
|
|
|
|
} else {
|
2022-07-08 00:04:47 +00:00
|
|
|
|
msg.push(`${title}超过${(Math.min(99.9, ds.percent * 100)).toFixed(1)}%的${char.name}用户`)
|
2022-07-07 23:02:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
msg.push("本次深渊排行:");
|
|
|
|
|
addMsg("最强一击", ret.data.damage || {});
|
|
|
|
|
addMsg("承受伤害", ret.data.takeDamage || {});
|
|
|
|
|
}
|
|
|
|
|
e.reply(msg.join("\n"))
|
2022-07-03 20:51:27 +00:00
|
|
|
|
} else {
|
|
|
|
|
e.reply(`${ret.message || "上传失败"},请稍后重试...`);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2022-04-04 21:36:44 +00:00
|
|
|
|
}
|