koishi-plugin-beatsaber-bot
Version:
一个 用于 BeatSaber 的 koishi Bot 插件
64 lines (63 loc) • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScoreSaberService = void 0;
const sortScore_1 = require("../sortScore");
class ScoreSaberService {
constructor(bsClient, scClient) {
this.bsClient = bsClient;
this.scClient = scClient;
}
getScoreUserById(id) {
return this.scClient.getScoreUserById(id);
}
async getScoreByPlayerIdAndMapId(playerId, mapId) {
const map = await this.bsClient.searchMapById(mapId);
if (!map) {
return null;
}
const hash = map.versions[0].hash;
const reqs = map.versions[0].diffs.map(it => ({
diff: it.difficulty,
mode: it.characteristic,
hash: hash,
playerID: playerId,
leaderboardContext: 'general'
}));
const res = await Promise.all(reqs.map(item => {
// return scClient.getPlayerScore(item)
return null;
}));
const scores = res.filter(item => item != null);
// todo sort score
if (scores.length < 1) {
return null;
}
scores.sort(sortScore_1.sortScore);
return scores[0];
}
getScoreInfoById(id, page) {
return this.scClient.getScoreItemsById(id, page);
}
async getPlayerRecentScoreWithUserInfo(uid) {
const userInfo = this.getScoreUserById(uid);
const scores = await this.scClient.getScoreItemsById(uid, 1, 24)
.then(res => res.playerScores);
const awaitedUserInfo = await userInfo;
const hashes = scores.map(it => it.leaderboard.songHash);
let hashInfo = await this.bsClient.getMapsByHashes(hashes);
if (hashInfo.id) {
const map = hashInfo;
hashInfo = {};
hashInfo[map.versions[0].hash] = map;
}
let res = scores.map(it => ({
mapId: hashInfo[it.leaderboard.songHash.toLowerCase()]?.id,
...it
}));
return {
scores: res,
userInfo: awaitedUserInfo
};
}
}
exports.ScoreSaberService = ScoreSaberService;