TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 1 | import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction } 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 |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 11 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 12 | await interaction.reply({embeds: LoadingEmbed, ephemeral: true}) |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 13 | 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] | 14 | interaction.editReply({ embeds: [ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 15 | new EmojiEmbed() |
| 16 | .setTitle("Premium") |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 17 | .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] | 18 | .setEmoji("NUCLEUS.LOGO") |
| 19 | .setStatus("Danger") |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 20 | ], 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^] | 21 | }) |
| 22 | if (!member) return; |
| 23 | const firstDescription = "\n\nPremium allows servers of your choice to get access to extra features for a fixed price per month.\nThis includes:\n" + |
| 24 | `${getEmojiByName("MOD.IMAGES.TOOSMALL")} Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n` + |
| 25 | `${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] | 26 | const dbMember = await client.database.premium.fetchUser(interaction.user.id) |
| 27 | 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] | 28 | let count = 0; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 29 | const {level, appliesTo} = dbMember ?? {level: 0, appliesTo: []} |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 30 | if (level === 99) { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 31 | 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.`; |
| 32 | count = 200; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 33 | } else if (level === 1) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 34 | 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] | 35 | count = 1; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 36 | } else if (level === 2) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 37 | 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] | 38 | count = 3; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 39 | } else if (level === 3) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 40 | 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] | 41 | count = 3; |
| 42 | } |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 43 | if (dbMember?.expiresAt) { |
| 44 | 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` |
| 45 | count = 0; |
| 46 | } |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 47 | const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id); |
| 48 | let premiumGuild = "" |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 49 | if (hasPremium) { //FIXME: Check how user applied premium |
| 50 | premiumGuild = `**This server has premium! It was ${hasPremium[2] === 3 ? `automatically applied by <@${hasPremium[1]}>` : `given by <@${hasPremium[1]}>`}**\n\n` |
| 51 | } |
| 52 | |
| 53 | const components: ActionRowBuilder<ButtonBuilder>[] = [] |
| 54 | if (level === 0 || dbMember?.expiresAt) { |
| 55 | components.push( |
| 56 | new ActionRowBuilder<ButtonBuilder>() |
| 57 | .addComponents( |
| 58 | new ButtonBuilder() |
| 59 | .setStyle(ButtonStyle.Link) |
| 60 | .setLabel("Join Clicks") |
| 61 | .setURL("https://discord.gg/bPaNnxe") |
| 62 | ) |
| 63 | ) |
| 64 | } else { |
| 65 | components.push( |
| 66 | new ActionRowBuilder<ButtonBuilder>() |
| 67 | .addComponents( |
| 68 | new ButtonBuilder() |
| 69 | .setStyle(premiumGuild.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Success) |
| 70 | .setLabel(premiumGuild.length > 0 ? "This server has premium" : "Activate premium here") |
| 71 | .setCustomId("premiumActivate") |
| 72 | .setDisabled(count <= 0 || (hasPremium ? hasPremium[0] : false)) |
| 73 | ) |
| 74 | ) |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 75 | } |
| 76 | |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 77 | interaction.editReply({ |
| 78 | embeds: [ |
| 79 | new EmojiEmbed() |
| 80 | .setTitle("Premium") |
| 81 | .setDescription( |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 82 | premiumGuild + premium + firstDescription |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 83 | ) |
| 84 | .setEmoji("NUCLEUS.LOGO") |
| 85 | .setStatus("Danger") |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 86 | // .setImage("") //TODO: Add image |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 87 | ], |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 88 | components: components |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 89 | }); |
| 90 | |
| 91 | const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id; |
| 92 | let i; |
| 93 | try { |
| 94 | i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 }); |
| 95 | } catch (e) { |
| 96 | return; |
| 97 | } |
| 98 | i.deferUpdate(); |
| 99 | const guild = i.guild!; |
| 100 | if (count - appliesTo.length <= 0) { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 101 | interaction.editReply({ |
| 102 | embeds: [ |
| 103 | new EmojiEmbed() |
| 104 | .setTitle("Premium") |
| 105 | .setDescription( |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 106 | `You have already activated premium on the maximum amount of servers!` + firstDescription |
| 107 | ) |
| 108 | .setEmoji("NUCLEUS.PREMIUMACTIVATE") |
| 109 | .setStatus("Danger") |
| 110 | ], |
| 111 | components: [] |
| 112 | }); |
| 113 | } else { |
| 114 | client.database.premium.addPremium(interaction.user.id, guild.id); |
| 115 | interaction.editReply({ |
| 116 | embeds: [ |
| 117 | new EmojiEmbed() |
| 118 | .setTitle("Premium") |
| 119 | .setDescription( |
| 120 | `You have activated premium on this server!` + firstDescription |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 121 | ) |
| 122 | .setEmoji("NUCLEUS.LOGO") |
| 123 | .setStatus("Danger") |
| 124 | ], |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 125 | components: [] |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 126 | }); |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 127 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 128 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 129 | |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 130 | export { command }; |
| 131 | export { callback }; |