TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 1 | import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, StringSelectMenuBuilder } 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"; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 6 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 7 | import type { PremiumSchema } from "../../utils/database.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 8 | |
| 9 | const command = (builder: SlashCommandSubcommandBuilder) => |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 10 | builder.setName("premium").setDescription("Information about Nucleus Premium"); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 11 | //TODO: Allow User to remove Premium |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 12 | |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 13 | const dmcallback = async (interaction: CommandInteraction, dbUser: PremiumSchema | null, firstDescription: string): Promise<void> => { |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 14 | |
| 15 | if(!dbUser) { |
| 16 | await interaction.editReply({embeds: [ |
| 17 | new EmojiEmbed() |
| 18 | .setTitle("Premium") |
| 19 | .setDescription(`*You do not have premium! You can't activate premium on any servers.*` + firstDescription) |
| 20 | .setEmoji("NUCLEUS.LOGO") |
| 21 | .setStatus("Danger") |
| 22 | ]}); |
| 23 | return; |
| 24 | } |
| 25 | const premiumGuilds = dbUser.appliesTo.map((guildID) => { |
| 26 | const guild = client.guilds.cache.get(guildID); |
| 27 | if(!guild) return undefined; |
| 28 | return guild.name; |
| 29 | }); |
| 30 | |
| 31 | const options = premiumGuilds.filter((guild) => guild !== undefined) as string[]; |
| 32 | |
| 33 | const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>() |
| 34 | .addComponents( |
| 35 | new StringSelectMenuBuilder() |
| 36 | .setCustomId("currentPremium") |
| 37 | .setPlaceholder("Select a server to remove premium from") |
| 38 | .setDisabled(premiumGuilds.length === 0) |
| 39 | .addOptions(options.map((guild) => { |
| 40 | return {label: guild, value: guild} |
| 41 | })) |
| 42 | ); |
| 43 | const removeButton = new ActionRowBuilder<ButtonBuilder>() |
| 44 | .addComponents( |
| 45 | new ButtonBuilder() |
| 46 | .setCustomId("removePremium") |
| 47 | .setLabel("Remove Premium") |
| 48 | .setStyle(ButtonStyle.Danger) |
| 49 | .setDisabled(premiumGuilds.length === 0) |
| 50 | ); |
| 51 | |
| 52 | await interaction.editReply( |
| 53 | { |
| 54 | embeds: [ |
| 55 | new EmojiEmbed() |
| 56 | .setTitle("Premium") |
| 57 | .setDescription(`*You have premium on the following servers:*` + firstDescription) |
| 58 | .setEmoji("NUCLEUS.LOGO") |
| 59 | .setStatus("Success") |
| 60 | ], |
| 61 | components: [removeRow, removeButton] |
| 62 | }); |
| 63 | |
| 64 | //TODO Finish this. |
| 65 | |
| 66 | |
| 67 | } |
| 68 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 69 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame^] | 70 | if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {}); |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 71 | await interaction.reply({embeds: LoadingEmbed, ephemeral: true}) |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 72 | const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id).catch(() => { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 73 | interaction.editReply({ embeds: [ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 74 | new EmojiEmbed() |
| 75 | .setTitle("Premium") |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 76 | .setDescription(`*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] | 77 | .setEmoji("NUCLEUS.LOGO") |
| 78 | .setStatus("Danger") |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 79 | ], components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel("Join").setURL("https://discord.gg/bPaNnxe"))] }); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 80 | }) |
| 81 | if (!member) return; |
| 82 | const firstDescription = "\n\nPremium allows servers of your choice to get access to extra features for a fixed price per month.\nThis includes:\n" + |
| 83 | `${getEmojiByName("MOD.IMAGES.TOOSMALL")} Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n` + |
| 84 | `${getEmojiByName("GUILD.TICKET.ARCHIVED")} Ticket Transcripts - Gives a link to view the history of a ticket after it has been closed.\n` |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 85 | const dbMember = await client.database.premium.fetchUser(interaction.user.id) |
| 86 | 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] | 87 | let count = 0; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 88 | const {level, appliesTo} = dbMember ?? {level: 0, appliesTo: []} |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 89 | if (level === 99) { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 90 | 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.`; |
| 91 | count = 200; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 92 | } else if (level === 1) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 93 | premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more server(s).`; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 94 | count = 1; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 95 | } else if (level === 2) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 96 | premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more server(s).`; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 97 | count = 3; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 98 | } else if (level === 3) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 99 | premium = `You have Premium Mod! You can give premium to ${3 - appliesTo.length} more server(s), 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] | 100 | count = 3; |
| 101 | } |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 102 | if (dbMember?.expiresAt) { |
| 103 | premium = `**You can't give servers premium anymore because your subscription ended or was cancelled.** To get premium again please subscribe in the Clicks server` |
| 104 | count = 0; |
| 105 | } |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 106 | if(!interaction.guild) return await dmcallback(interaction, dbMember, firstDescription); |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 107 | const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id); |
| 108 | let premiumGuild = "" |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 109 | if (hasPremium) { |
| 110 | premiumGuild = `**This server has premium! It was ${hasPremium[2] === 3 && hasPremium[3] ? `automatically applied by <@${hasPremium[1]}>` : `given by <@${hasPremium[1]}>`}**\n\n` |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 111 | } |
| 112 | |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 113 | |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 114 | const components: ActionRowBuilder<ButtonBuilder>[] = [] |
| 115 | if (level === 0 || dbMember?.expiresAt) { |
| 116 | components.push( |
| 117 | new ActionRowBuilder<ButtonBuilder>() |
| 118 | .addComponents( |
| 119 | new ButtonBuilder() |
| 120 | .setStyle(ButtonStyle.Link) |
| 121 | .setLabel("Join Clicks") |
| 122 | .setURL("https://discord.gg/bPaNnxe") |
| 123 | ) |
| 124 | ) |
| 125 | } else { |
| 126 | components.push( |
| 127 | new ActionRowBuilder<ButtonBuilder>() |
| 128 | .addComponents( |
| 129 | new ButtonBuilder() |
| 130 | .setStyle(premiumGuild.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Success) |
| 131 | .setLabel(premiumGuild.length > 0 ? "This server has premium" : "Activate premium here") |
| 132 | .setCustomId("premiumActivate") |
| 133 | .setDisabled(count <= 0 || (hasPremium ? hasPremium[0] : false)) |
| 134 | ) |
| 135 | ) |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 136 | } |
| 137 | |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 138 | interaction.editReply({ |
| 139 | embeds: [ |
| 140 | new EmojiEmbed() |
| 141 | .setTitle("Premium") |
| 142 | .setDescription( |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 143 | premiumGuild + premium + firstDescription |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 144 | ) |
| 145 | .setEmoji("NUCLEUS.LOGO") |
| 146 | .setStatus("Danger") |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 147 | // .setImage("") //TODO: Add image |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 148 | ], |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 149 | components: components |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 150 | }); |
| 151 | |
| 152 | const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id; |
| 153 | let i; |
| 154 | try { |
| 155 | i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 }); |
| 156 | } catch (e) { |
| 157 | return; |
| 158 | } |
| 159 | i.deferUpdate(); |
| 160 | const guild = i.guild!; |
| 161 | if (count - appliesTo.length <= 0) { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 162 | interaction.editReply({ |
| 163 | embeds: [ |
| 164 | new EmojiEmbed() |
| 165 | .setTitle("Premium") |
| 166 | .setDescription( |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 167 | `You have already activated premium on the maximum amount of servers!` + firstDescription |
| 168 | ) |
| 169 | .setEmoji("NUCLEUS.PREMIUMACTIVATE") |
| 170 | .setStatus("Danger") |
| 171 | ], |
| 172 | components: [] |
| 173 | }); |
| 174 | } else { |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame^] | 175 | await client.database.premium.addPremium(interaction.user.id, guild.id); |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 176 | interaction.editReply({ |
| 177 | embeds: [ |
| 178 | new EmojiEmbed() |
| 179 | .setTitle("Premium") |
| 180 | .setDescription( |
| 181 | `You have activated premium on this server!` + firstDescription |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 182 | ) |
| 183 | .setEmoji("NUCLEUS.LOGO") |
| 184 | .setStatus("Danger") |
| 185 | ], |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 186 | components: [] |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 187 | }); |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 188 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 189 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 190 | |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 191 | export { command }; |
| 192 | export { callback }; |