From 3bd45e2bf77fc5cfc78ef14b070484e180bc0f6c Mon Sep 17 00:00:00 2001 From: Stijn van der Kolk Date: Sun, 28 Jul 2024 13:29:03 +0100 Subject: [PATCH] feat: lower player limit for free servers, removed point interval set from setup --- src/commands/game/sub/addPlayer.ts | 12 ++++++++++-- src/commands/game/sub/setup.ts | 4 +--- src/interactions/commands/game.ts | 1 - src/util/SKU.ts | 6 ++++++ 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/util/SKU.ts diff --git a/src/commands/game/sub/addPlayer.ts b/src/commands/game/sub/addPlayer.ts index 89dd8e9..d5c8501 100644 --- a/src/commands/game/sub/addPlayer.ts +++ b/src/commands/game/sub/addPlayer.ts @@ -4,6 +4,7 @@ import { SubcommandFunction } from '../../../util/Command'; import { getGame, prisma } from '../../../util/prisma'; import { GameStatus } from '@prisma/client'; import { Util } from '../../../util/Util'; +import { isPremiumCheck } from '../../../util/SKU'; export const gameAddPlayerSubCommand: SubcommandFunction< (typeof GameCommand)['options']['add-player'] @@ -18,6 +19,10 @@ export const gameAddPlayerSubCommand: SubcommandFunction< content: 'This command can only be used in a forum post.', }); + const isPremium = interaction.entitlements.some((sku) => + isPremiumCheck(sku.skuId) + ); + const game = await getGame( interaction.channel.parent.id, interaction.channelId, @@ -41,9 +46,12 @@ export const gameAddPlayerSubCommand: SubcommandFunction< }); } - if (game.players.length === 20) { + // game limit for premium is 20, non-premium is 10 + if (game.players.length === (isPremium ? 20 : 10)) { return respond(interaction, { - content: 'This game is full, there can be no more than 20 players.', + content: `This game is full, there can be no more than ${ + isPremium ? 20 : 10 + } players.`, }); } diff --git a/src/commands/game/sub/setup.ts b/src/commands/game/sub/setup.ts index 7afa9d3..828576a 100644 --- a/src/commands/game/sub/setup.ts +++ b/src/commands/game/sub/setup.ts @@ -73,14 +73,12 @@ export const gameSetupSubCommand: SubcommandFunction< }, }); - const pointInterval = args['point-interval'] * 60e3; - const game = await prisma.game.createSetupGame({ guildId: interaction.guildId, channelId: tankTacticsChannel.id, threadId: forumThread.id, createdById: interaction.user.id, - pointInterval, + pointInterval: 10 * 60 * 1_000, type, }); diff --git a/src/interactions/commands/game.ts b/src/interactions/commands/game.ts index d331583..d6e2516 100644 --- a/src/interactions/commands/game.ts +++ b/src/interactions/commands/game.ts @@ -69,7 +69,6 @@ export const GameCommand = { description: 'Set up a game', options: { type: GameTypeOption, - 'point-interval': PointIntervalOption, }, }, 'add-player': { diff --git a/src/util/SKU.ts b/src/util/SKU.ts new file mode 100644 index 0000000..2948597 --- /dev/null +++ b/src/util/SKU.ts @@ -0,0 +1,6 @@ +const premiumSkus = process.env.SKU_IDS_PREMIUM?.split(','); + +export const isPremiumCheck = (skuId: string) => { + if (!premiumSkus) return true; + return premiumSkus.includes(skuId); +};