TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 1 | import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction } from "discord.js"; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 2 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 3 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 4 | import client from "../../utils/client.js"; |
| 5 | import { LoadingEmbed } from "../../utils/defaults.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 6 | |
| 7 | const command = (builder: SlashCommandSubcommandBuilder) => |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 8 | builder.setName("premium").setDescription("Information about Nucleus Premium"); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 9 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 10 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 11 | await interaction.reply({embeds: LoadingEmbed, ephemeral: true}) |
TheCodedProf | d0a166d | 2023-02-19 00:04:53 -0500 | [diff] [blame] | 12 | const member = (await interaction.client.guilds.fetch("684492926528651336")).members.cache.get(interaction.user.id) |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 13 | const firstDescription = "\n\nPremium allows your server to get access to extra features, for a fixed price per month.\nThis includes:\n" + |
| 14 | "- Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n" + |
| 15 | "- Ticket Transcripts - Gives a link to view the history of a ticket after it has been closed.\n" |
| 16 | if(!member) { |
| 17 | interaction.editReply({ embeds: [ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 18 | new EmojiEmbed() |
| 19 | .setTitle("Premium") |
| 20 | .setDescription( |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 21 | `*You are not currently in the Clicks Server. To gain access to premium please join.*` + firstDescription |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 22 | ) |
| 23 | .setEmoji("NUCLEUS.LOGO") |
| 24 | .setStatus("Danger") |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 25 | ], components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel("Join").setURL("https://discord.gg/bPaNnxe"))] }); |
| 26 | return; |
| 27 | } |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 28 | const dbMember = await client.database.premium.fetchUser(interaction.user.id) |
| 29 | let premium = `You do not have premium! You can't activate premium on any servers.`; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 30 | let count = 0; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 31 | const {level, appliesTo} = dbMember ?? {level: 0, appliesTo: []} |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 32 | if (level === 99) { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 33 | premium = `You have Infinite Premium! You have been gifted this by the developers as a thank you. You can give premium to any and all servers you are in.`; |
| 34 | count = 200; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 35 | } else if (level === 1) { |
| 36 | premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more servers.`; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 37 | count = 1; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 38 | } else if (level === 2) { |
| 39 | premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more servers.`; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 40 | count = 3; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 41 | } else if (level === 3) { |
| 42 | premium = `You have Premium Mod! You can give premium to ${3 - appliesTo.length} more servers, as well as automatically giving premium to all servers you have a "manage" permission in.` |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 43 | count = 3; |
| 44 | } |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 45 | const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id); |
| 46 | let premiumGuild = "" |
| 47 | if (hasPremium) { |
| 48 | premiumGuild = `\n\n**This server has premium!**` |
| 49 | } |
| 50 | |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 51 | interaction.editReply({ |
| 52 | embeds: [ |
| 53 | new EmojiEmbed() |
| 54 | .setTitle("Premium") |
| 55 | .setDescription( |
| 56 | premium + firstDescription + premiumGuild |
| 57 | ) |
| 58 | .setEmoji("NUCLEUS.LOGO") |
| 59 | .setStatus("Danger") |
| 60 | ], |
| 61 | components: [ |
| 62 | new ActionRowBuilder<ButtonBuilder>() |
| 63 | .addComponents( |
| 64 | new ButtonBuilder() |
| 65 | .setStyle(ButtonStyle.Primary) |
| 66 | .setLabel("Activate Premium here") |
| 67 | .setCustomId("premiumActivate") |
| 68 | .setDisabled(count <= 0 && hasPremium) |
| 69 | ) |
| 70 | ] |
| 71 | }); |
| 72 | |
| 73 | const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id; |
| 74 | let i; |
| 75 | try { |
| 76 | i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 }); |
| 77 | } catch (e) { |
| 78 | return; |
| 79 | } |
| 80 | i.deferUpdate(); |
| 81 | const guild = i.guild!; |
| 82 | if (count - appliesTo.length <= 0) { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 83 | interaction.editReply({ |
| 84 | embeds: [ |
| 85 | new EmojiEmbed() |
| 86 | .setTitle("Premium") |
| 87 | .setDescription( |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 88 | `You have already activated premium on the maximum amount of servers!` + firstDescription |
| 89 | ) |
| 90 | .setEmoji("NUCLEUS.PREMIUMACTIVATE") |
| 91 | .setStatus("Danger") |
| 92 | ], |
| 93 | components: [] |
| 94 | }); |
| 95 | } else { |
| 96 | client.database.premium.addPremium(interaction.user.id, guild.id); |
| 97 | interaction.editReply({ |
| 98 | embeds: [ |
| 99 | new EmojiEmbed() |
| 100 | .setTitle("Premium") |
| 101 | .setDescription( |
| 102 | `You have activated premium on this server!` + firstDescription |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 103 | ) |
| 104 | .setEmoji("NUCLEUS.LOGO") |
| 105 | .setStatus("Danger") |
| 106 | ], |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 107 | components: [] |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 108 | }); |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 109 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 110 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 111 | |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 112 | export { command }; |
| 113 | export { callback }; |