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