Skip to content

Commit

Permalink
Use new parameters for online score attributes endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian8337 committed Sep 14, 2024
1 parent d5e3ff6 commit ca6af28
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 39 deletions.
7 changes: 4 additions & 3 deletions src/database/utils/elainaDb/UserBind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,10 @@ export class UserBind extends Manager {
continue;
}

const scoreId = score instanceof Score ? score.scoreID : score.id;
const liveAttribs =
await DPPProcessorRESTManager.getOnlineScoreAttributes(
scoreId,
score.uid,
score.hash,
Modes.droid,
PPCalculationMethod.live,
);
Expand All @@ -645,7 +645,8 @@ export class UserBind extends Manager {

const rebalAttribs =
await DPPProcessorRESTManager.getOnlineScoreAttributes(
scoreId,
score.uid,
score.hash,
Modes.droid,
PPCalculationMethod.rebalance,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export const run: ButtonCommand["run"] = async (_, interaction) => {
? player.recentPlays
: await DroidHelper.getRecentScores(player.id, 1, undefined, [
"id",
"uid",
"hash",
"score",
"filename",
"hash",
Expand All @@ -85,10 +87,10 @@ export const run: ButtonCommand["run"] = async (_, interaction) => {
}

const score = recentPlays[0];
const scoreId = score instanceof Score ? score.scoreID : score.id;

const scoreAttribs = await DPPProcessorRESTManager.getOnlineScoreAttributes(
scoreId,
score.uid,
score.hash,
Modes.droid,
PPCalculationMethod.live,
);
Expand Down
14 changes: 8 additions & 6 deletions src/interactions/commands/osu! and osu!droid/compare/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { EmbedCreator } from "@alice-utils/creators/EmbedCreator";
import { MessageCreator } from "@alice-utils/creators/MessageCreator";
import { BeatmapManager } from "@alice-utils/managers/BeatmapManager";
import { GuildMember } from "discord.js";
import { Player, Score } from "@rian8337/osu-droid-utilities";
import { Player } from "@rian8337/osu-droid-utilities";
import { CompareLocalization } from "@alice-localization/interactions/commands/osu! and osu!droid/compare/CompareLocalization";
import { CommandHelper } from "@alice-utils/helpers/CommandHelper";
import { InteractionHelper } from "@alice-utils/helpers/InteractionHelper";
Expand Down Expand Up @@ -70,7 +70,8 @@ export const run: SlashCommand["run"] = async (_, interaction) => {
case !!uid:
player = await DroidHelper.getPlayer(uid!, ["id", "username"]);

uid ??= player instanceof Player ? player.uid : player?.id ?? null;
uid ??=
player instanceof Player ? player.uid : (player?.id ?? null);

break;
case !!username:
Expand All @@ -84,7 +85,8 @@ export const run: SlashCommand["run"] = async (_, interaction) => {

player = await DroidHelper.getPlayer(username, ["id", "username"]);

uid ??= player instanceof Player ? player.uid : player?.id ?? null;
uid ??=
player instanceof Player ? player.uid : (player?.id ?? null);

break;
default:
Expand Down Expand Up @@ -131,6 +133,7 @@ export const run: SlashCommand["run"] = async (_, interaction) => {

const score = await DroidHelper.getScore(uid, cachedBeatmapHash, [
"id",
"uid",
"filename",
"hash",
"mode",
Expand All @@ -156,10 +159,9 @@ export const run: SlashCommand["run"] = async (_, interaction) => {
});
}

const scoreId = score instanceof Score ? score.scoreID : score.id;

const scoreAttribs = await DPPProcessorRESTManager.getOnlineScoreAttributes(
scoreId,
score.uid,
score.hash,
Modes.droid,
PPCalculationMethod.live,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export const run: SlashCommand["run"] = async (_, interaction) => {

const score = await DroidHelper.getScore(uid, hash, [
"id",
"uid",
"hash",
"score",
"combo",
"mark",
Expand Down Expand Up @@ -240,7 +242,8 @@ export const run: SlashCommand["run"] = async (_, interaction) => {
}

const droidAttribs = await DPPProcessorRESTManager.getOnlineScoreAttributes(
scoreId,
score.uid,
score.hash,
Modes.droid,
PPCalculationMethod.live,
true,
Expand All @@ -266,7 +269,8 @@ export const run: SlashCommand["run"] = async (_, interaction) => {
}

const osuAttribs = await DPPProcessorRESTManager.getOnlineScoreAttributes(
scoreId,
score.uid,
score.hash,
Modes.osu,
PPCalculationMethod.live,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { BeatmapManager } from "@alice-utils/managers/BeatmapManager";
import { EmbedCreator } from "@alice-utils/creators/EmbedCreator";
import { SelectMenuCreator } from "@alice-utils/creators/SelectMenuCreator";
import { Modes, RankedStatus } from "@rian8337/osu-base";
import { Score } from "@rian8337/osu-droid-utilities";
import { ProfileLocalization } from "@alice-localization/interactions/commands/osu! and osu!droid/profile/ProfileLocalization";
import { CommandHelper } from "@alice-utils/helpers/CommandHelper";
import { ConstantsLocalization } from "@alice-localization/core/constants/ConstantsLocalization";
Expand Down Expand Up @@ -193,7 +192,7 @@ export const run: SlashSubcommand<false>["run"] = async (_, interaction) => {
const score = await DroidHelper.getScore(
uid,
beatmapInfo.hash,
["id"],
["uid", "hash"],
);

if (!score) {
Expand All @@ -202,7 +201,8 @@ export const run: SlashSubcommand<false>["run"] = async (_, interaction) => {

const attribs =
await DPPProcessorRESTManager.getOnlineScoreAttributes(
score instanceof Score ? score.scoreID : score.id,
score.uid,
score.hash,
Modes.osu,
PPCalculationMethod.live,
);
Expand Down
9 changes: 6 additions & 3 deletions src/interactions/commands/osu! and osu!droid/recent/recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const run: SlashCommand["run"] = async (_, interaction) => {
| Pick<
OfficialDatabaseScore,
| "id"
| "uid"
| "hash"
| "score"
| "filename"
Expand Down Expand Up @@ -161,6 +162,7 @@ export const run: SlashCommand["run"] = async (_, interaction) => {
undefined,
[
"id",
"uid",
"hash",
"score",
"filename",
Expand Down Expand Up @@ -203,10 +205,11 @@ export const run: SlashCommand["run"] = async (_, interaction) => {

const scoreAttribs =
score instanceof RecentPlay
? score.droidAttribs ?? null
? (score.droidAttribs ?? null)
: (
await DPPProcessorRESTManager.getOnlineScoreAttributes(
score instanceof Score ? score.scoreID : score.id,
score.uid,
score.hash,
Modes.droid,
PPCalculationMethod.live,
)
Expand All @@ -219,7 +222,7 @@ export const run: SlashCommand["run"] = async (_, interaction) => {
: DroidHelper.getAvatarURL(player.id),
(<GuildMember | null>interaction.member)?.displayColor,
scoreAttribs,
score instanceof RecentPlay ? score.osuAttribs ?? null : undefined,
score instanceof RecentPlay ? (score.osuAttribs ?? null) : undefined,
localization.language,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ export const run: SlashCommand["run"] = async (_, interaction) => {
beatmap.hash,
[
"id",
"uid",
"hash",
"combo",
"mark",
"mode",
Expand Down
7 changes: 5 additions & 2 deletions src/interactions/contextmenus/message/compareScore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CommandHelper } from "@alice-utils/helpers/CommandHelper";
import { InteractionHelper } from "@alice-utils/helpers/InteractionHelper";
import { BeatmapManager } from "@alice-utils/managers/BeatmapManager";
import { Modes } from "@rian8337/osu-base";
import { Player, Score } from "@rian8337/osu-droid-utilities";
import { Player } from "@rian8337/osu-droid-utilities";
import { GuildMember, InteractionReplyOptions } from "discord.js";
import { MessageButtonCreator } from "@alice-utils/creators/MessageButtonCreator";
import { PPCalculationMethod } from "@alice-enums/utils/PPCalculationMethod";
Expand Down Expand Up @@ -89,6 +89,8 @@ export const run: MessageContextMenuCommand["run"] = async (_, interaction) => {
beatmapInfo.hash,
[
"id",
"uid",
"hash",
"score",
"filename",
"hash",
Expand Down Expand Up @@ -117,7 +119,8 @@ export const run: MessageContextMenuCommand["run"] = async (_, interaction) => {
);

const scoreAttribs = await DPPProcessorRESTManager.getOnlineScoreAttributes(
score instanceof Score ? score.scoreID : score.id,
score.uid,
score.hash,
Modes.droid,
PPCalculationMethod.live,
);
Expand Down
8 changes: 6 additions & 2 deletions src/utils/creators/EmbedCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ export abstract class EmbedCreator {
| Pick<
OfficialDatabaseScore,
| "id"
| "uid"
| "hash"
| "score"
| "combo"
| "mark"
Expand Down Expand Up @@ -554,7 +556,8 @@ export abstract class EmbedCreator {
? score.droidAttribs
: (
await DPPProcessorRESTManager.getOnlineScoreAttributes(
score instanceof Score ? score.scoreID : score.id,
score.uid,
score.hash,
Modes.droid,
PPCalculationMethod.live,
)
Expand All @@ -567,7 +570,8 @@ export abstract class EmbedCreator {
? score.osuAttribs
: (
await DPPProcessorRESTManager.getOnlineScoreAttributes(
score instanceof Score ? score.scoreID : score.id,
score.uid,
score.hash,
Modes.osu,
PPCalculationMethod.live,
)
Expand Down
14 changes: 8 additions & 6 deletions src/utils/helpers/ScoreDisplayHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,27 +281,29 @@ export abstract class ScoreDisplayHelper {
]
> => {
const droidAttribs = beatmapInfo
? droidAttribsCache.get(score.scoreID) ??
? (droidAttribsCache.get(score.scoreID) ??
(
await DPPProcessorRESTManager.getOnlineScoreAttributes(
score.scoreID,
score.uid,
score.hash,
Modes.droid,
PPCalculationMethod.live,
)
)?.attributes ??
null
null)
: null;

const osuAttribs = beatmapInfo
? osuAttribsCache.get(score.scoreID) ??
? (osuAttribsCache.get(score.scoreID) ??
(
await DPPProcessorRESTManager.getOnlineScoreAttributes(
score.scoreID,
score.uid,
score.hash,
Modes.osu,
PPCalculationMethod.live,
)
)?.attributes ??
null
null)
: null;

if (!droidAttribsCache.has(score.scoreID)) {
Expand Down
30 changes: 20 additions & 10 deletions src/utils/managers/DPPProcessorRESTManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,16 @@ export abstract class DPPProcessorRESTManager extends RESTManager {
/**
* Gets the difficulty and performance attributes of a score.
*
* @param scoreId The ID of the score.
* @param uid The uid of the player in the score.
* @param hash The MD5 hash of the beatmap in the score.
* @param mode The gamemode to calculate.
* @param calculationMethod The calculation method to use.
* @param generateStrainChart Whether to generate a strain chart.
* @returns The difficulty and performance attributes, `null` if the attributes cannot be retrieved.
*/
static async getOnlineScoreAttributes<THasStrainChart extends boolean>(
scoreId: number,
uid: number,
hash: string,
mode: Modes.droid,
calculationMethod: PPCalculationMethod.live,
generateStrainChart?: THasStrainChart,
Expand All @@ -438,14 +440,16 @@ export abstract class DPPProcessorRESTManager extends RESTManager {
/**
* Gets the difficulty and performance attributes of a score.
*
* @param scoreId The ID of the score.
* @param uid The uid of the player in the score.
* @param hash The MD5 hash of the beatmap in the score.
* @param mode The gamemode to calculate.
* @param calculationMethod The calculation method to use.
* @param generateStrainChart Whether to generate a strain chart.
* @returns The difficulty and performance attributes, `null` if the attributes cannot be retrieved.
*/
static async getOnlineScoreAttributes<THasStrainChart extends boolean>(
scoreId: number,
uid: number,
hash: string,
mode: Modes.droid,
calculationMethod: PPCalculationMethod.rebalance,
generateStrainChart?: THasStrainChart,
Expand All @@ -460,14 +464,16 @@ export abstract class DPPProcessorRESTManager extends RESTManager {
/**
* Gets the difficulty and performance attributes of a score.
*
* @param scoreId The ID of the score.
* @param uid The uid of the player in the score.
* @param hash The MD5 hash of the beatmap in the score.
* @param mode The gamemode to calculate.
* @param calculationMethod The calculation method to use.
* @param generateStrainChart Whether to generate a strain chart.
* @returns The difficulty and performance attributes, `null` if the attributes cannot be retrieved.
*/
static async getOnlineScoreAttributes<THasStrainChart extends boolean>(
scoreId: number,
uid: number,
hash: string,
mode: Modes.osu,
calculationMethod: PPCalculationMethod.live,
generateStrainChart?: THasStrainChart,
Expand All @@ -482,14 +488,16 @@ export abstract class DPPProcessorRESTManager extends RESTManager {
/**
* Gets the difficulty and performance attributes of a score.
*
* @param scoreId The ID of the score.
* @param uid The uid of the player in the score.
* @param hash The MD5 hash of the beatmap in the score.
* @param mode The gamemode to calculate.
* @param calculationMethod The calculation method to use.
* @param generateStrainChart Whether to generate a strain chart.
* @returns The difficulty and performance attributes, `null` if the attributes cannot be retrieved.
*/
static async getOnlineScoreAttributes<THasStrainChart extends boolean>(
scoreId: number,
uid: number,
hash: string,
mode: Modes.osu,
calculationMethod: PPCalculationMethod.rebalance,
generateStrainChart?: THasStrainChart,
Expand All @@ -502,7 +510,8 @@ export abstract class DPPProcessorRESTManager extends RESTManager {
> | null>;

static async getOnlineScoreAttributes<THasStrainChart extends boolean>(
scoreId: number,
uid: number,
hash: string,
mode: Modes,
calculationMethod: PPCalculationMethod,
generateStrainChart?: THasStrainChart,
Expand All @@ -516,7 +525,8 @@ export abstract class DPPProcessorRESTManager extends RESTManager {
const url = new URL(`${this.endpoint}get-online-score-attributes`);

url.searchParams.set("key", process.env.DROID_SERVER_INTERNAL_KEY!);
url.searchParams.set("scoreid", scoreId.toString());
url.searchParams.set("uid", uid.toString());
url.searchParams.set("hash", hash);
url.searchParams.set("gamemode", mode);
url.searchParams.set("calculationmethod", calculationMethod.toString());

Expand Down

0 comments on commit ca6af28

Please sign in to comment.