Skip to content

Commit

Permalink
fixes #165
Browse files Browse the repository at this point in the history
  • Loading branch information
YoruNoken committed Apr 9, 2024
1 parent 137b91f commit 1003457
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/cleaners/scores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ export async function getScore({ scores, beatmap: map_, index, mode, mapData }:
// Instead of rounding it down to 40, it would make more sense to round it to 41.
const drainSeconds = Math.ceil(drainLengthInSeconds % 60);

const objectshit = (scoreStatistics.count_300 ?? 0) + (scoreStatistics.count_100 ?? 0) + (scoreStatistics.count_50 ?? 0) + scoreStatistics.count_miss;
const objects = performance.mapValues.nCircles + performance.mapValues.nSliders + performance.mapValues.nSpinners;
const percentageNum = objectshit / objects * 100;
const objectsHit = (scoreStatistics.count_300 ?? 0) + (scoreStatistics.count_100 ?? 0) + (scoreStatistics.count_50 ?? 0) + scoreStatistics.count_miss;
const objects = performance.mapValues.nObjects;

const percentageNum = objectsHit / objects * 100;
const beatmapStatus = beatmapset.status;

return {
Expand Down
2 changes: 1 addition & 1 deletion src/commands-message/osu/recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function run({ message, args, commandName, index = 0, channel }: { message
initiatorId: message.author.id,
user: osuUser,
mode: user.mode,
userDb: user.userDb,
authorDb: user.authorDb,
plays,
index,
mods
Expand Down
2 changes: 1 addition & 1 deletion src/commands-message/osu/recentbest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function run({ message, args, commandName, index, channel }: { message: Me
mode: user.mode,
isMultiple: true,
sortByDate: true,
userDb: user.userDb,
authorDb: user.authorDb,
page,
isPage,
plays,
Expand Down
2 changes: 1 addition & 1 deletion src/commands-message/osu/recentlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function run({ message, args, commandName, index, channel }: { message: Me
user: osuUser,
mode: user.mode,
isMultiple: true,
userDb: user.userDb,
authorDb: user.authorDb,
page,
isPage,
index,
Expand Down
2 changes: 1 addition & 1 deletion src/commands-message/osu/top.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function run({ message, args, commandName, index, channel }: { message: Me
user: osuUser,
mode: user.mode,
isMultiple: true,
userDb: user.userDb,
authorDb: user.authorDb,
page,
isPage,
index,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/osu/recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function run(interaction: Interaction<ApplicationCommandData>): Promise<vo
user: osuUser,
mode: user.mode,
mods: { exclude: false, forceInclude: false, include: true, name: mod },
userDb: user.userDb,
authorDb: user.authorDb,
index,
plays
};
Expand Down
2 changes: 1 addition & 1 deletion src/commands/osu/recentbest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async function run(interaction: Interaction<ApplicationCommandData>): Promise<vo
mode: user.mode,
isMultiple: true,
sortByDate: true,
userDb: user.userDb,
authorDb: user.authorDb,
isPage,
page,
index,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/osu/recentlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async function run(interaction: Interaction<ApplicationCommandData>): Promise<vo
mode: user.mode,
isMultiple: true,
mods: { exclude: false, forceInclude: false, include: true, name: mod },
userDb: user.userDb,
authorDb: user.authorDb,
page,
index,
isPage,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/osu/top.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async function run(interaction: Interaction<ApplicationCommandData>): Promise<vo
user: osuUser,
mode: user.mode,
isMultiple: true,
userDb: user.userDb,
authorDb: user.authorDb,
plays,
page,
isPage,
Expand Down
24 changes: 12 additions & 12 deletions src/embed-builders/plays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function playBuilder({
mods,
isMultiple,
page,
userDb,
authorDb,
sortByDate
}: PlaysBuilderOptions): Promise<Array<EmbedStructure>> {
if (typeof page === "undefined" && typeof index === "undefined") {
Expand Down Expand Up @@ -63,20 +63,20 @@ export async function playBuilder({
] satisfies Array<EmbedStructure>;
}

return typeof page !== "undefined" ? getMultiplePlays({ plays, page, mode, profile, userDb }) : getSinglePlay({ mode, index: index ?? 0, plays, profile, userDb, isMultiple });
return typeof page !== "undefined" ? getMultiplePlays({ plays, page, mode, profile, authorDb }) : getSinglePlay({ mode, index: index ?? 0, plays, profile, authorDb, isMultiple });
}

async function getSinglePlay({ mode, index, plays, profile, userDb, isMultiple }:
async function getSinglePlay({ mode, index, plays, profile, authorDb, isMultiple }:
{
plays: Array<UserBestScore> | Array<UserScore>,
mode: Mode,
profile: ProfileInfo,
index: number,
userDb: DatabaseUser | null,
authorDb: DatabaseUser | null,
isMultiple?: boolean
}): Promise<Array<EmbedStructure>> {
const isMaximized = (userDb?.score_embeds ?? 1) === 1;
const embedType = userDb?.embed_type ?? EmbedScoreType.Hanami;
const isMaximized = (authorDb?.score_embeds ?? 1) === 1;
const embedType = authorDb?.embed_type ?? EmbedScoreType.Hanami;

const play = await getScore({ scores: plays, index, mode });
const { performance } = play;
Expand Down Expand Up @@ -133,7 +133,7 @@ async function getSinglePlay({ mode, index, plays, profile, userDb, isMultiple }
];

const fields = [
{ name: "Grade", value: `${play.grade} @${play.percentagePassed}%`, inline: true },
{ name: "Grade", value: `${play.grade} ${play.percentagePassed !== null ? `@${play.percentagePassed}%` : ""}`, inline: true },
{ name: "Score", value: play.score, inline: true },
{ name: "Acc", value: `${play.accuracy}%`, inline: true },
{ name: "PP", value: `${play.ppFormatted}`, inline: true },
Expand Down Expand Up @@ -176,7 +176,7 @@ async function getSinglePlay({ mode, index, plays, profile, userDb, isMultiple }
thumbnail: { url: play.listLink },
fields: [
{
name: `${play.grade} @${play.percentagePassed}% ${SPACE} ${play.score} ${SPACE} (${play.accuracy}%) ${SPACE} ${play.playSubmitted}`,
name: `${play.grade} ${play.percentagePassed !== null ? `@${play.percentagePassed}%` : ""} ${SPACE} ${play.score} ${SPACE} (${play.accuracy}%) ${SPACE} ${play.playSubmitted}`,
value: `${play.ppFormatted} [ ${play.comboValues} ] {${play.hitValues}}`
}
]
Expand All @@ -186,7 +186,7 @@ async function getSinglePlay({ mode, index, plays, profile, userDb, isMultiple }

// it's owo, so return owo embed.
const desc = [
`▸ ${play.grade} (${play.percentagePassed}%) ▸ **${performance.current.pp.toFixed(2).toLocaleString()}PP** ${play.ifFcOwo}${play.accuracy}%`,
`▸ ${play.grade} ${play.percentagePassed !== null ? `(${play.percentagePassed}%)` : ""} ▸ **${performance.current.pp.toFixed(2).toLocaleString()}PP** ${play.ifFcOwo}${play.accuracy}%`,
`▸ ${play.score}${play.comboValues} ▸ [${play.hitValues}]`
];

Expand All @@ -205,15 +205,15 @@ async function getSinglePlay({ mode, index, plays, profile, userDb, isMultiple }
];
}

async function getMultiplePlays({ plays, page, mode, profile, userDb }:
async function getMultiplePlays({ plays, page, mode, profile, authorDb }:
{
plays: Array<UserBestScore> | Array<UserScore>,
page: number,
mode: Mode,
profile: ProfileInfo,
userDb: DatabaseUser | null
authorDb: DatabaseUser | null
}): Promise<Array<EmbedStructure>> {
const embedType = userDb?.embed_type ?? EmbedScoreType.Hanami;
const embedType = authorDb?.embed_type ?? EmbedScoreType.Hanami;

const pageStart = page * 5;
const pageEnd = pageStart + 5;
Expand Down
3 changes: 2 additions & 1 deletion src/types/commandArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const enum UserType {

interface BaseUser {
type: UserType;
userDb: DatabaseUser | null;
authorDb: DatabaseUser | null;
playerDb?: DatabaseUser | null;
beatmapId: string | null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/embedBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface PlaysBuilderOptions extends BuilderOptions {
type: EmbedBuilderType.PLAYS;
user: UserExtended;
mode: Mode;
userDb: DatabaseUser | null;
authorDb: DatabaseUser | null;
index?: number;
isMultiple?: boolean;
sortByDate?: boolean;
Expand Down
18 changes: 9 additions & 9 deletions src/utils/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ export function getCommandArgs(interaction: Interaction<ApplicationCommandData>)

const user: User = discordUserId
? discordUser?.banchoId
? { type: UserType.SUCCESS, banchoId: discordUser.banchoId, userDb: discordUser, mode, beatmapId }
? { type: UserType.SUCCESS, banchoId: discordUser.banchoId, authorDb: userAuthor, mode, beatmapId }
: {
type: UserType.FAIL,
beatmapId,
userDb: discordUser,
authorDb: userAuthor,
failMessage: discordUserId ? `The user <@${discordUserId}> hasn't linked their account to the bot yet!` : `Please link your account to the bot using ${linkCommand()}!`
}
: userArg
? { type: UserType.SUCCESS, banchoId: userArg, mode, beatmapId, userDb: userAuthor }
? { type: UserType.SUCCESS, banchoId: userArg, mode, beatmapId, authorDb: userAuthor }
: userAuthor?.banchoId
? { type: UserType.SUCCESS, banchoId: userAuthor.banchoId, mode, beatmapId, userDb: userAuthor }
: { type: UserType.FAIL, beatmapId, userDb: userAuthor, failMessage: "Please link your account to the bot using /link!" };
? { type: UserType.SUCCESS, banchoId: userAuthor.banchoId, mode, beatmapId, authorDb: userAuthor }
: { type: UserType.FAIL, beatmapId, authorDb: userAuthor, failMessage: "Please link your account to the bot using /link!" };

return { user, mods };
}
Expand All @@ -130,7 +130,7 @@ export function parseOsuArguments(message: Message, args: Array<string>, mode: M
beatmapId: null,
type: UserType.FAIL,
failMessage: `Please link your account to the bot using ${linkCommand()}!`,
userDb: null
authorDb: null
},
flags: {},
mods: {
Expand Down Expand Up @@ -207,7 +207,7 @@ export function parseOsuArguments(message: Message, args: Array<string>, mode: M
beatmapId: result.user.beatmapId,
type: UserType.SUCCESS,
banchoId: userAuthor.banchoId,
userDb: userAuthor,
authorDb: userAuthor,
mode
};
} else if (result.tempUser) {
Expand All @@ -221,15 +221,15 @@ export function parseOsuArguments(message: Message, args: Array<string>, mode: M
result.user = {
beatmapId: result.user.beatmapId,
type: UserType.FAIL,
userDb: discordUser,
authorDb: userAuthor,
failMessage: `The user <@${discordUserId}> hasn't linked their account to the bot yet!`
};
} else {
result.user = {
beatmapId: result.user.beatmapId,
type: UserType.SUCCESS,
banchoId: discordId ?? userArg,
userDb: discordUser,
authorDb: userAuthor,
mode
};
}
Expand Down
7 changes: 7 additions & 0 deletions src/utils/initalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ export const messageCommands = new Map<string, DefaultMessageCommand>();
export const commandAliases = new Map<string, string>();
export const applicationCommands = new Map<string, DefaultSlashCommand>();

/**
* Loads all message commands from the `./src/commands-message` directory and adds them to the `messageCommands` and `commandAliases` maps.
*
* This function reads the contents of the `./src/commands-message` directory, imports each command module, and adds the command and its aliases to the respective maps.
*
* @returns {Promise<void>} A promise that resolves when all message commands have been loaded.
*/
export async function loadMessageCommands(): Promise<void> {
// Temporary array to store promises of MessageCommands
const temp: Array<Promise<DefaultMessageCommand>> = [];
Expand Down

0 comments on commit 1003457

Please sign in to comment.