blob: be1a610216001225739a248d4d7660fe3d08d210 [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 {
PineappleFanba20ac62023-03-13 11:26:13 +000096 await client.database.premium.removePremium(interaction.user.id, i.values[0]!);
TheCodedProf8d577fa2023-03-01 13:06:40 -050097 }
98 } while (!closed);
99 await interaction.deleteReply();
Skyler Greyda16adf2023-03-05 10:22:12 +0000100};
TheCodedProfaa3fe992023-02-25 21:53:09 -0500101
pineafanbd02b4a2022-08-05 22:01:38 +0100102const callback = async (interaction: CommandInteraction): Promise<void> => {
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500103 if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {});
Skyler Greyda16adf2023-03-05 10:22:12 +0000104 const m = await interaction.reply({ embeds: LoadingEmbed, ephemeral: true, fetchReply: true });
105 const member = await (await interaction.client.guilds.fetch("684492926528651336")).members
106 .fetch(interaction.user.id)
107 .catch(() => {
Skyler Greyf4f21c42023-03-08 14:36:29 +0000108 void interaction.editReply({
Skyler Greyda16adf2023-03-05 10:22:12 +0000109 embeds: [
110 new EmojiEmbed()
111 .setTitle("Premium")
112 .setDescription(
113 `*You are not currently in the Clicks Server. To gain access to premium please join.*` +
114 firstDescription
115 )
116 .setEmoji("NUCLEUS.LOGO")
117 .setStatus("Danger")
118 ],
119 components: [
120 new ActionRowBuilder<ButtonBuilder>().addComponents(
121 new ButtonBuilder()
122 .setStyle(ButtonStyle.Link)
123 .setLabel("Join")
124 .setURL("https://discord.gg/bPaNnxe")
125 )
126 ]
127 });
128 });
TheCodedProf94ff6de2023-02-22 17:47:26 -0500129 if (!member) return;
Skyler Greyda16adf2023-03-05 10:22:12 +0000130 const firstDescription =
131 "\n\nPremium allows servers of your choice to get access to extra features for a fixed price per month.\nThis includes:\n" +
132 `${getEmojiByName(
133 "MOD.IMAGES.TOOSMALL"
134 )} Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n` +
135 `${getEmojiByName(
136 "GUILD.TICKET.ARCHIVED"
137 )} Ticket Transcripts - Gives a link to view the history of a ticket after it has been closed.\n`;
138 const dbMember = await client.database.premium.fetchUser(interaction.user.id);
TheCodedProf633866f2023-02-03 17:06:00 -0500139 let premium = `You do not have premium! You can't activate premium on any servers.`;
TheCodedProf267563a2023-01-21 17:00:57 -0500140 let count = 0;
Skyler Greyda16adf2023-03-05 10:22:12 +0000141 const { level, appliesTo } = dbMember ?? { level: 0, appliesTo: [] };
TheCodedProf633866f2023-02-03 17:06:00 -0500142 if (level === 99) {
TheCodedProf267563a2023-01-21 17:00:57 -0500143 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.`;
144 count = 200;
TheCodedProf633866f2023-02-03 17:06:00 -0500145 } else if (level === 1) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500146 premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -0500147 count = 1;
TheCodedProf633866f2023-02-03 17:06:00 -0500148 } else if (level === 2) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500149 premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -0500150 count = 3;
TheCodedProf633866f2023-02-03 17:06:00 -0500151 } else if (level === 3) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000152 premium = `You have Premium Mod! You can give premium to ${
153 3 - appliesTo.length
154 } more server(s), as well as automatically giving premium to all servers you have a "manage" permission in.`;
TheCodedProf267563a2023-01-21 17:00:57 -0500155 count = 3;
156 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500157 if (dbMember?.expiresAt) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000158 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 -0500159 count = 0;
160 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000161 if (!interaction.guild) return await dmcallback(interaction, firstDescription, m);
TheCodedProffc420b72023-01-24 17:14:38 -0500162 const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
Skyler Greyda16adf2023-03-05 10:22:12 +0000163 let premiumGuild = "";
TheCodedProfaa3fe992023-02-25 21:53:09 -0500164 if (hasPremium) {
TheCodedProf48865eb2023-03-05 15:25:25 -0500165 const gaveUser = await client.users.fetch(hasPremium[1]);
Skyler Greyda16adf2023-03-05 10:22:12 +0000166 premiumGuild = `**This server has premium! It was ${
167 hasPremium[2] === 3 && hasPremium[3]
pineafan3c1c6802023-05-28 15:45:24 +0100168 ? `automatically applied by ${gaveUser.username}`
Skyler Greyda16adf2023-03-05 10:22:12 +0000169 : `given by <@${hasPremium[1]}>`
170 }**\n\n`;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500171 }
172
Skyler Greyda16adf2023-03-05 10:22:12 +0000173 const components: ActionRowBuilder<ButtonBuilder>[] = [];
TheCodedProf94ff6de2023-02-22 17:47:26 -0500174 if (level === 0 || dbMember?.expiresAt) {
175 components.push(
Skyler Greyda16adf2023-03-05 10:22:12 +0000176 new ActionRowBuilder<ButtonBuilder>().addComponents(
177 new ButtonBuilder()
TheCodedProf94ff6de2023-02-22 17:47:26 -0500178 .setStyle(ButtonStyle.Link)
179 .setLabel("Join Clicks")
180 .setURL("https://discord.gg/bPaNnxe")
Skyler Greyda16adf2023-03-05 10:22:12 +0000181 )
182 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500183 } else {
184 components.push(
Skyler Greyda16adf2023-03-05 10:22:12 +0000185 new ActionRowBuilder<ButtonBuilder>().addComponents(
186 new ButtonBuilder()
187 .setStyle(premiumGuild.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Success)
188 .setLabel(premiumGuild.length > 0 ? "This server has premium" : "Activate premium here")
189 .setCustomId("premiumActivate")
190 .setDisabled(count <= 0 || (hasPremium ? hasPremium[0] : false))
191 )
192 );
TheCodedProffc420b72023-01-24 17:14:38 -0500193 }
194
Skyler Greya0c70242023-03-06 09:56:21 +0000195 let userPremiumServers = "";
Skyler Grey67691762023-03-06 09:58:19 +0000196 if ((dbMember?.appliesTo.length ?? 0) > 0)
197 userPremiumServers = "\nIf you want to remove premium from a server, run this command in your DMs with me.";
TheCodedProf48865eb2023-03-05 15:25:25 -0500198
Skyler Greyf4f21c42023-03-08 14:36:29 +0000199 await interaction.editReply({
TheCodedProf1807fb32023-02-20 14:33:48 -0500200 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 }
Skyler Greyf4f21c42023-03-08 14:36:29 +0000218 await i.deferUpdate();
TheCodedProf1807fb32023-02-20 14:33:48 -0500219 const guild = i.guild!;
220 if (count - appliesTo.length <= 0) {
Skyler Greyf4f21c42023-03-08 14:36:29 +0000221 await interaction.editReply({
TheCodedProf267563a2023-01-21 17:00:57 -0500222 embeds: [
223 new EmojiEmbed()
224 .setTitle("Premium")
225 .setDescription(
Skyler Grey67691762023-03-06 09:58:19 +0000226 `You have already activated premium on the maximum amount of servers!` +
227 userPremiumServers +
228 firstDescription
TheCodedProf1807fb32023-02-20 14:33:48 -0500229 )
230 .setEmoji("NUCLEUS.PREMIUMACTIVATE")
231 .setStatus("Danger")
232 ],
233 components: []
234 });
235 } else {
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500236 await client.database.premium.addPremium(interaction.user.id, guild.id);
Skyler Greyf4f21c42023-03-08 14:36:29 +0000237 await interaction.editReply({
TheCodedProf1807fb32023-02-20 14:33:48 -0500238 embeds: [
239 new EmojiEmbed()
240 .setTitle("Premium")
Skyler Grey67691762023-03-06 09:58:19 +0000241 .setDescription(
242 `You have activated premium on this server!` + userPremiumServers + firstDescription
243 )
TheCodedProf267563a2023-01-21 17:00:57 -0500244 .setEmoji("NUCLEUS.LOGO")
245 .setStatus("Danger")
246 ],
TheCodedProf1807fb32023-02-20 14:33:48 -0500247 components: []
TheCodedProf267563a2023-01-21 17:00:57 -0500248 });
TheCodedProf1807fb32023-02-20 14:33:48 -0500249 }
pineafan63fc5e22022-08-04 22:04:10 +0100250};
pineafan813bdf42022-07-24 10:39:10 +0100251
pineafan813bdf42022-07-24 10:39:10 +0100252export { command };
253export { callback };