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