From fc420b79d04da350c5c453bf332956c31b12b8b8 Mon Sep 17 00:00:00 2001 From: TheCodedProf Date: Tue, 24 Jan 2023 17:14:38 -0500 Subject: [PATCH] edited premium --- src/commands/nucleus/premium.ts | 58 +++++++++++++++++++++++++++---- src/commands/settings/oldStats.ts | 2 +- src/index.ts | 5 ++- src/utils/database.ts | 6 +++- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/commands/nucleus/premium.ts b/src/commands/nucleus/premium.ts index 74d7da8..8b47ab7 100644 --- a/src/commands/nucleus/premium.ts +++ b/src/commands/nucleus/premium.ts @@ -42,14 +42,20 @@ const callback = async (interaction: CommandInteraction): Promise => { count = 3; } - const closed = false; + const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id); + let premiumGuild = "" + if (hasPremium) { + premiumGuild = `\n\n**This server has premium!**` + } + + let closed = false; do { interaction.editReply({ embeds: [ new EmojiEmbed() .setTitle("Premium") .setDescription( - premium + firstDescription + premium + firstDescription + premiumGuild ) .setEmoji("NUCLEUS.LOGO") .setStatus("Danger") @@ -61,15 +67,55 @@ const callback = async (interaction: CommandInteraction): Promise => { .setStyle(ButtonStyle.Primary) .setLabel("Activate Premium here") .setCustomId("premiumActivate") - .setDisabled(count <= 0) + .setDisabled(count <= 0 && hasPremium) ) ] }); const filter = (i: any) => i.customId === "premiumActivate" && i.user.id === interaction.user.id; - const collector = interaction.channel?.awaitMessageComponent({ filter, time: 60000 }); - - } while (closed); + let i; + try { + i = await interaction.channel!.awaitMessageComponent({ filter, time: 60000 }); + } catch (e) { + return; + } + if (i) { + i.deferUpdate(); + let guild = i.guild!; + let m = await client.database.premium.fetchTotal(interaction.user.id); + if (count - m <= 0) { + interaction.editReply({ + embeds: [ + new EmojiEmbed() + .setTitle("Premium") + .setDescription( + `You have already activated premium on the maximum amount of servers!` + firstDescription + ) + .setEmoji("NUCLEUS.LOGO") + .setStatus("Danger") + ], + components: [] + }); + closed = true; + } else { + client.database.premium.addPremium(interaction.user.id, guild.id); + interaction.editReply({ + embeds: [ + new EmojiEmbed() + .setTitle("Premium") + .setDescription( + `You have activated premium on this server!` + firstDescription + ) + .setEmoji("NUCLEUS.LOGO") + .setStatus("Danger") + ], + components: [] + }); + closed = true; + } + } + + } while (!closed); }; const check = () => { diff --git a/src/commands/settings/oldStats.ts b/src/commands/settings/oldStats.ts index 94b09a4..8f13109 100644 --- a/src/commands/settings/oldStats.ts +++ b/src/commands/settings/oldStats.ts @@ -12,7 +12,7 @@ import type { GuildConfig } from "../../utils/database.js"; const command = (builder: SlashCommandSubcommandBuilder) => builder - .setName("stats") + .setName("oldstats") .setDescription("Controls channels which update when someone joins or leaves the server") type ChangesType = Record diff --git a/src/index.ts b/src/index.ts index 362b805..a88cc54 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,4 +14,7 @@ process.on("uncaughtException", (err) => { console.error(err) }); await client.login(config.enableDevelopment ? config.developmentToken : config.token) -await recordPerformance(); \ No newline at end of file +await recordPerformance(); + +import { getCommandMentionByName} from "./utils/getCommandMentionByName.js"; +console.log(await getCommandMentionByName("nucleus/premium")) diff --git a/src/utils/database.ts b/src/utils/database.ts index 3d4ca78..10b0ddb 100644 --- a/src/utils/database.ts +++ b/src/utils/database.ts @@ -217,9 +217,13 @@ export class Premium { return entry.appliesTo.length; } - setPremium(user: string, guild: string) { + addPremium(user: string, guild: string) { return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true }); } + + removePremium(user: string, guild: string) { + return this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } }); + } } export interface GuildConfig {