blob: ed4f2259b7dc050c7b50e803be537c6f5bd5455a [file] [log] [blame]
TheCodedProfaa3fe992023-02-25 21:53:09 -05001import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, GuildMember, StringSelectMenuBuilder } from "discord.js";
TheCodedProff86ba092023-01-27 17:10:07 -05002import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan813bdf42022-07-24 10:39:10 +01003import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
TheCodedProf267563a2023-01-21 17:00:57 -05004import client from "../../utils/client.js";
5import { LoadingEmbed } from "../../utils/defaults.js";
TheCodedProf94ff6de2023-02-22 17:47:26 -05006import getEmojiByName from "../../utils/getEmojiByName.js";
TheCodedProfaa3fe992023-02-25 21:53:09 -05007import type { PremiumSchema } from "../../utils/database.js";
pineafan813bdf42022-07-24 10:39:10 +01008
9const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Grey11236ba2022-08-08 21:13:33 +010010 builder.setName("premium").setDescription("Information about Nucleus Premium");
TheCodedProf94ff6de2023-02-22 17:47:26 -050011//TODO: Allow User to remove Premium
TheCodedProfaa3fe992023-02-25 21:53:09 -050012
13const dmcallback = async (interaction: CommandInteraction, member: GuildMember, dbUser: PremiumSchema | null, firstDescription: string): Promise<void> => {
14
15 if(!dbUser) {
16 await interaction.editReply({embeds: [
17 new EmojiEmbed()
18 .setTitle("Premium")
19 .setDescription(`*You do not have premium! You can't activate premium on any servers.*` + firstDescription)
20 .setEmoji("NUCLEUS.LOGO")
21 .setStatus("Danger")
22 ]});
23 return;
24 }
25 const premiumGuilds = dbUser.appliesTo.map((guildID) => {
26 const guild = client.guilds.cache.get(guildID);
27 if(!guild) return undefined;
28 return guild.name;
29 });
30
31 const options = premiumGuilds.filter((guild) => guild !== undefined) as string[];
32
33 const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>()
34 .addComponents(
35 new StringSelectMenuBuilder()
36 .setCustomId("currentPremium")
37 .setPlaceholder("Select a server to remove premium from")
38 .setDisabled(premiumGuilds.length === 0)
39 .addOptions(options.map((guild) => {
40 return {label: guild, value: guild}
41 }))
42 );
43 const removeButton = new ActionRowBuilder<ButtonBuilder>()
44 .addComponents(
45 new ButtonBuilder()
46 .setCustomId("removePremium")
47 .setLabel("Remove Premium")
48 .setStyle(ButtonStyle.Danger)
49 .setDisabled(premiumGuilds.length === 0)
50 );
51
52 await interaction.editReply(
53 {
54 embeds: [
55 new EmojiEmbed()
56 .setTitle("Premium")
57 .setDescription(`*You have premium on the following servers:*` + firstDescription)
58 .setEmoji("NUCLEUS.LOGO")
59 .setStatus("Success")
60 ],
61 components: [removeRow, removeButton]
62 });
63
64 //TODO Finish this.
65
66
67}
68
pineafanbd02b4a2022-08-05 22:01:38 +010069const callback = async (interaction: CommandInteraction): Promise<void> => {
TheCodedProfaa3fe992023-02-25 21:53:09 -050070
TheCodedProf267563a2023-01-21 17:00:57 -050071 await interaction.reply({embeds: LoadingEmbed, ephemeral: true})
TheCodedProf94ff6de2023-02-22 17:47:26 -050072 const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id).catch(() => {
TheCodedProf267563a2023-01-21 17:00:57 -050073 interaction.editReply({ embeds: [
Skyler Grey75ea9172022-08-06 10:22:23 +010074 new EmojiEmbed()
75 .setTitle("Premium")
TheCodedProf94ff6de2023-02-22 17:47:26 -050076 .setDescription(`*You are not currently in the Clicks Server. To gain access to premium please join.*` + firstDescription)
Skyler Grey75ea9172022-08-06 10:22:23 +010077 .setEmoji("NUCLEUS.LOGO")
78 .setStatus("Danger")
TheCodedProf267563a2023-01-21 17:00:57 -050079 ], components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel("Join").setURL("https://discord.gg/bPaNnxe"))] });
TheCodedProf94ff6de2023-02-22 17:47:26 -050080 })
81 if (!member) return;
82 const firstDescription = "\n\nPremium allows servers of your choice to get access to extra features for a fixed price per month.\nThis includes:\n" +
83 `${getEmojiByName("MOD.IMAGES.TOOSMALL")} Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n` +
84 `${getEmojiByName("GUILD.TICKET.ARCHIVED")} Ticket Transcripts - Gives a link to view the history of a ticket after it has been closed.\n`
TheCodedProf633866f2023-02-03 17:06:00 -050085 const dbMember = await client.database.premium.fetchUser(interaction.user.id)
86 let premium = `You do not have premium! You can't activate premium on any servers.`;
TheCodedProf267563a2023-01-21 17:00:57 -050087 let count = 0;
TheCodedProf1807fb32023-02-20 14:33:48 -050088 const {level, appliesTo} = dbMember ?? {level: 0, appliesTo: []}
TheCodedProf633866f2023-02-03 17:06:00 -050089 if (level === 99) {
TheCodedProf267563a2023-01-21 17:00:57 -050090 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.`;
91 count = 200;
TheCodedProf633866f2023-02-03 17:06:00 -050092 } else if (level === 1) {
TheCodedProf94ff6de2023-02-22 17:47:26 -050093 premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -050094 count = 1;
TheCodedProf633866f2023-02-03 17:06:00 -050095 } else if (level === 2) {
TheCodedProf94ff6de2023-02-22 17:47:26 -050096 premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -050097 count = 3;
TheCodedProf633866f2023-02-03 17:06:00 -050098 } else if (level === 3) {
TheCodedProf94ff6de2023-02-22 17:47:26 -050099 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.`
TheCodedProf267563a2023-01-21 17:00:57 -0500100 count = 3;
101 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500102 if (dbMember?.expiresAt) {
103 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`
104 count = 0;
105 }
TheCodedProfaa3fe992023-02-25 21:53:09 -0500106 if(!interaction.guild) return await dmcallback(interaction, member, dbMember, firstDescription);
TheCodedProffc420b72023-01-24 17:14:38 -0500107 const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
108 let premiumGuild = ""
TheCodedProfaa3fe992023-02-25 21:53:09 -0500109 if (hasPremium) {
110 premiumGuild = `**This server has premium! It was ${hasPremium[2] === 3 && hasPremium[3] ? `automatically applied by <@${hasPremium[1]}>` : `given by <@${hasPremium[1]}>`}**\n\n`
TheCodedProf94ff6de2023-02-22 17:47:26 -0500111 }
112
TheCodedProfaa3fe992023-02-25 21:53:09 -0500113
TheCodedProf94ff6de2023-02-22 17:47:26 -0500114 const components: ActionRowBuilder<ButtonBuilder>[] = []
115 if (level === 0 || dbMember?.expiresAt) {
116 components.push(
117 new ActionRowBuilder<ButtonBuilder>()
118 .addComponents(
119 new ButtonBuilder()
120 .setStyle(ButtonStyle.Link)
121 .setLabel("Join Clicks")
122 .setURL("https://discord.gg/bPaNnxe")
123 )
124 )
125 } else {
126 components.push(
127 new ActionRowBuilder<ButtonBuilder>()
128 .addComponents(
129 new ButtonBuilder()
130 .setStyle(premiumGuild.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Success)
131 .setLabel(premiumGuild.length > 0 ? "This server has premium" : "Activate premium here")
132 .setCustomId("premiumActivate")
133 .setDisabled(count <= 0 || (hasPremium ? hasPremium[0] : false))
134 )
135 )
TheCodedProffc420b72023-01-24 17:14:38 -0500136 }
137
TheCodedProf1807fb32023-02-20 14:33:48 -0500138 interaction.editReply({
139 embeds: [
140 new EmojiEmbed()
141 .setTitle("Premium")
142 .setDescription(
TheCodedProf94ff6de2023-02-22 17:47:26 -0500143 premiumGuild + premium + firstDescription
TheCodedProf1807fb32023-02-20 14:33:48 -0500144 )
145 .setEmoji("NUCLEUS.LOGO")
146 .setStatus("Danger")
TheCodedProf94ff6de2023-02-22 17:47:26 -0500147 // .setImage("") //TODO: Add image
TheCodedProf1807fb32023-02-20 14:33:48 -0500148 ],
TheCodedProf94ff6de2023-02-22 17:47:26 -0500149 components: components
TheCodedProf1807fb32023-02-20 14:33:48 -0500150 });
151
152 const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id;
153 let i;
154 try {
155 i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 });
156 } catch (e) {
157 return;
158 }
159 i.deferUpdate();
160 const guild = i.guild!;
161 if (count - appliesTo.length <= 0) {
TheCodedProf267563a2023-01-21 17:00:57 -0500162 interaction.editReply({
163 embeds: [
164 new EmojiEmbed()
165 .setTitle("Premium")
166 .setDescription(
TheCodedProf1807fb32023-02-20 14:33:48 -0500167 `You have already activated premium on the maximum amount of servers!` + firstDescription
168 )
169 .setEmoji("NUCLEUS.PREMIUMACTIVATE")
170 .setStatus("Danger")
171 ],
172 components: []
173 });
174 } else {
175 client.database.premium.addPremium(interaction.user.id, guild.id);
176 interaction.editReply({
177 embeds: [
178 new EmojiEmbed()
179 .setTitle("Premium")
180 .setDescription(
181 `You have activated premium on this server!` + firstDescription
TheCodedProf267563a2023-01-21 17:00:57 -0500182 )
183 .setEmoji("NUCLEUS.LOGO")
184 .setStatus("Danger")
185 ],
TheCodedProf1807fb32023-02-20 14:33:48 -0500186 components: []
TheCodedProf267563a2023-01-21 17:00:57 -0500187 });
TheCodedProf1807fb32023-02-20 14:33:48 -0500188 }
pineafan63fc5e22022-08-04 22:04:10 +0100189};
pineafan813bdf42022-07-24 10:39:10 +0100190
pineafan813bdf42022-07-24 10:39:10 +0100191export { command };
192export { callback };