From 535659a2b7606191e275f27aa53b9590682aaf33 Mon Sep 17 00:00:00 2001 From: Almeida Date: Sat, 4 Sep 2021 17:16:44 +0100 Subject: [PATCH] Fix max stickers and premium tier in !server (#258) --- .../Utility/functions/getServerInfoEmbed.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts index a0922399..91728e04 100644 --- a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts @@ -1,4 +1,4 @@ -import { MessageEmbedOptions, Snowflake } from "discord.js"; +import { MessageEmbedOptions, PremiumTier, Snowflake } from "discord.js"; import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; import moment from "moment-timezone"; @@ -19,6 +19,13 @@ import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { UtilityPluginType } from "../types"; import { getGuildPreview } from "./getGuildPreview"; +const PremiumTiers: Record = { + NONE: 0, + TIER_1: 1, + TIER_2: 2, + TIER_3: 3, +}; + export async function getServerInfoEmbed( pluginData: GuildPluginData, serverId: string, @@ -179,20 +186,22 @@ export async function getServerInfoEmbed( } if (restGuild) { + const premiumTierValue = PremiumTiers[restGuild.premiumTier]; + const maxEmojis = { 0: 50, 1: 100, 2: 150, 3: 250, - }[restGuild.premiumTier] || 50; + }[premiumTierValue] ?? 50; const maxStickers = { 0: 0, 1: 15, 2: 30, 3: 60, - }[restGuild.premiumTier] || 0; + }[premiumTierValue] ?? 0; otherStats.push(`Emojis: **${restGuild.emojis.cache.size}** / ${maxEmojis * 2}`); otherStats.push(`Stickers: **${restGuild.stickers.cache.size}** / ${maxStickers}`); @@ -202,7 +211,9 @@ export async function getServerInfoEmbed( } if (thisServer) { - otherStats.push(`Boosts: **${thisServer.premiumSubscriptionCount ?? 0}** (level ${thisServer.premiumTier})`); + otherStats.push( + `Boosts: **${thisServer.premiumSubscriptionCount ?? 0}** (level ${PremiumTiers[thisServer.premiumTier]})`, + ); } embed.fields.push({