From 0f9c0a3c6a89fb338def24f011bbcec1177844cc Mon Sep 17 00:00:00 2001 From: yoshman8 Date: Mon, 8 Sep 2025 16:11:53 +0100 Subject: [PATCH 1/3] remove scrabbledex filters --- src/database/games.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/database/games.ts b/src/database/games.ts index 1be2af0..12b95e2 100644 --- a/src/database/games.ts +++ b/src/database/games.ts @@ -117,9 +117,6 @@ export async function getScrabbleDex(): Promise { if (!IS_ENABLED.DB) return null; const scrabbleGames = await model.find({ game: GamesList.Scrabble, mod: [ScrabbleMods.CRAZYMONS, ScrabbleMods.POKEMON] }).lean(); return scrabbleGames - .filter(game => { - const time = Temporal.Instant.fromEpochMilliseconds(game.created.getTime()); - return instantInRange(time, [UGO_2025_START, UGO_2025_END]); }) .flatMap(game => { const baseCtx = { gameId: game.id, mod: game.mod! }; @@ -170,5 +167,5 @@ export async function getScrabbleDex(): Promise { }) .flat(); }) - .filter(entry => entry.won); + .filter(() => true); } From 5b18020e0d8750b58952b996daaa14465616270d Mon Sep 17 00:00:00 2001 From: yoshman8 Date: Mon, 8 Sep 2025 16:22:06 +0100 Subject: [PATCH 2/3] Update games.ts --- src/database/games.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/database/games.ts b/src/database/games.ts index 12b95e2..281171b 100644 --- a/src/database/games.ts +++ b/src/database/games.ts @@ -117,7 +117,6 @@ export async function getScrabbleDex(): Promise { if (!IS_ENABLED.DB) return null; const scrabbleGames = await model.find({ game: GamesList.Scrabble, mod: [ScrabbleMods.CRAZYMONS, ScrabbleMods.POKEMON] }).lean(); return scrabbleGames - }) .flatMap(game => { const baseCtx = { gameId: game.id, mod: game.mod! }; const winCtx = game.winCtx as ScrabbleWinCtx | undefined; From 61947f62829b973e4761f28532582db891a306cd Mon Sep 17 00:00:00 2001 From: PartMan Date: Mon, 8 Sep 2025 21:28:53 +0530 Subject: [PATCH 3/3] chore: Remove redundant filter from Scrabbledex --- src/database/games.ts | 101 ++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 53 deletions(-) diff --git a/src/database/games.ts b/src/database/games.ts index 281171b..cb6db47 100644 --- a/src/database/games.ts +++ b/src/database/games.ts @@ -1,12 +1,9 @@ -import { Temporal } from '@js-temporal/polyfill'; import mongoose, { type HydratedDocument } from 'mongoose'; import { pokedex } from 'ps-client/data'; import { IS_ENABLED } from '@/enabled'; import { ScrabbleMods } from '@/ps/games/scrabble/constants'; import { GamesList } from '@/ps/games/types'; -import { UGO_2025_END, UGO_2025_START } from '@/ps/ugo/constants'; -import { instantInRange } from '@/utils/timeInRange'; import { toId } from '@/utils/toId'; import type { Log as ScrabbleLog } from '@/ps/games/scrabble/logs'; @@ -116,55 +113,53 @@ export type ScrabbleDexEntry = { export async function getScrabbleDex(): Promise { if (!IS_ENABLED.DB) return null; const scrabbleGames = await model.find({ game: GamesList.Scrabble, mod: [ScrabbleMods.CRAZYMONS, ScrabbleMods.POKEMON] }).lean(); - return scrabbleGames - .flatMap(game => { - const baseCtx = { gameId: game.id, mod: game.mod! }; - const winCtx = game.winCtx as ScrabbleWinCtx | undefined; - const winners = winCtx?.type === 'win' ? winCtx.winnerIds : []; - const logs = game.log.map(log => JSON.parse(log)); - if (winCtx?.type === 'dq' || winCtx?.type === 'regular') { - const leftUsers = logs.filter(log => log.action === 'dq' || log.action === 'forfeit').map(log => log.turn); - if (winCtx.type === 'dq') - winners.push( - ...Object.values(game.players) - .map(player => player.turn) - .filter(player => !leftUsers.includes(player)) - ); - else if (winCtx.type === 'regular' && logs.filter(log => log.action === 'play').length > 20) { - const points: Record = {}; - logs.forEach(log => { - if (log.action === 'play') { - points[log.turn] ??= 0; - points[log.turn] += log.ctx.points.total; - } - }); - const players = Object.entries(points).filter(([player]) => !leftUsers.includes(player)); - const maxPoints = Math.max(...players.map(([_player, score]) => score)); - winners.push(...players.filter(([_player, score]) => score === maxPoints).map(([player]) => player)); - } + return scrabbleGames.flatMap(game => { + const baseCtx = { gameId: game.id, mod: game.mod! }; + const winCtx = game.winCtx as ScrabbleWinCtx | undefined; + const winners = winCtx?.type === 'win' ? winCtx.winnerIds : []; + const logs = game.log.map(log => JSON.parse(log)); + if (winCtx?.type === 'dq' || winCtx?.type === 'regular') { + const leftUsers = logs.filter(log => log.action === 'dq' || log.action === 'forfeit').map(log => log.turn); + if (winCtx.type === 'dq') + winners.push( + ...Object.values(game.players) + .map(player => player.turn) + .filter(player => !leftUsers.includes(player)) + ); + else if (winCtx.type === 'regular' && logs.filter(log => log.action === 'play').length > 20) { + const points: Record = {}; + logs.forEach(log => { + if (log.action === 'play') { + points[log.turn] ??= 0; + points[log.turn] += log.ctx.points.total; + } + }); + const players = Object.entries(points).filter(([player]) => !leftUsers.includes(player)); + const maxPoints = Math.max(...players.map(([_player, score]) => score)); + winners.push(...players.filter(([_player, score]) => score === maxPoints).map(([player]) => player)); } - return logs - .filterMap(log => { - if (log.action !== 'play') return; - const words = Object.keys(log.ctx.words).map(toId).unique(); - return words.filterMap(word => { - if (!(word in pokedex)) return; - let mon = pokedex[word]; - if (mon.baseSpecies) mon = pokedex[toId(mon.baseSpecies)]; - if (mon.num <= 0) return; - return { - ...baseCtx, - pokemon: word, - pokemonName: mon.name, - num: mon.num, - by: log.turn, - byName: game.players[log.turn]?.name ?? null, - at: log.time, - won: winners.includes(log.turn), - }; - }); - }) - .flat(); - }) - .filter(() => true); + } + return logs + .filterMap(log => { + if (log.action !== 'play') return; + const words = Object.keys(log.ctx.words).map(toId).unique(); + return words.filterMap(word => { + if (!(word in pokedex)) return; + let mon = pokedex[word]; + if (mon.baseSpecies) mon = pokedex[toId(mon.baseSpecies)]; + if (mon.num <= 0) return; + return { + ...baseCtx, + pokemon: word, + pokemonName: mon.name, + num: mon.num, + by: log.turn, + byName: game.players[log.turn]?.name ?? null, + at: log.time, + won: winners.includes(log.turn), + }; + }); + }) + .flat(); + }); }