From ce9567f2986e6258a116d627174c4c32f3c41f25 Mon Sep 17 00:00:00 2001 From: Jacob Koshy <42344274+jacobk999@users.noreply.github.com> Date: Sun, 18 Aug 2024 22:42:24 -0400 Subject: [PATCH] feat: consolidate /recentgames, /dropper, /partygames and /bridge (#684) --- apps/api/src/player/player.controller.ts | 18 -- apps/api/src/player/player.service.ts | 29 +--- .../src/commands/arcade/arcade.profile.tsx | 6 +- .../src/commands/arcade/dropper.command.tsx | 30 ---- .../src/commands/arcade/dropper.profile.tsx | 66 ------- .../commands/arcade/modes/dropper-maps.tsx | 70 -------- .../src/commands/arcade/modes/dropper.tsx | 101 +++++++++-- .../src/commands/arcade/modes/index.tsx | 1 - .../src/commands/arcade/modes/party-games.tsx | 134 ++++++++++---- .../commands/arcade/party-game.profile.tsx | 111 ------------ .../commands/arcade/party-games.command.tsx | 30 ---- .../src/commands/base.hypixel-command.ts | 7 +- .../commands/deprecated/bridge.command.tsx | 23 +++ .../daily.command.tsx | 0 .../commands/deprecated/dropper.command.tsx | 23 +++ .../historical.base.tsx | 0 .../lastDay.command.tsx | 0 .../lastMonth.command.tsx | 0 .../lastWeek.command.tsx | 0 .../monthly.command.tsx | 0 .../deprecated/recentgames.command.tsx | 22 +++ .../weekly.command.tsx | 0 .../yesterday.command.tsx | 0 .../src/commands/duels/bridge.command.tsx | 30 ---- .../src/commands/duels/bridge.profile.tsx | 94 ---------- .../src/commands/duels/duels.profile.tsx | 4 +- .../duels/tables/bridge-duels.table.tsx | 71 ++++---- .../commands/historical/session.command.tsx | 32 ++-- .../recentgames/recentgames.command.tsx | 71 -------- .../recentgames/recentgames.profile.tsx | 80 --------- .../src/commands/status/status.command.tsx | 6 +- .../src/commands/status/status.profile.tsx | 164 ++++++++++++------ .../{Historical-Exclude.tsx => Exclude.tsx} | 0 .../{Historical-Header.tsx => Header.tsx} | 0 .../src/components/Historical/Include.tsx | 19 ++ ...orical-Progression.tsx => Progression.tsx} | 2 +- .../src/components/Historical/index.ts | 10 +- apps/discord-bot/src/constants.ts | 18 +- locales/en-US/default.json | 11 +- locales/en-US/emojis.json | 4 + packages/api-client/src/api.service.ts | 11 -- packages/api-client/src/exceptions/index.ts | 1 - .../src/exceptions/recentgames.404.ts | 31 ---- .../src/responses/get.recentgames.response.ts | 16 -- packages/api-client/src/responses/index.ts | 1 - .../discord/src/command/command.context.ts | 6 +- packages/discord/src/services/api.service.ts | 35 ---- .../discord/src/services/paginate.service.ts | 4 +- packages/schemas/src/game/game.ts | 3 - packages/schemas/src/index.ts | 1 - .../src/player/gamemodes/arcade/index.ts | 34 ++-- .../src/player/gamemodes/duels/index.ts | 27 ++- packages/schemas/src/recentgames/index.ts | 26 --- packages/schemas/src/status/index.ts | 7 + .../recentgame.ts => status/recent-game.ts} | 0 55 files changed, 508 insertions(+), 982 deletions(-) delete mode 100644 apps/discord-bot/src/commands/arcade/dropper.command.tsx delete mode 100644 apps/discord-bot/src/commands/arcade/dropper.profile.tsx delete mode 100644 apps/discord-bot/src/commands/arcade/modes/dropper-maps.tsx delete mode 100644 apps/discord-bot/src/commands/arcade/party-game.profile.tsx delete mode 100644 apps/discord-bot/src/commands/arcade/party-games.command.tsx create mode 100644 apps/discord-bot/src/commands/deprecated/bridge.command.tsx rename apps/discord-bot/src/commands/{historical => deprecated}/daily.command.tsx (100%) create mode 100644 apps/discord-bot/src/commands/deprecated/dropper.command.tsx rename apps/discord-bot/src/commands/{historical => deprecated}/historical.base.tsx (100%) rename apps/discord-bot/src/commands/{historical => deprecated}/lastDay.command.tsx (100%) rename apps/discord-bot/src/commands/{historical => deprecated}/lastMonth.command.tsx (100%) rename apps/discord-bot/src/commands/{historical => deprecated}/lastWeek.command.tsx (100%) rename apps/discord-bot/src/commands/{historical => deprecated}/monthly.command.tsx (100%) create mode 100644 apps/discord-bot/src/commands/deprecated/recentgames.command.tsx rename apps/discord-bot/src/commands/{historical => deprecated}/weekly.command.tsx (100%) rename apps/discord-bot/src/commands/{historical => deprecated}/yesterday.command.tsx (100%) delete mode 100644 apps/discord-bot/src/commands/duels/bridge.command.tsx delete mode 100644 apps/discord-bot/src/commands/duels/bridge.profile.tsx delete mode 100644 apps/discord-bot/src/commands/recentgames/recentgames.command.tsx delete mode 100644 apps/discord-bot/src/commands/recentgames/recentgames.profile.tsx rename apps/discord-bot/src/components/Historical/{Historical-Exclude.tsx => Exclude.tsx} (100%) rename apps/discord-bot/src/components/Historical/{Historical-Header.tsx => Header.tsx} (100%) create mode 100644 apps/discord-bot/src/components/Historical/Include.tsx rename apps/discord-bot/src/components/Historical/{Historical-Progression.tsx => Progression.tsx} (96%) delete mode 100644 packages/api-client/src/exceptions/recentgames.404.ts delete mode 100644 packages/api-client/src/responses/get.recentgames.response.ts delete mode 100644 packages/schemas/src/recentgames/index.ts rename packages/schemas/src/{recentgames/recentgame.ts => status/recent-game.ts} (100%) diff --git a/apps/api/src/player/player.controller.ts b/apps/api/src/player/player.controller.ts index 9dbd4c86a..1d47e9524 100644 --- a/apps/api/src/player/player.controller.ts +++ b/apps/api/src/player/player.controller.ts @@ -20,10 +20,8 @@ import { DeletePlayerResponse, ErrorResponse, GetPlayerResponse, - GetRecentGamesResponse, GetStatusResponse, PlayerNotFoundException, - RecentGamesNotFoundException, StatusNotFoundException, } from "@statsify/api-client"; @@ -78,22 +76,6 @@ export class PlayerController { }; } - @ApiOperation({ summary: "Get the Recent Games of a Player" }) - @ApiOkResponse({ type: GetRecentGamesResponse }) - @ApiBadRequestResponse({ type: ErrorResponse }) - @ApiNotFoundResponse({ type: RecentGamesNotFoundException }) - @ApiNotFoundResponse({ type: PlayerNotFoundException }) - @Auth() - @Get("/recentgames") - public async getRecentGames(@Query() { player: tag }: PlayerDto) { - const recentGames = await this.playerService.getRecentGames(tag); - - return { - success: !!recentGames, - recentGames, - }; - } - @ApiOperation({ summary: "Get the Status of a Player" }) @ApiOkResponse({ type: GetStatusResponse }) @ApiBadRequestResponse({ type: ErrorResponse }) diff --git a/apps/api/src/player/player.service.ts b/apps/api/src/player/player.service.ts index 2bc4bf96e..d2ee45b35 100644 --- a/apps/api/src/player/player.service.ts +++ b/apps/api/src/player/player.service.ts @@ -9,8 +9,6 @@ import { type APIData, type Circular, type Flatten, flatten } from "@statsify/util"; import { CacheLevel, - PlayerNotFoundException, - RecentGamesNotFoundException, StatusNotFoundException, } from "@statsify/api-client"; import { HypixelService } from "#hypixel"; @@ -115,7 +113,10 @@ export class PlayerService { if (!player) throw new NotFoundException("player"); - const status = await this.hypixelService.getStatus(player.uuid); + const [status, games] = await Promise.all([ + this.hypixelService.getStatus(player.uuid), + this.hypixelService.getRecentGames(player.uuid), + ]); if (!status) throw new StatusNotFoundException(player); @@ -123,31 +124,11 @@ export class PlayerService { status.prefixName = player.prefixName; status.uuid = player.uuid; status.actions = player.status; + status.recentGames = games; return status; } - public async getRecentGames(tag: string) { - const player = await this.get(tag, CacheLevel.CACHE_ONLY, { - uuid: true, - displayName: true, - prefixName: true, - }); - - if (!player) throw new PlayerNotFoundException(); - - const games = await this.hypixelService.getRecentGames(player.uuid); - - if (!games || !games.length) throw new RecentGamesNotFoundException(player); - - return { - uuid: player.uuid, - displayName: player.displayName, - prefixName: player.prefixName, - games, - }; - } - /** * * @param tag UUID or Username of the player diff --git a/apps/discord-bot/src/commands/arcade/arcade.profile.tsx b/apps/discord-bot/src/commands/arcade/arcade.profile.tsx index b0c19e2e2..976db99ef 100644 --- a/apps/discord-bot/src/commands/arcade/arcade.profile.tsx +++ b/apps/discord-bot/src/commands/arcade/arcade.profile.tsx @@ -76,7 +76,7 @@ export const ArcadeProfile = ({ break; case "dropper": - table = ; + table = ; break; case "enderSpleef": @@ -112,7 +112,7 @@ export const ArcadeProfile = ({ break; case "partyGames": - table = ; + table = ; break; case "pixelPainters": @@ -149,7 +149,7 @@ export const ArcadeProfile = ({ sidebar={sidebar} title={`§l${FormattedGame.ARCADE} §f${ api === "overall" ? t("stats.wins") : "Stats" - } §r(${mode.formatted})`} + } §r(${mode.formatted}${mode.submode ? ` ${mode.submode.formatted}` : ""})`} time={time} /> {table} diff --git a/apps/discord-bot/src/commands/arcade/dropper.command.tsx b/apps/discord-bot/src/commands/arcade/dropper.command.tsx deleted file mode 100644 index 4b53c2890..000000000 --- a/apps/discord-bot/src/commands/arcade/dropper.command.tsx +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) Statsify - * - * This source code is licensed under the GNU GPL v3 license found in the - * LICENSE file in the root directory of this source tree. - * https://github.com/Statsify/statsify/blob/main/LICENSE - */ - -import { - BaseHypixelCommand, - BaseProfileProps, - ProfileData, -} from "#commands/base.hypixel-command"; -import { Command } from "@statsify/discord"; -import { DROPPER_MODES, DropperModes } from "@statsify/schemas"; -import { DropperProfile } from "./dropper.profile.js"; - -@Command({ description: (t) => t("commands.dropper") }) -export class DropperCommand extends BaseHypixelCommand { - public constructor() { - super(DROPPER_MODES); - } - - public getProfile( - base: BaseProfileProps, - { mode }: ProfileData - ): JSX.Element { - return ; - } -} diff --git a/apps/discord-bot/src/commands/arcade/dropper.profile.tsx b/apps/discord-bot/src/commands/arcade/dropper.profile.tsx deleted file mode 100644 index d15a9ddb3..000000000 --- a/apps/discord-bot/src/commands/arcade/dropper.profile.tsx +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) Statsify - * - * This source code is licensed under the GNU GPL v3 license found in the - * LICENSE file in the root directory of this source tree. - * https://github.com/Statsify/statsify/blob/main/LICENSE - */ - -/** - * Copyright (c) Statsify - * - * This source code is licensed under the GNU GPL v3 license found in the - * LICENSE file in the root directory of this source tree. - * https://github.com/Statsify/statsify/blob/main/LICENSE - */ - -import { Container, Footer, Header } from "#components"; -import { DropperMapsTable, DropperTable } from "./modes/index.js"; -import { DropperModes, FormattedGame, type GameMode } from "@statsify/schemas"; -import type { BaseProfileProps } from "#commands/base.hypixel-command"; - -export interface DropperProfileProps extends BaseProfileProps { - mode: GameMode; -} - -export const DropperProfile = ({ - skin, - player, - background, - logo, - user, - badge, - mode, - t, - time, -}: DropperProfileProps) => { - const { arcade } = player.stats; - - let table; - - switch (mode.api) { - case "overall": - table = ; - break; - case "bestTimes": - table = ; - break; - case "completions": - table = ; - break; - } - - return ( - -
- {table} -