Skip to content

Commit

Permalink
fix: cached stats not displaying correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kk committed Nov 8, 2023
1 parent bd1c38d commit 9e47dc4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/commands/stats/DailyBedwarsStatisticsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BedwarsStatisticsCommand extends CommandBase {
const bblrDifference = formatRatio((bedwars?.beds_broken_bedwars ?? 0) - (cachedBedwars?.beds_broken_bedwars ?? 0), (bedwars?.beds_lost_bedwars ?? 0) - (cachedBedwars?.beds_lost_bedwars ?? 0));
const wlrDifference = formatRatio(winsDifference, (bedwars?.losses_bedwars ?? 0) - (cachedBedwars?.losses_bedwars ?? 0));

const formattedString = `${star}\u272B FKDR: ${fkdrDifference} | BBLR: ${bblrDifference} | WLR: ${wlrDifference} | FK: ${formatNumber(finalsDifference)} | Wins: ${formatNumber(winsDifference)}`;
const formattedString = `${star}\u272B FKDR: ${fkdrDifference} | BBLR: ${bblrDifference} | WLR: ${wlrDifference} | FK: ${formatNumber(finalsDifference)} | Wins: ${formatNumber(winsDifference)} | Reset: ${new Date(cachedStats.resetAt).toDateString()}`;

this.send("bedwars", formattedString, playerStats);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/stats/MonthlyBedwarsStatisticsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BedwarsStatisticsCommand extends CommandBase {
const bblrDifference = formatRatio((bedwars?.beds_broken_bedwars ?? 0) - (cachedBedwars?.beds_broken_bedwars ?? 0), (bedwars?.beds_lost_bedwars ?? 0) - (cachedBedwars?.beds_lost_bedwars ?? 0));
const wlrDifference = formatRatio(winsDifference, (bedwars?.losses_bedwars ?? 0) - (cachedBedwars?.losses_bedwars ?? 0));

const formattedString = `${star}\u272B FKDR: ${fkdrDifference} | BBLR: ${bblrDifference} | WLR: ${wlrDifference} | FK: ${formatNumber(finalsDifference)} | Wins: ${formatNumber(winsDifference)}`;
const formattedString = `${star}\u272B FKDR: ${fkdrDifference} | BBLR: ${bblrDifference} | WLR: ${wlrDifference} | FK: ${formatNumber(finalsDifference)} | Wins: ${formatNumber(winsDifference)} | Reset: ${new Date(cachedStats.resetAt).toDateString()}`;

this.send("bedwars", formattedString, playerStats);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/stats/WeeklyBedwarsStatisticsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BedwarsStatisticsCommand extends CommandBase {
const bblrDifference = formatRatio((bedwars?.beds_broken_bedwars ?? 0) - (cachedBedwars?.beds_broken_bedwars ?? 0), (bedwars?.beds_lost_bedwars ?? 0) - (cachedBedwars?.beds_lost_bedwars ?? 0));
const wlrDifference = formatRatio(winsDifference, (bedwars?.losses_bedwars ?? 0) - (cachedBedwars?.losses_bedwars ?? 0));

const formattedString = `${star}\u272B FKDR: ${fkdrDifference} | BBLR: ${bblrDifference} | WLR: ${wlrDifference} | FK: ${formatNumber(finalsDifference)} | Wins: ${formatNumber(winsDifference)}`;
const formattedString = `${star}\u272B FKDR: ${fkdrDifference} | BBLR: ${bblrDifference} | WLR: ${wlrDifference} | FK: ${formatNumber(finalsDifference)} | Wins: ${formatNumber(winsDifference)} | Reset: ${new Date(cachedStats.resetAt).toDateString()}`;

this.send("bedwars", formattedString, playerStats);
}
Expand Down
7 changes: 5 additions & 2 deletions src/util/CommonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ export const getPlayerUuid = async (username: string) => {
}
};

export const formatRatio = (num1: number, num2: number) => {
const playerValue = num1 / num2;
export const formatRatio = (num1: number, num2?: number) => {
let playerValue = num1;
if (num2) {
playerValue = num1 / num2;
}
let displayValue: number | string = playerValue;
if (!isFinite(playerValue)) displayValue = ~~Number((((0 - 18) / 0) * 100).toFixed(2));
else if (!Number.isInteger(playerValue)) displayValue = playerValue.toFixed(2);
Expand Down
7 changes: 6 additions & 1 deletion src/util/SeraphCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export class SeraphCache {
}

const { data, status } = await axios.get(`https://cache.seraph.si/seraph/${mode}/${checkedUuid}`, { headers: { ...this.headers } });
return data.success && status == 200 ? (data.data as Components.Schemas.Player) : null;
if (data.success && status == 200) {
data.data.resetAt = data.resetsAt;
return data.data as Components.Schemas.Player & { resetAt: string };
} else {
return null;
}
};

public getGuildByPlayer = async (uuid: string) => {
Expand Down

0 comments on commit 9e47dc4

Please sign in to comment.