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(() => { |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame^] | 109 | void interaction.editReply({ |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 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 | |
Skyler Grey | a0c7024 | 2023-03-06 09:56:21 +0000 | [diff] [blame] | 196 | let userPremiumServers = ""; |
Skyler Grey | 6769176 | 2023-03-06 09:58:19 +0000 | [diff] [blame] | 197 | if ((dbMember?.appliesTo.length ?? 0) > 0) |
| 198 | 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] | 199 | |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame^] | 200 | await interaction.editReply({ |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 201 | embeds: [ |
| 202 | new EmojiEmbed() |
| 203 | .setTitle("Premium") |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 204 | .setDescription(premiumGuild + premium + firstDescription) |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 205 | .setEmoji("NUCLEUS.LOGO") |
| 206 | .setStatus("Danger") |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 207 | .setImage("https://assets.clicks.codes/ads/ads/nucleus-premium.png") |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 208 | ], |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 209 | components: components |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 210 | }); |
| 211 | |
| 212 | const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id; |
| 213 | let i; |
| 214 | try { |
| 215 | i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 }); |
| 216 | } catch (e) { |
| 217 | return; |
| 218 | } |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame^] | 219 | await i.deferUpdate(); |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 220 | const guild = i.guild!; |
| 221 | if (count - appliesTo.length <= 0) { |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame^] | 222 | await interaction.editReply({ |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 223 | embeds: [ |
| 224 | new EmojiEmbed() |
| 225 | .setTitle("Premium") |
| 226 | .setDescription( |
Skyler Grey | 6769176 | 2023-03-06 09:58:19 +0000 | [diff] [blame] | 227 | `You have already activated premium on the maximum amount of servers!` + |
| 228 | userPremiumServers + |
| 229 | firstDescription |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 230 | ) |
| 231 | .setEmoji("NUCLEUS.PREMIUMACTIVATE") |
| 232 | .setStatus("Danger") |
| 233 | ], |
| 234 | components: [] |
| 235 | }); |
| 236 | } else { |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 237 | await client.database.premium.addPremium(interaction.user.id, guild.id); |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame^] | 238 | await interaction.editReply({ |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 239 | embeds: [ |
| 240 | new EmojiEmbed() |
| 241 | .setTitle("Premium") |
Skyler Grey | 6769176 | 2023-03-06 09:58:19 +0000 | [diff] [blame] | 242 | .setDescription( |
| 243 | `You have activated premium on this server!` + userPremiumServers + firstDescription |
| 244 | ) |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 245 | .setEmoji("NUCLEUS.LOGO") |
| 246 | .setStatus("Danger") |
| 247 | ], |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 248 | components: [] |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 249 | }); |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 250 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 251 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 252 | |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 253 | export { command }; |
| 254 | export { callback }; |