mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-06 13:58:05 +03:00
style: replace Playtypes[Game] with Playtype
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import db from "external/mongo/db";
|
||||
import { Game, integer, Playtypes, PublicUserDocument } from "tachi-common";
|
||||
import { Game, integer, Playtype, Playtypes, PublicUserDocument } from "tachi-common";
|
||||
import CreateLogCtx from "lib/logger/logger";
|
||||
import { CreateCalculatedData } from "lib/score-import/framework/calculated-data/calculated-data";
|
||||
import { UpdateUsersGamePlaytypeStats } from "lib/score-import/framework/user-game-stats/update-ugs";
|
||||
@@ -67,13 +67,13 @@ export async function RecalcAllScores(filter = {}) {
|
||||
logger.info(`Updating Profiles for ${modifiedUsers.size} users...`);
|
||||
|
||||
for (const userInfo of modifiedUsers.values()) {
|
||||
const [game, playtype, strUserID] = userInfo.split("-") as [Game, Playtypes[Game], string];
|
||||
const [game, playtype, strUserID] = userInfo.split("-") as [Game, Playtype, string];
|
||||
|
||||
const userID = Number(strUserID);
|
||||
|
||||
await UpdateUsersGamePlaytypeStats(
|
||||
game as Game,
|
||||
playtype as Playtypes[Game],
|
||||
playtype as Playtype,
|
||||
userID,
|
||||
null,
|
||||
logger
|
||||
|
||||
@@ -2,7 +2,7 @@ import db from "external/mongo/db";
|
||||
import { CreateGameSettings } from "lib/game-settings/create-game-settings";
|
||||
import CreateLogCtx from "lib/logger/logger";
|
||||
import { EmitWebhookEvent } from "lib/webhooks/webhooks";
|
||||
import { Game, IDStrings, integer, Playtypes, UserGameStats } from "tachi-common";
|
||||
import { Game, IDStrings, integer, Playtype, UserGameStats } from "tachi-common";
|
||||
import { GameClassSets } from "tachi-common/js/game-classes";
|
||||
|
||||
const logger = CreateLogCtx(__filename);
|
||||
@@ -35,7 +35,7 @@ export function ReturnClassIfGreater(
|
||||
export async function UpdateClassIfGreater(
|
||||
userID: integer,
|
||||
game: Game,
|
||||
playtype: Playtypes[Game],
|
||||
playtype: Playtype,
|
||||
classSet: GameClassSets[IDStrings],
|
||||
classVal: integer
|
||||
) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
FolderDocument,
|
||||
Playtypes,
|
||||
Game,
|
||||
Playtype,
|
||||
} from "tachi-common";
|
||||
import db from "external/mongo/db";
|
||||
import CreateLogCtx from "lib/logger/logger";
|
||||
@@ -264,19 +265,11 @@ export function GetGradeLampDistributionForFolders(userID: integer, folders: Fol
|
||||
return Promise.all(folders.map((f) => GetGradeLampDistributionForFolder(userID, f)));
|
||||
}
|
||||
|
||||
export function CreateFolderID(
|
||||
query: Record<string, unknown>,
|
||||
game: Game,
|
||||
playtype: Playtypes[Game]
|
||||
) {
|
||||
export function CreateFolderID(query: Record<string, unknown>, game: Game, playtype: Playtype) {
|
||||
return `F${fjsh.hash(Object.assign({ game, playtype }, query), "SHA256")}`;
|
||||
}
|
||||
|
||||
export async function GetRecentlyViewedFolders(
|
||||
userID: integer,
|
||||
game: Game,
|
||||
playtype: Playtypes[Game]
|
||||
) {
|
||||
export async function GetRecentlyViewedFolders(userID: integer, game: Game, playtype: Playtype) {
|
||||
const views = await db["recent-folder-views"].find(
|
||||
{
|
||||
userID,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { exec } from "child_process";
|
||||
import crypto from "crypto";
|
||||
import { ONE_HOUR } from "lib/constants/time";
|
||||
import { TachiConfig } from "lib/setup/config";
|
||||
import { Game, GamePTConfig, GetGameConfig, integer, Playtypes } from "tachi-common";
|
||||
import { Game, GamePTConfig, GetGameConfig, integer, Playtype, Playtypes } from "tachi-common";
|
||||
import { URL } from "url";
|
||||
|
||||
// https://github.com/sindresorhus/escape-string-regexp/blob/main/index.js
|
||||
@@ -68,8 +68,8 @@ export function IsValidGame(str: string): str is Game {
|
||||
return !!TachiConfig.GAMES.includes(str as Game);
|
||||
}
|
||||
|
||||
export function IsValidPlaytype(game: Game, str: string): str is Playtypes[Game] {
|
||||
return GetGameConfig(game).validPlaytypes.includes(str as Playtypes[Game]);
|
||||
export function IsValidPlaytype(game: Game, str: string): str is Playtype {
|
||||
return GetGameConfig(game).validPlaytypes.includes(str as Playtype);
|
||||
}
|
||||
|
||||
export function IsValidScoreAlg(
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
GPTSupportedVersions,
|
||||
IDStrings,
|
||||
integer,
|
||||
Playtype,
|
||||
Playtypes,
|
||||
} from "tachi-common";
|
||||
|
||||
@@ -69,7 +70,7 @@ export function FindChartWithPTDFVersion<
|
||||
export function FindDDRChartOnSongHash(
|
||||
songHash: string,
|
||||
// Technically both of these should be "ddr" instead of Game, but it proves hard to work with.
|
||||
playtype: Playtypes[Game],
|
||||
playtype: Playtype,
|
||||
difficulty: Difficulties[IDStrings]
|
||||
) {
|
||||
// note: this only works on accident because monk
|
||||
@@ -99,7 +100,7 @@ export function FindBMSChartOnHash(hash: string) {
|
||||
export function FindChartOnInGameID(
|
||||
game: Game,
|
||||
inGameID: number,
|
||||
playtype: Playtypes[Game],
|
||||
playtype: Playtype,
|
||||
difficulty: Difficulties[IDStrings]
|
||||
) {
|
||||
if (game === "bms" || game === "usc") {
|
||||
@@ -119,7 +120,7 @@ export function FindChartOnInGameID(
|
||||
*/
|
||||
export function FindIIDXChartOnInGameID(
|
||||
inGameID: number,
|
||||
playtype: Playtypes[Game],
|
||||
playtype: Playtype,
|
||||
difficulty: Difficulties[IDStrings]
|
||||
) {
|
||||
return db.charts.iidx.findOne({
|
||||
@@ -137,7 +138,7 @@ export function FindIIDXChartOnInGameID(
|
||||
*/
|
||||
export function FindIIDXChartOnInGameIDVersion(
|
||||
inGameID: number,
|
||||
playtype: Playtypes[Game],
|
||||
playtype: Playtype,
|
||||
difficulty: Difficulties[IDStrings],
|
||||
version: GPTSupportedVersions[IDStrings]
|
||||
) {
|
||||
@@ -156,7 +157,7 @@ export function FindIIDXChartOnInGameIDVersion(
|
||||
export function FindChartOnInGameIDVersion<I extends IDStrings = IDStrings>(
|
||||
game: Game,
|
||||
inGameID: number,
|
||||
playtype: Playtypes[Game],
|
||||
playtype: Playtype,
|
||||
difficulty: Difficulties[I],
|
||||
version: GPTSupportedVersions[I]
|
||||
) {
|
||||
@@ -243,7 +244,7 @@ export function FindChartOnSHA256(game: Game, hash: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function FindChartOnSHA256Playtype(game: Game, hash: string, playtype: Playtypes[Game]) {
|
||||
export function FindChartOnSHA256Playtype(game: Game, hash: string, playtype: Playtype) {
|
||||
if (game !== "bms" && game !== "usc" && game !== "iidx" && game !== "pms") {
|
||||
throw new Error(`Cannot call FindChartOnSHA256 for game ${game}.`);
|
||||
}
|
||||
@@ -267,7 +268,7 @@ export function FindChartOnARCID(game: "iidx" | "ddr" | "jubeat" | "sdvx", arcID
|
||||
*/
|
||||
export async function FindChartsOnPopularity(
|
||||
game: Game,
|
||||
playtype: Playtypes[Game],
|
||||
playtype: Playtype,
|
||||
songIDs?: integer[],
|
||||
skip = 0,
|
||||
limit = 100,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import db from "external/mongo/db";
|
||||
import { ONE_HOUR } from "lib/constants/time";
|
||||
import NodeCache from "node-cache";
|
||||
import { Game, gameClasses, IDStrings, integer, Playtypes } from "tachi-common";
|
||||
import { Game, gameClasses, IDStrings, integer, Playtype, Playtypes } from "tachi-common";
|
||||
|
||||
const classDistCache = new NodeCache();
|
||||
|
||||
export async function GetClassDistribution(
|
||||
game: Game,
|
||||
playtype: Playtypes[Game],
|
||||
playtype: Playtype,
|
||||
className: gameClasses.GameClassSets[IDStrings]
|
||||
) {
|
||||
const cacheKey = `${game}:${playtype}:${className}`;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import db from "external/mongo/db";
|
||||
import { integer, Game, Playtypes } from "tachi-common";
|
||||
import { integer, Game, Playtypes, Playtype } from "tachi-common";
|
||||
import { UpdateAllPBs } from "utils/calculations/recalc-scores";
|
||||
|
||||
/**
|
||||
@@ -10,7 +10,7 @@ import { UpdateAllPBs } from "utils/calculations/recalc-scores";
|
||||
export default async function DestroyUserGamePlaytypeData(
|
||||
userID: integer,
|
||||
game: Game,
|
||||
playtype: Playtypes[Game]
|
||||
playtype: Playtype
|
||||
) {
|
||||
await db["game-stats-snapshots"].remove({
|
||||
userID,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Game, GamePTConfig, GetGamePTConfig, Playtypes } from "tachi-common";
|
||||
import { Game, GamePTConfig, GetGamePTConfig, Playtype, Playtypes } from "tachi-common";
|
||||
import { IsString } from "./misc";
|
||||
|
||||
const isIntegerRegex = /^-?\d+$/u;
|
||||
@@ -47,7 +47,7 @@ export type ProfileRatingAlgs = GamePTConfig["defaultProfileRatingAlg"];
|
||||
export type ScoreRatingAlgs = GamePTConfig["defaultScoreRatingAlg"];
|
||||
export type SessionRatingAlgs = GamePTConfig["defaultSessionRatingAlg"];
|
||||
|
||||
export function CheckStrProfileAlg(game: Game, playtype: Playtypes[Game], strVal: string) {
|
||||
export function CheckStrProfileAlg(game: Game, playtype: Playtype, strVal: string) {
|
||||
const gptConfig = GetGamePTConfig(game, playtype);
|
||||
|
||||
// @hack
|
||||
@@ -58,7 +58,7 @@ export function CheckStrProfileAlg(game: Game, playtype: Playtypes[Game], strVal
|
||||
return strVal as ProfileRatingAlgs;
|
||||
}
|
||||
|
||||
export function CheckStrScoreAlg(game: Game, playtype: Playtypes[Game], strVal: string) {
|
||||
export function CheckStrScoreAlg(game: Game, playtype: Playtype, strVal: string) {
|
||||
const gptConfig = GetGamePTConfig(game, playtype);
|
||||
|
||||
// @hack
|
||||
@@ -69,7 +69,7 @@ export function CheckStrScoreAlg(game: Game, playtype: Playtypes[Game], strVal:
|
||||
return strVal as ScoreRatingAlgs;
|
||||
}
|
||||
|
||||
export function CheckStrSessionAlg(game: Game, playtype: Playtypes[Game], strVal: string) {
|
||||
export function CheckStrSessionAlg(game: Game, playtype: Playtype, strVal: string) {
|
||||
const gptConfig = GetGamePTConfig(game, playtype);
|
||||
|
||||
// @hack
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
PublicUserDocument,
|
||||
UserGameStats,
|
||||
Game,
|
||||
Playtypes,
|
||||
Playtype,
|
||||
SongDocument,
|
||||
UserSettings,
|
||||
TachiAPIClientDocument,
|
||||
@@ -61,7 +61,7 @@ export interface TachiRequestData {
|
||||
requestedUser?: PublicUserDocument;
|
||||
requestedUserGameStats?: UserGameStats;
|
||||
game?: Game;
|
||||
playtype?: Playtypes[Game];
|
||||
playtype?: Playtype;
|
||||
|
||||
chartDoc?: ChartDocument;
|
||||
songDoc?: SongDocument;
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
GetGamePTConfig,
|
||||
IDStrings,
|
||||
integer,
|
||||
Playtypes,
|
||||
Playtype,
|
||||
PublicUserDocument,
|
||||
UGSRatingsLookup,
|
||||
UserGameStats,
|
||||
@@ -171,7 +171,7 @@ export async function GetUsersRanking(stats: UserGameStats) {
|
||||
return (aggRes[0].ranking + 1) as integer;
|
||||
}
|
||||
|
||||
export function GetUGPTPlaycount(userID: integer, game: Game, playtype: Playtypes[Game]) {
|
||||
export function GetUGPTPlaycount(userID: integer, game: Game, playtype: Playtype) {
|
||||
return db.scores.count({ userID, game, playtype });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user