blob: c431c8ed76e251ac8d580e0eff0a7af700cf3fe3 [file] [log] [blame]
TheCodedProf8d577fa2023-03-01 13:06:40 -05001import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, ComponentType, Message, StringSelectMenuBuilder, StringSelectMenuInteraction } 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";
pineafan813bdf42022-07-24 10:39:10 +01007
8const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Grey11236ba2022-08-08 21:13:33 +01009 builder.setName("premium").setDescription("Information about Nucleus Premium");
TheCodedProf94ff6de2023-02-22 17:47:26 -050010//TODO: Allow User to remove Premium
TheCodedProfaa3fe992023-02-25 21:53:09 -050011
TheCodedProf8d577fa2023-03-01 13:06:40 -050012const dmcallback = async (interaction: CommandInteraction, firstDescription: string, msg: Message): Promise<void> => {
13 let closed = false;
14 do {
15 const dbUser = await client.database.premium.fetchUser(interaction.user.id);
16 if(!dbUser) {
17 await interaction.editReply({embeds: [
18 new EmojiEmbed()
19 .setTitle("Premium")
20 .setDescription(`*You do not have premium! You can't activate premium on any servers.*` + firstDescription)
21 .setEmoji("NUCLEUS.LOGO")
22 .setStatus("Danger")
23 ]});
24 return;
25 }
26 const premiumGuilds = dbUser.appliesTo.map((guildID) => {
27 const guild = client.guilds.cache.get(guildID);
28 if(!guild) return undefined;
29 return guild.name;
30 });
TheCodedProfaa3fe992023-02-25 21:53:09 -050031
TheCodedProf8d577fa2023-03-01 13:06:40 -050032 const options = premiumGuilds.filter((guild) => guild !== undefined) as string[];
TheCodedProfaa3fe992023-02-25 21:53:09 -050033
TheCodedProf8d577fa2023-03-01 13:06:40 -050034 const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>()
35 .addComponents(
36 new StringSelectMenuBuilder()
37 .setCustomId("currentPremium")
38 .setPlaceholder("Select a server to remove premium from")
39 .setDisabled(premiumGuilds.length === 0)
40 .addOptions(options.slice(0, Math.min(options.length, 24)).map((guild) => {
41 return {label: guild, value: guild}
42 }))
43 );
44 const cancel = new ActionRowBuilder<ButtonBuilder>()
45 .addComponents(
46 new ButtonBuilder()
47 .setCustomId("cancel")
48 .setLabel("Close")
49 .setStyle(ButtonStyle.Danger)
50 );
TheCodedProfaa3fe992023-02-25 21:53:09 -050051
TheCodedProf8d577fa2023-03-01 13:06:40 -050052 const components: ActionRowBuilder<StringSelectMenuBuilder | ButtonBuilder>[] = [cancel];
53 if(options.length > 0) components.unshift(removeRow);
54 await interaction.editReply(
55 {
56 embeds: [
57 new EmojiEmbed()
58 .setTitle("Premium")
59 .setDescription(
60 `*You have premium on the following servers:*\n\n` +
61 (options.length > 0 ? options.join(', ') : `You have not activated premium in any guilds`) +
62 firstDescription)
63 .setEmoji("NUCLEUS.LOGO")
64 .setStatus("Success")
65 ],
66 components: components
67 });
TheCodedProfaa3fe992023-02-25 21:53:09 -050068
TheCodedProf8d577fa2023-03-01 13:06:40 -050069 let i: StringSelectMenuInteraction | ButtonInteraction;
70 try {
71 const filter = (i: StringSelectMenuInteraction | ButtonInteraction) => i.user.id === interaction.user.id;
72 i = await msg.awaitMessageComponent<ComponentType.StringSelect | ComponentType.Button>({time: 300000, filter})
73 } catch (e) {
74 await interaction.deleteReply();
75 closed = true;
76 break;
77 }
78 await i.deferUpdate();
79 if(i.isButton()) {
80 closed = true;
81 } else {
82 const response = client.database.premium.removePremium(interaction.user.id, i.values[0]!);
83 console.log(response)
84 }
85 } while (!closed);
86 await interaction.deleteReply();
TheCodedProfaa3fe992023-02-25 21:53:09 -050087}
88
pineafanbd02b4a2022-08-05 22:01:38 +010089const callback = async (interaction: CommandInteraction): Promise<void> => {
TheCodedProf9c51a7e2023-02-27 17:11:13 -050090 if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {});
TheCodedProf8d577fa2023-03-01 13:06:40 -050091 const m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true})
TheCodedProf94ff6de2023-02-22 17:47:26 -050092 const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id).catch(() => {
TheCodedProf267563a2023-01-21 17:00:57 -050093 interaction.editReply({ embeds: [
Skyler Grey75ea9172022-08-06 10:22:23 +010094 new EmojiEmbed()
95 .setTitle("Premium")
TheCodedProf94ff6de2023-02-22 17:47:26 -050096 .setDescription(`*You are not currently in the Clicks Server. To gain access to premium please join.*` + firstDescription)
Skyler Grey75ea9172022-08-06 10:22:23 +010097 .setEmoji("NUCLEUS.LOGO")
98 .setStatus("Danger")
TheCodedProf267563a2023-01-21 17:00:57 -050099 ], components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel("Join").setURL("https://discord.gg/bPaNnxe"))] });
TheCodedProf94ff6de2023-02-22 17:47:26 -0500100 })
101 if (!member) return;
102 const firstDescription = "\n\nPremium allows servers of your choice to get access to extra features for a fixed price per month.\nThis includes:\n" +
103 `${getEmojiByName("MOD.IMAGES.TOOSMALL")} Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n` +
104 `${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 -0500105 const dbMember = await client.database.premium.fetchUser(interaction.user.id)
106 let premium = `You do not have premium! You can't activate premium on any servers.`;
TheCodedProf267563a2023-01-21 17:00:57 -0500107 let count = 0;
TheCodedProf1807fb32023-02-20 14:33:48 -0500108 const {level, appliesTo} = dbMember ?? {level: 0, appliesTo: []}
TheCodedProf633866f2023-02-03 17:06:00 -0500109 if (level === 99) {
TheCodedProf267563a2023-01-21 17:00:57 -0500110 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.`;
111 count = 200;
TheCodedProf633866f2023-02-03 17:06:00 -0500112 } else if (level === 1) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500113 premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -0500114 count = 1;
TheCodedProf633866f2023-02-03 17:06:00 -0500115 } else if (level === 2) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500116 premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -0500117 count = 3;
TheCodedProf633866f2023-02-03 17:06:00 -0500118 } else if (level === 3) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500119 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 -0500120 count = 3;
121 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500122 if (dbMember?.expiresAt) {
123 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`
124 count = 0;
125 }
TheCodedProf8d577fa2023-03-01 13:06:40 -0500126 if(!interaction.guild) return await dmcallback(interaction, firstDescription, m);
TheCodedProffc420b72023-01-24 17:14:38 -0500127 const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
128 let premiumGuild = ""
TheCodedProfaa3fe992023-02-25 21:53:09 -0500129 if (hasPremium) {
130 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 -0500131 }
132
133 const components: ActionRowBuilder<ButtonBuilder>[] = []
134 if (level === 0 || dbMember?.expiresAt) {
135 components.push(
136 new ActionRowBuilder<ButtonBuilder>()
137 .addComponents(
138 new ButtonBuilder()
139 .setStyle(ButtonStyle.Link)
140 .setLabel("Join Clicks")
141 .setURL("https://discord.gg/bPaNnxe")
142 )
143 )
144 } else {
145 components.push(
146 new ActionRowBuilder<ButtonBuilder>()
147 .addComponents(
148 new ButtonBuilder()
149 .setStyle(premiumGuild.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Success)
150 .setLabel(premiumGuild.length > 0 ? "This server has premium" : "Activate premium here")
151 .setCustomId("premiumActivate")
152 .setDisabled(count <= 0 || (hasPremium ? hasPremium[0] : false))
153 )
154 )
TheCodedProffc420b72023-01-24 17:14:38 -0500155 }
156
TheCodedProf1807fb32023-02-20 14:33:48 -0500157 interaction.editReply({
158 embeds: [
159 new EmojiEmbed()
160 .setTitle("Premium")
161 .setDescription(
TheCodedProf94ff6de2023-02-22 17:47:26 -0500162 premiumGuild + premium + firstDescription
TheCodedProf1807fb32023-02-20 14:33:48 -0500163 )
164 .setEmoji("NUCLEUS.LOGO")
165 .setStatus("Danger")
TheCodedProf8d577fa2023-03-01 13:06:40 -0500166 .setImage("https://assets.clicks.codes/ads/ads/nucleus-premium.png")
TheCodedProf1807fb32023-02-20 14:33:48 -0500167 ],
TheCodedProf94ff6de2023-02-22 17:47:26 -0500168 components: components
TheCodedProf1807fb32023-02-20 14:33:48 -0500169 });
170
171 const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id;
172 let i;
173 try {
174 i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 });
175 } catch (e) {
176 return;
177 }
178 i.deferUpdate();
179 const guild = i.guild!;
180 if (count - appliesTo.length <= 0) {
TheCodedProf267563a2023-01-21 17:00:57 -0500181 interaction.editReply({
182 embeds: [
183 new EmojiEmbed()
184 .setTitle("Premium")
185 .setDescription(
TheCodedProf1807fb32023-02-20 14:33:48 -0500186 `You have already activated premium on the maximum amount of servers!` + firstDescription
187 )
188 .setEmoji("NUCLEUS.PREMIUMACTIVATE")
189 .setStatus("Danger")
190 ],
191 components: []
192 });
193 } else {
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500194 await client.database.premium.addPremium(interaction.user.id, guild.id);
TheCodedProf1807fb32023-02-20 14:33:48 -0500195 interaction.editReply({
196 embeds: [
197 new EmojiEmbed()
198 .setTitle("Premium")
199 .setDescription(
200 `You have activated premium on this server!` + firstDescription
TheCodedProf267563a2023-01-21 17:00:57 -0500201 )
202 .setEmoji("NUCLEUS.LOGO")
203 .setStatus("Danger")
204 ],
TheCodedProf1807fb32023-02-20 14:33:48 -0500205 components: []
TheCodedProf267563a2023-01-21 17:00:57 -0500206 });
TheCodedProf1807fb32023-02-20 14:33:48 -0500207 }
pineafan63fc5e22022-08-04 22:04:10 +0100208};
pineafan813bdf42022-07-24 10:39:10 +0100209
pineafan813bdf42022-07-24 10:39:10 +0100210export { command };
211export { callback };