blob: f544045f942819ec80523471a390ced6481f42f2 [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(() => {
Skyler Greyf4f21c42023-03-08 14:36:29 +0000109 void interaction.editReply({
Skyler Greyda16adf2023-03-05 10:22:12 +0000110 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 = "";
Skyler Grey67691762023-03-06 09:58:19 +0000197 if ((dbMember?.appliesTo.length ?? 0) > 0)
198 userPremiumServers = "\nIf you want to remove premium from a server, run this command in your DMs with me.";
TheCodedProf48865eb2023-03-05 15:25:25 -0500199
Skyler Greyf4f21c42023-03-08 14:36:29 +0000200 await interaction.editReply({
TheCodedProf1807fb32023-02-20 14:33:48 -0500201 embeds: [
202 new EmojiEmbed()
203 .setTitle("Premium")
Skyler Greyda16adf2023-03-05 10:22:12 +0000204 .setDescription(premiumGuild + premium + firstDescription)
TheCodedProf1807fb32023-02-20 14:33:48 -0500205 .setEmoji("NUCLEUS.LOGO")
206 .setStatus("Danger")
TheCodedProf8d577fa2023-03-01 13:06:40 -0500207 .setImage("https://assets.clicks.codes/ads/ads/nucleus-premium.png")
TheCodedProf1807fb32023-02-20 14:33:48 -0500208 ],
TheCodedProf94ff6de2023-02-22 17:47:26 -0500209 components: components
TheCodedProf1807fb32023-02-20 14:33:48 -0500210 });
211
212 const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id;
213 let i;
214 try {
215 i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 });
216 } catch (e) {
217 return;
218 }
Skyler Greyf4f21c42023-03-08 14:36:29 +0000219 await i.deferUpdate();
TheCodedProf1807fb32023-02-20 14:33:48 -0500220 const guild = i.guild!;
221 if (count - appliesTo.length <= 0) {
Skyler Greyf4f21c42023-03-08 14:36:29 +0000222 await interaction.editReply({
TheCodedProf267563a2023-01-21 17:00:57 -0500223 embeds: [
224 new EmojiEmbed()
225 .setTitle("Premium")
226 .setDescription(
Skyler Grey67691762023-03-06 09:58:19 +0000227 `You have already activated premium on the maximum amount of servers!` +
228 userPremiumServers +
229 firstDescription
TheCodedProf1807fb32023-02-20 14:33:48 -0500230 )
231 .setEmoji("NUCLEUS.PREMIUMACTIVATE")
232 .setStatus("Danger")
233 ],
234 components: []
235 });
236 } else {
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500237 await client.database.premium.addPremium(interaction.user.id, guild.id);
Skyler Greyf4f21c42023-03-08 14:36:29 +0000238 await interaction.editReply({
TheCodedProf1807fb32023-02-20 14:33:48 -0500239 embeds: [
240 new EmojiEmbed()
241 .setTitle("Premium")
Skyler Grey67691762023-03-06 09:58:19 +0000242 .setDescription(
243 `You have activated premium on this server!` + userPremiumServers + firstDescription
244 )
TheCodedProf267563a2023-01-21 17:00:57 -0500245 .setEmoji("NUCLEUS.LOGO")
246 .setStatus("Danger")
247 ],
TheCodedProf1807fb32023-02-20 14:33:48 -0500248 components: []
TheCodedProf267563a2023-01-21 17:00:57 -0500249 });
TheCodedProf1807fb32023-02-20 14:33:48 -0500250 }
pineafan63fc5e22022-08-04 22:04:10 +0100251};
pineafan813bdf42022-07-24 10:39:10 +0100252
pineafan813bdf42022-07-24 10:39:10 +0100253export { command };
254export { callback };