Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1 | import { |
| 2 | ActionRowBuilder, |
| 3 | ButtonBuilder, |
| 4 | ButtonInteraction, |
| 5 | ButtonStyle, |
| 6 | CommandInteraction, |
| 7 | ComponentType, |
| 8 | Message, |
| 9 | StringSelectMenuBuilder, |
| 10 | StringSelectMenuInteraction |
| 11 | } from "discord.js"; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 12 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 13 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 14 | import client from "../../utils/client.js"; |
| 15 | import { LoadingEmbed } from "../../utils/defaults.js"; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 16 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 17 | |
| 18 | const command = (builder: SlashCommandSubcommandBuilder) => |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 19 | builder.setName("premium").setDescription("Information about Nucleus Premium"); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 20 | //TODO: Allow User to remove Premium |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 21 | |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 22 | const dmcallback = async (interaction: CommandInteraction, firstDescription: string, msg: Message): Promise<void> => { |
| 23 | let closed = false; |
| 24 | do { |
| 25 | const dbUser = await client.database.premium.fetchUser(interaction.user.id); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 26 | if (!dbUser) { |
| 27 | await interaction.editReply({ |
| 28 | embeds: [ |
| 29 | new EmojiEmbed() |
| 30 | .setTitle("Premium") |
| 31 | .setDescription( |
| 32 | `*You do not have premium! You can't activate premium on any servers.*` + firstDescription |
| 33 | ) |
| 34 | .setEmoji("NUCLEUS.LOGO") |
| 35 | .setStatus("Danger") |
| 36 | ] |
| 37 | }); |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 38 | return; |
| 39 | } |
| 40 | const premiumGuilds = dbUser.appliesTo.map((guildID) => { |
| 41 | const guild = client.guilds.cache.get(guildID); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 42 | if (!guild) return undefined; |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 43 | return guild.name; |
| 44 | }); |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 45 | |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 46 | const options = premiumGuilds.filter((guild) => guild !== undefined) as string[]; |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 47 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 48 | const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 49 | new StringSelectMenuBuilder() |
| 50 | .setCustomId("currentPremium") |
| 51 | .setPlaceholder("Select a server to remove premium from") |
| 52 | .setDisabled(premiumGuilds.length === 0) |
| 53 | .addOptions( |
| 54 | options.slice(0, Math.min(options.length, 24)).map((guild) => { |
| 55 | return { label: guild, value: guild }; |
| 56 | }) |
| 57 | ) |
| 58 | ); |
| 59 | const cancel = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 60 | new ButtonBuilder().setCustomId("cancel").setLabel("Close").setStyle(ButtonStyle.Danger) |
| 61 | ); |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 62 | |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 63 | const components: ActionRowBuilder<StringSelectMenuBuilder | ButtonBuilder>[] = [cancel]; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 64 | if (options.length > 0) components.unshift(removeRow); |
| 65 | await interaction.editReply({ |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 66 | embeds: [ |
| 67 | new EmojiEmbed() |
| 68 | .setTitle("Premium") |
| 69 | .setDescription( |
| 70 | `*You have premium on the following servers:*\n\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 71 | (options.length > 0 ? options.join(", ") : `You have not activated premium in any guilds`) + |
| 72 | firstDescription |
| 73 | ) |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 74 | .setEmoji("NUCLEUS.LOGO") |
| 75 | .setStatus("Success") |
| 76 | ], |
| 77 | components: components |
| 78 | }); |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 79 | |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 80 | let i: StringSelectMenuInteraction | ButtonInteraction; |
| 81 | try { |
| 82 | const filter = (i: StringSelectMenuInteraction | ButtonInteraction) => i.user.id === interaction.user.id; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 83 | i = await msg.awaitMessageComponent<ComponentType.StringSelect | ComponentType.Button>({ |
| 84 | time: 300000, |
| 85 | filter |
| 86 | }); |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 87 | } catch (e) { |
| 88 | await interaction.deleteReply(); |
| 89 | closed = true; |
| 90 | break; |
| 91 | } |
| 92 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 93 | if (i.isButton()) { |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 94 | closed = true; |
| 95 | } else { |
TheCodedProf | 48865eb | 2023-03-05 15:25:25 -0500 | [diff] [blame] | 96 | const response = await client.database.premium.removePremium(interaction.user.id, i.values[0]!); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 97 | console.log(response); |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 98 | } |
| 99 | } while (!closed); |
| 100 | await interaction.deleteReply(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 101 | }; |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 102 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 103 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 104 | if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {}); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 105 | const m = await interaction.reply({ embeds: LoadingEmbed, ephemeral: true, fetchReply: true }); |
| 106 | const member = await (await interaction.client.guilds.fetch("684492926528651336")).members |
| 107 | .fetch(interaction.user.id) |
| 108 | .catch(() => { |
| 109 | interaction.editReply({ |
| 110 | embeds: [ |
| 111 | new EmojiEmbed() |
| 112 | .setTitle("Premium") |
| 113 | .setDescription( |
| 114 | `*You are not currently in the Clicks Server. To gain access to premium please join.*` + |
| 115 | firstDescription |
| 116 | ) |
| 117 | .setEmoji("NUCLEUS.LOGO") |
| 118 | .setStatus("Danger") |
| 119 | ], |
| 120 | components: [ |
| 121 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 122 | new ButtonBuilder() |
| 123 | .setStyle(ButtonStyle.Link) |
| 124 | .setLabel("Join") |
| 125 | .setURL("https://discord.gg/bPaNnxe") |
| 126 | ) |
| 127 | ] |
| 128 | }); |
| 129 | }); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 130 | if (!member) return; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 131 | const firstDescription = |
| 132 | "\n\nPremium allows servers of your choice to get access to extra features for a fixed price per month.\nThis includes:\n" + |
| 133 | `${getEmojiByName( |
| 134 | "MOD.IMAGES.TOOSMALL" |
| 135 | )} Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n` + |
| 136 | `${getEmojiByName( |
| 137 | "GUILD.TICKET.ARCHIVED" |
| 138 | )} Ticket Transcripts - Gives a link to view the history of a ticket after it has been closed.\n`; |
| 139 | const dbMember = await client.database.premium.fetchUser(interaction.user.id); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 140 | 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] | 141 | let count = 0; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 142 | const { level, appliesTo } = dbMember ?? { level: 0, appliesTo: [] }; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 143 | if (level === 99) { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 144 | 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.`; |
| 145 | count = 200; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 146 | } else if (level === 1) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 147 | 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] | 148 | count = 1; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 149 | } else if (level === 2) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 150 | 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] | 151 | count = 3; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 152 | } else if (level === 3) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 153 | premium = `You have Premium Mod! You can give premium to ${ |
| 154 | 3 - appliesTo.length |
| 155 | } 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] | 156 | count = 3; |
| 157 | } |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 158 | if (dbMember?.expiresAt) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 159 | 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`; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 160 | count = 0; |
| 161 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 162 | if (!interaction.guild) return await dmcallback(interaction, firstDescription, m); |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 163 | const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 164 | let premiumGuild = ""; |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 165 | if (hasPremium) { |
TheCodedProf | 48865eb | 2023-03-05 15:25:25 -0500 | [diff] [blame] | 166 | const gaveUser = await client.users.fetch(hasPremium[1]); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 167 | premiumGuild = `**This server has premium! It was ${ |
| 168 | hasPremium[2] === 3 && hasPremium[3] |
TheCodedProf | 48865eb | 2023-03-05 15:25:25 -0500 | [diff] [blame] | 169 | ? `automatically applied by ${gaveUser.username}#${gaveUser.discriminator}` |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 170 | : `given by <@${hasPremium[1]}>` |
| 171 | }**\n\n`; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 172 | } |
| 173 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 174 | const components: ActionRowBuilder<ButtonBuilder>[] = []; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 175 | if (level === 0 || dbMember?.expiresAt) { |
| 176 | components.push( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 177 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 178 | new ButtonBuilder() |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 179 | .setStyle(ButtonStyle.Link) |
| 180 | .setLabel("Join Clicks") |
| 181 | .setURL("https://discord.gg/bPaNnxe") |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 182 | ) |
| 183 | ); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 184 | } else { |
| 185 | components.push( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 186 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 187 | new ButtonBuilder() |
| 188 | .setStyle(premiumGuild.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Success) |
| 189 | .setLabel(premiumGuild.length > 0 ? "This server has premium" : "Activate premium here") |
| 190 | .setCustomId("premiumActivate") |
| 191 | .setDisabled(count <= 0 || (hasPremium ? hasPremium[0] : false)) |
| 192 | ) |
| 193 | ); |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 194 | } |
| 195 | |
TheCodedProf | 48865eb | 2023-03-05 15:25:25 -0500 | [diff] [blame] | 196 | let userPremiumServers; |
| 197 | if ((dbMember?.appliesTo.length ?? 0) > 0) userPremiumServers = "\nIf you want to remove premium from a server, run this command in your DMs with me."; |
| 198 | |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 199 | interaction.editReply({ |
| 200 | embeds: [ |
| 201 | new EmojiEmbed() |
| 202 | .setTitle("Premium") |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 203 | .setDescription(premiumGuild + premium + firstDescription) |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 204 | .setEmoji("NUCLEUS.LOGO") |
| 205 | .setStatus("Danger") |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 206 | .setImage("https://assets.clicks.codes/ads/ads/nucleus-premium.png") |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 207 | ], |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 208 | components: components |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 209 | }); |
| 210 | |
| 211 | const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id; |
| 212 | let i; |
| 213 | try { |
| 214 | i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 }); |
| 215 | } catch (e) { |
| 216 | return; |
| 217 | } |
| 218 | i.deferUpdate(); |
| 219 | const guild = i.guild!; |
| 220 | if (count - appliesTo.length <= 0) { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 221 | interaction.editReply({ |
| 222 | embeds: [ |
| 223 | new EmojiEmbed() |
| 224 | .setTitle("Premium") |
| 225 | .setDescription( |
TheCodedProf | 48865eb | 2023-03-05 15:25:25 -0500 | [diff] [blame] | 226 | `You have already activated premium on the maximum amount of servers!` + userPremiumServers + firstDescription |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 227 | ) |
| 228 | .setEmoji("NUCLEUS.PREMIUMACTIVATE") |
| 229 | .setStatus("Danger") |
| 230 | ], |
| 231 | components: [] |
| 232 | }); |
| 233 | } else { |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 234 | await client.database.premium.addPremium(interaction.user.id, guild.id); |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 235 | interaction.editReply({ |
| 236 | embeds: [ |
| 237 | new EmojiEmbed() |
| 238 | .setTitle("Premium") |
TheCodedProf | 48865eb | 2023-03-05 15:25:25 -0500 | [diff] [blame] | 239 | .setDescription(`You have activated premium on this server!` + userPremiumServers + firstDescription) |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 240 | .setEmoji("NUCLEUS.LOGO") |
| 241 | .setStatus("Danger") |
| 242 | ], |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 243 | components: [] |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 244 | }); |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 245 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 246 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 247 | |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 248 | export { command }; |
| 249 | export { callback }; |