blob: 5fe6d88c6dfd708e54f9495bfbeecfba8b724d25 [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 );
TheCodedProfaa3fe992023-02-25 21:53:09 -050059
TheCodedProf920d7292023-06-05 11:02:32 -040060 const components: ActionRowBuilder<StringSelectMenuBuilder>[] = [];
Skyler Greyda16adf2023-03-05 10:22:12 +000061 if (options.length > 0) components.unshift(removeRow);
62 await interaction.editReply({
TheCodedProf8d577fa2023-03-01 13:06:40 -050063 embeds: [
64 new EmojiEmbed()
65 .setTitle("Premium")
66 .setDescription(
67 `*You have premium on the following servers:*\n\n` +
Skyler Greyda16adf2023-03-05 10:22:12 +000068 (options.length > 0 ? options.join(", ") : `You have not activated premium in any guilds`) +
69 firstDescription
70 )
TheCodedProf8d577fa2023-03-01 13:06:40 -050071 .setEmoji("NUCLEUS.LOGO")
72 .setStatus("Success")
73 ],
74 components: components
75 });
TheCodedProfaa3fe992023-02-25 21:53:09 -050076
TheCodedProf920d7292023-06-05 11:02:32 -040077 let i: StringSelectMenuInteraction;
TheCodedProf8d577fa2023-03-01 13:06:40 -050078 try {
TheCodedProf920d7292023-06-05 11:02:32 -040079 const filter = (i: StringSelectMenuInteraction) => i.user.id === interaction.user.id;
80 i = await msg.awaitMessageComponent<ComponentType.StringSelect>({
Skyler Greyda16adf2023-03-05 10:22:12 +000081 time: 300000,
82 filter
83 });
TheCodedProf8d577fa2023-03-01 13:06:40 -050084 } catch (e) {
85 await interaction.deleteReply();
86 closed = true;
TheCodedProf920d7292023-06-05 11:02:32 -040087 continue;
TheCodedProf8d577fa2023-03-01 13:06:40 -050088 }
89 await i.deferUpdate();
TheCodedProf920d7292023-06-05 11:02:32 -040090 await client.database.premium.removePremium(interaction.user.id, i.values[0]!);
TheCodedProf8d577fa2023-03-01 13:06:40 -050091 } while (!closed);
TheCodedProf920d7292023-06-05 11:02:32 -040092 await interaction.deleteReply()
Skyler Greyda16adf2023-03-05 10:22:12 +000093};
TheCodedProfaa3fe992023-02-25 21:53:09 -050094
pineafanbd02b4a2022-08-05 22:01:38 +010095const callback = async (interaction: CommandInteraction): Promise<void> => {
TheCodedProf9c51a7e2023-02-27 17:11:13 -050096 if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {});
Skyler Greyda16adf2023-03-05 10:22:12 +000097 const m = await interaction.reply({ embeds: LoadingEmbed, ephemeral: true, fetchReply: true });
98 const member = await (await interaction.client.guilds.fetch("684492926528651336")).members
99 .fetch(interaction.user.id)
100 .catch(() => {
Skyler Greyf4f21c42023-03-08 14:36:29 +0000101 void interaction.editReply({
Skyler Greyda16adf2023-03-05 10:22:12 +0000102 embeds: [
103 new EmojiEmbed()
104 .setTitle("Premium")
105 .setDescription(
106 `*You are not currently in the Clicks Server. To gain access to premium please join.*` +
107 firstDescription
108 )
109 .setEmoji("NUCLEUS.LOGO")
110 .setStatus("Danger")
111 ],
112 components: [
113 new ActionRowBuilder<ButtonBuilder>().addComponents(
114 new ButtonBuilder()
115 .setStyle(ButtonStyle.Link)
116 .setLabel("Join")
117 .setURL("https://discord.gg/bPaNnxe")
118 )
119 ]
120 });
121 });
TheCodedProf94ff6de2023-02-22 17:47:26 -0500122 if (!member) return;
Skyler Greyda16adf2023-03-05 10:22:12 +0000123 const firstDescription =
124 "\n\nPremium allows servers of your choice to get access to extra features for a fixed price per month.\nThis includes:\n" +
125 `${getEmojiByName(
126 "MOD.IMAGES.TOOSMALL"
127 )} Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n` +
128 `${getEmojiByName(
129 "GUILD.TICKET.ARCHIVED"
130 )} Ticket Transcripts - Gives a link to view the history of a ticket after it has been closed.\n`;
131 const dbMember = await client.database.premium.fetchUser(interaction.user.id);
TheCodedProf633866f2023-02-03 17:06:00 -0500132 let premium = `You do not have premium! You can't activate premium on any servers.`;
TheCodedProf267563a2023-01-21 17:00:57 -0500133 let count = 0;
Skyler Greyda16adf2023-03-05 10:22:12 +0000134 const { level, appliesTo } = dbMember ?? { level: 0, appliesTo: [] };
TheCodedProf633866f2023-02-03 17:06:00 -0500135 if (level === 99) {
TheCodedProf267563a2023-01-21 17:00:57 -0500136 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.`;
137 count = 200;
TheCodedProf633866f2023-02-03 17:06:00 -0500138 } else if (level === 1) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500139 premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -0500140 count = 1;
TheCodedProf633866f2023-02-03 17:06:00 -0500141 } else if (level === 2) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500142 premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -0500143 count = 3;
TheCodedProf633866f2023-02-03 17:06:00 -0500144 } else if (level === 3) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000145 premium = `You have Premium Mod! You can give premium to ${
146 3 - appliesTo.length
147 } more server(s), as well as automatically giving premium to all servers you have a "manage" permission in.`;
TheCodedProf267563a2023-01-21 17:00:57 -0500148 count = 3;
149 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500150 if (dbMember?.expiresAt) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000151 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 -0500152 count = 0;
153 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000154 if (!interaction.guild) return await dmcallback(interaction, firstDescription, m);
TheCodedProffc420b72023-01-24 17:14:38 -0500155 const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
Skyler Greyda16adf2023-03-05 10:22:12 +0000156 let premiumGuild = "";
TheCodedProfaa3fe992023-02-25 21:53:09 -0500157 if (hasPremium) {
TheCodedProf48865eb2023-03-05 15:25:25 -0500158 const gaveUser = await client.users.fetch(hasPremium[1]);
Skyler Greyda16adf2023-03-05 10:22:12 +0000159 premiumGuild = `**This server has premium! It was ${
160 hasPremium[2] === 3 && hasPremium[3]
Skyler Greyfda35b82023-05-29 18:42:47 +0200161 ? `automatically applied by ` +
162 (gaveUser.discriminator !== "0"
163 ? `${gaveUser.username}#${gaveUser.discriminator}`
164 : `@${gaveUser.username}`)
Skyler Greyda16adf2023-03-05 10:22:12 +0000165 : `given by <@${hasPremium[1]}>`
166 }**\n\n`;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500167 }
168
Skyler Greyda16adf2023-03-05 10:22:12 +0000169 const components: ActionRowBuilder<ButtonBuilder>[] = [];
TheCodedProf94ff6de2023-02-22 17:47:26 -0500170 if (level === 0 || dbMember?.expiresAt) {
171 components.push(
Skyler Greyda16adf2023-03-05 10:22:12 +0000172 new ActionRowBuilder<ButtonBuilder>().addComponents(
173 new ButtonBuilder()
TheCodedProf94ff6de2023-02-22 17:47:26 -0500174 .setStyle(ButtonStyle.Link)
175 .setLabel("Join Clicks")
176 .setURL("https://discord.gg/bPaNnxe")
Skyler Greyda16adf2023-03-05 10:22:12 +0000177 )
178 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500179 } else {
180 components.push(
Skyler Greyda16adf2023-03-05 10:22:12 +0000181 new ActionRowBuilder<ButtonBuilder>().addComponents(
182 new ButtonBuilder()
183 .setStyle(premiumGuild.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Success)
184 .setLabel(premiumGuild.length > 0 ? "This server has premium" : "Activate premium here")
185 .setCustomId("premiumActivate")
186 .setDisabled(count <= 0 || (hasPremium ? hasPremium[0] : false))
187 )
188 );
TheCodedProffc420b72023-01-24 17:14:38 -0500189 }
190
Skyler Greya0c70242023-03-06 09:56:21 +0000191 let userPremiumServers = "";
Skyler Grey67691762023-03-06 09:58:19 +0000192 if ((dbMember?.appliesTo.length ?? 0) > 0)
193 userPremiumServers = "\nIf you want to remove premium from a server, run this command in your DMs with me.";
TheCodedProf48865eb2023-03-05 15:25:25 -0500194
Skyler Greyf4f21c42023-03-08 14:36:29 +0000195 await interaction.editReply({
TheCodedProf1807fb32023-02-20 14:33:48 -0500196 embeds: [
197 new EmojiEmbed()
198 .setTitle("Premium")
Skyler Greyda16adf2023-03-05 10:22:12 +0000199 .setDescription(premiumGuild + premium + firstDescription)
TheCodedProf1807fb32023-02-20 14:33:48 -0500200 .setEmoji("NUCLEUS.LOGO")
201 .setStatus("Danger")
TheCodedProf8d577fa2023-03-01 13:06:40 -0500202 .setImage("https://assets.clicks.codes/ads/ads/nucleus-premium.png")
TheCodedProf1807fb32023-02-20 14:33:48 -0500203 ],
TheCodedProf94ff6de2023-02-22 17:47:26 -0500204 components: components
TheCodedProf1807fb32023-02-20 14:33:48 -0500205 });
206
207 const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id;
208 let i;
209 try {
210 i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 });
211 } catch (e) {
212 return;
213 }
Skyler Greyf4f21c42023-03-08 14:36:29 +0000214 await i.deferUpdate();
TheCodedProf1807fb32023-02-20 14:33:48 -0500215 const guild = i.guild!;
216 if (count - appliesTo.length <= 0) {
Skyler Greyf4f21c42023-03-08 14:36:29 +0000217 await interaction.editReply({
TheCodedProf267563a2023-01-21 17:00:57 -0500218 embeds: [
219 new EmojiEmbed()
220 .setTitle("Premium")
221 .setDescription(
Skyler Grey67691762023-03-06 09:58:19 +0000222 `You have already activated premium on the maximum amount of servers!` +
223 userPremiumServers +
224 firstDescription
TheCodedProf1807fb32023-02-20 14:33:48 -0500225 )
226 .setEmoji("NUCLEUS.PREMIUMACTIVATE")
227 .setStatus("Danger")
228 ],
229 components: []
230 });
231 } else {
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500232 await client.database.premium.addPremium(interaction.user.id, guild.id);
Skyler Greyf4f21c42023-03-08 14:36:29 +0000233 await interaction.editReply({
TheCodedProf1807fb32023-02-20 14:33:48 -0500234 embeds: [
235 new EmojiEmbed()
236 .setTitle("Premium")
Skyler Grey67691762023-03-06 09:58:19 +0000237 .setDescription(
238 `You have activated premium on this server!` + userPremiumServers + firstDescription
239 )
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 };