blob: 58b51a9927d9993b95de5d99cd33fe2b29babcc1 [file] [log] [blame]
Skyler Greyda16adf2023-03-05 10:22:12 +00001import {
2 ActionRowBuilder,
3 ButtonBuilder,
4 ButtonInteraction,
5 ButtonStyle,
6 CommandInteraction,
7 ComponentType,
8 Message,
9 StringSelectMenuBuilder,
10 StringSelectMenuInteraction
11} from "discord.js";
TheCodedProff86ba092023-01-27 17:10:07 -050012import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan813bdf42022-07-24 10:39:10 +010013import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
TheCodedProf267563a2023-01-21 17:00:57 -050014import client from "../../utils/client.js";
15import { LoadingEmbed } from "../../utils/defaults.js";
TheCodedProf94ff6de2023-02-22 17:47:26 -050016import getEmojiByName from "../../utils/getEmojiByName.js";
pineafan813bdf42022-07-24 10:39:10 +010017
18const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Grey11236ba2022-08-08 21:13:33 +010019 builder.setName("premium").setDescription("Information about Nucleus Premium");
TheCodedProf94ff6de2023-02-22 17:47:26 -050020//TODO: Allow User to remove Premium
TheCodedProfaa3fe992023-02-25 21:53:09 -050021
TheCodedProf8d577fa2023-03-01 13:06:40 -050022const 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 Greyda16adf2023-03-05 10:22:12 +000026 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 });
TheCodedProf8d577fa2023-03-01 13:06:40 -050038 return;
39 }
40 const premiumGuilds = dbUser.appliesTo.map((guildID) => {
41 const guild = client.guilds.cache.get(guildID);
Skyler Greyda16adf2023-03-05 10:22:12 +000042 if (!guild) return undefined;
TheCodedProf8d577fa2023-03-01 13:06:40 -050043 return guild.name;
44 });
TheCodedProfaa3fe992023-02-25 21:53:09 -050045
TheCodedProf8d577fa2023-03-01 13:06:40 -050046 const options = premiumGuilds.filter((guild) => guild !== undefined) as string[];
TheCodedProfaa3fe992023-02-25 21:53:09 -050047
Skyler Greyda16adf2023-03-05 10:22:12 +000048 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 );
TheCodedProfaa3fe992023-02-25 21:53:09 -050062
TheCodedProf8d577fa2023-03-01 13:06:40 -050063 const components: ActionRowBuilder<StringSelectMenuBuilder | ButtonBuilder>[] = [cancel];
Skyler Greyda16adf2023-03-05 10:22:12 +000064 if (options.length > 0) components.unshift(removeRow);
65 await interaction.editReply({
TheCodedProf8d577fa2023-03-01 13:06:40 -050066 embeds: [
67 new EmojiEmbed()
68 .setTitle("Premium")
69 .setDescription(
70 `*You have premium on the following servers:*\n\n` +
Skyler Greyda16adf2023-03-05 10:22:12 +000071 (options.length > 0 ? options.join(", ") : `You have not activated premium in any guilds`) +
72 firstDescription
73 )
TheCodedProf8d577fa2023-03-01 13:06:40 -050074 .setEmoji("NUCLEUS.LOGO")
75 .setStatus("Success")
76 ],
77 components: components
78 });
TheCodedProfaa3fe992023-02-25 21:53:09 -050079
TheCodedProf8d577fa2023-03-01 13:06:40 -050080 let i: StringSelectMenuInteraction | ButtonInteraction;
81 try {
82 const filter = (i: StringSelectMenuInteraction | ButtonInteraction) => i.user.id === interaction.user.id;
Skyler Greyda16adf2023-03-05 10:22:12 +000083 i = await msg.awaitMessageComponent<ComponentType.StringSelect | ComponentType.Button>({
84 time: 300000,
85 filter
86 });
TheCodedProf8d577fa2023-03-01 13:06:40 -050087 } catch (e) {
88 await interaction.deleteReply();
89 closed = true;
90 break;
91 }
92 await i.deferUpdate();
Skyler Greyda16adf2023-03-05 10:22:12 +000093 if (i.isButton()) {
TheCodedProf8d577fa2023-03-01 13:06:40 -050094 closed = true;
95 } else {
TheCodedProf48865eb2023-03-05 15:25:25 -050096 const response = await client.database.premium.removePremium(interaction.user.id, i.values[0]!);
Skyler Greyda16adf2023-03-05 10:22:12 +000097 console.log(response);
TheCodedProf8d577fa2023-03-01 13:06:40 -050098 }
99 } while (!closed);
100 await interaction.deleteReply();
Skyler Greyda16adf2023-03-05 10:22:12 +0000101};
TheCodedProfaa3fe992023-02-25 21:53:09 -0500102
pineafanbd02b4a2022-08-05 22:01:38 +0100103const callback = async (interaction: CommandInteraction): Promise<void> => {
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500104 if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {});
Skyler Greyda16adf2023-03-05 10:22:12 +0000105 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(() => {
109 interaction.editReply({
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 });
TheCodedProf94ff6de2023-02-22 17:47:26 -0500130 if (!member) return;
Skyler Greyda16adf2023-03-05 10:22:12 +0000131 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);
TheCodedProf633866f2023-02-03 17:06:00 -0500140 let premium = `You do not have premium! You can't activate premium on any servers.`;
TheCodedProf267563a2023-01-21 17:00:57 -0500141 let count = 0;
Skyler Greyda16adf2023-03-05 10:22:12 +0000142 const { level, appliesTo } = dbMember ?? { level: 0, appliesTo: [] };
TheCodedProf633866f2023-02-03 17:06:00 -0500143 if (level === 99) {
TheCodedProf267563a2023-01-21 17:00:57 -0500144 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;
TheCodedProf633866f2023-02-03 17:06:00 -0500146 } else if (level === 1) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500147 premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -0500148 count = 1;
TheCodedProf633866f2023-02-03 17:06:00 -0500149 } else if (level === 2) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500150 premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -0500151 count = 3;
TheCodedProf633866f2023-02-03 17:06:00 -0500152 } else if (level === 3) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000153 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.`;
TheCodedProf267563a2023-01-21 17:00:57 -0500156 count = 3;
157 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500158 if (dbMember?.expiresAt) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000159 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`;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500160 count = 0;
161 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000162 if (!interaction.guild) return await dmcallback(interaction, firstDescription, m);
TheCodedProffc420b72023-01-24 17:14:38 -0500163 const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
Skyler Greyda16adf2023-03-05 10:22:12 +0000164 let premiumGuild = "";
TheCodedProfaa3fe992023-02-25 21:53:09 -0500165 if (hasPremium) {
TheCodedProf48865eb2023-03-05 15:25:25 -0500166 const gaveUser = await client.users.fetch(hasPremium[1]);
Skyler Greyda16adf2023-03-05 10:22:12 +0000167 premiumGuild = `**This server has premium! It was ${
168 hasPremium[2] === 3 && hasPremium[3]
TheCodedProf48865eb2023-03-05 15:25:25 -0500169 ? `automatically applied by ${gaveUser.username}#${gaveUser.discriminator}`
Skyler Greyda16adf2023-03-05 10:22:12 +0000170 : `given by <@${hasPremium[1]}>`
171 }**\n\n`;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500172 }
173
Skyler Greyda16adf2023-03-05 10:22:12 +0000174 const components: ActionRowBuilder<ButtonBuilder>[] = [];
TheCodedProf94ff6de2023-02-22 17:47:26 -0500175 if (level === 0 || dbMember?.expiresAt) {
176 components.push(
Skyler Greyda16adf2023-03-05 10:22:12 +0000177 new ActionRowBuilder<ButtonBuilder>().addComponents(
178 new ButtonBuilder()
TheCodedProf94ff6de2023-02-22 17:47:26 -0500179 .setStyle(ButtonStyle.Link)
180 .setLabel("Join Clicks")
181 .setURL("https://discord.gg/bPaNnxe")
Skyler Greyda16adf2023-03-05 10:22:12 +0000182 )
183 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500184 } else {
185 components.push(
Skyler Greyda16adf2023-03-05 10:22:12 +0000186 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 );
TheCodedProffc420b72023-01-24 17:14:38 -0500194 }
195
Skyler Greya0c70242023-03-06 09:56:21 +0000196 let userPremiumServers = "";
TheCodedProf48865eb2023-03-05 15:25:25 -0500197 if ((dbMember?.appliesTo.length ?? 0) > 0) userPremiumServers = "\nIf you want to remove premium from a server, run this command in your DMs with me.";
198
TheCodedProf1807fb32023-02-20 14:33:48 -0500199 interaction.editReply({
200 embeds: [
201 new EmojiEmbed()
202 .setTitle("Premium")
Skyler Greyda16adf2023-03-05 10:22:12 +0000203 .setDescription(premiumGuild + premium + firstDescription)
TheCodedProf1807fb32023-02-20 14:33:48 -0500204 .setEmoji("NUCLEUS.LOGO")
205 .setStatus("Danger")
TheCodedProf8d577fa2023-03-01 13:06:40 -0500206 .setImage("https://assets.clicks.codes/ads/ads/nucleus-premium.png")
TheCodedProf1807fb32023-02-20 14:33:48 -0500207 ],
TheCodedProf94ff6de2023-02-22 17:47:26 -0500208 components: components
TheCodedProf1807fb32023-02-20 14:33:48 -0500209 });
210
211 const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id;
212 let i;
213 try {
214 i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 });
215 } catch (e) {
216 return;
217 }
218 i.deferUpdate();
219 const guild = i.guild!;
220 if (count - appliesTo.length <= 0) {
TheCodedProf267563a2023-01-21 17:00:57 -0500221 interaction.editReply({
222 embeds: [
223 new EmojiEmbed()
224 .setTitle("Premium")
225 .setDescription(
TheCodedProf48865eb2023-03-05 15:25:25 -0500226 `You have already activated premium on the maximum amount of servers!` + userPremiumServers + firstDescription
TheCodedProf1807fb32023-02-20 14:33:48 -0500227 )
228 .setEmoji("NUCLEUS.PREMIUMACTIVATE")
229 .setStatus("Danger")
230 ],
231 components: []
232 });
233 } else {
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500234 await client.database.premium.addPremium(interaction.user.id, guild.id);
TheCodedProf1807fb32023-02-20 14:33:48 -0500235 interaction.editReply({
236 embeds: [
237 new EmojiEmbed()
238 .setTitle("Premium")
TheCodedProf48865eb2023-03-05 15:25:25 -0500239 .setDescription(`You have activated premium on this server!` + userPremiumServers + firstDescription)
TheCodedProf267563a2023-01-21 17:00:57 -0500240 .setEmoji("NUCLEUS.LOGO")
241 .setStatus("Danger")
242 ],
TheCodedProf1807fb32023-02-20 14:33:48 -0500243 components: []
TheCodedProf267563a2023-01-21 17:00:57 -0500244 });
TheCodedProf1807fb32023-02-20 14:33:48 -0500245 }
pineafan63fc5e22022-08-04 22:04:10 +0100246};
pineafan813bdf42022-07-24 10:39:10 +0100247
pineafan813bdf42022-07-24 10:39:10 +0100248export { command };
249export { callback };