blob: c431c8ed76e251ac8d580e0eff0a7af700cf3fe3 [file] [log] [blame]
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05001import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, ComponentType, Message, StringSelectMenuBuilder, StringSelectMenuInteraction } from "discord.js";
2import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan813bdf42022-07-24 10:39:10 +01003import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05004import client from "../../utils/client.js";
5import { LoadingEmbed } from "../../utils/defaults.js";
6import 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");
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050010//TODO: Allow User to remove Premium
11
12const 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 });
31
32 const options = premiumGuilds.filter((guild) => guild !== undefined) as string[];
33
34 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 );
51
52 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 });
68
69 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();
87}
pineafan813bdf42022-07-24 10:39:10 +010088
pineafanbd02b4a2022-08-05 22:01:38 +010089const callback = async (interaction: CommandInteraction): Promise<void> => {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050090 if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {});
91 const m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true})
92 const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id).catch(() => {
93 interaction.editReply({ embeds: [
94 new EmojiEmbed()
95 .setTitle("Premium")
96 .setDescription(`*You are not currently in the Clicks Server. To gain access to premium please join.*` + firstDescription)
97 .setEmoji("NUCLEUS.LOGO")
98 .setStatus("Danger")
99 ], components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel("Join").setURL("https://discord.gg/bPaNnxe"))] });
100 })
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`
105 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.`;
107 let count = 0;
108 const {level, appliesTo} = dbMember ?? {level: 0, appliesTo: []}
109 if (level === 99) {
110 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;
112 } else if (level === 1) {
113 premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more server(s).`;
114 count = 1;
115 } else if (level === 2) {
116 premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more server(s).`;
117 count = 3;
118 } else if (level === 3) {
119 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.`
120 count = 3;
121 }
122 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 }
126 if(!interaction.guild) return await dmcallback(interaction, firstDescription, m);
127 const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
128 let premiumGuild = ""
129 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`
131 }
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 )
155 }
156
157 interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100158 embeds: [
159 new EmojiEmbed()
160 .setTitle("Premium")
161 .setDescription(
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500162 premiumGuild + premium + firstDescription
Skyler Grey75ea9172022-08-06 10:22:23 +0100163 )
164 .setEmoji("NUCLEUS.LOGO")
165 .setStatus("Danger")
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500166 .setImage("https://assets.clicks.codes/ads/ads/nucleus-premium.png")
Skyler Grey75ea9172022-08-06 10:22:23 +0100167 ],
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500168 components: components
Skyler Grey75ea9172022-08-06 10:22:23 +0100169 });
pineafan813bdf42022-07-24 10:39:10 +0100170
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500171 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) {
181 interaction.editReply({
182 embeds: [
183 new EmojiEmbed()
184 .setTitle("Premium")
185 .setDescription(
186 `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 {
194 await client.database.premium.addPremium(interaction.user.id, guild.id);
195 interaction.editReply({
196 embeds: [
197 new EmojiEmbed()
198 .setTitle("Premium")
199 .setDescription(
200 `You have activated premium on this server!` + firstDescription
201 )
202 .setEmoji("NUCLEUS.LOGO")
203 .setStatus("Danger")
204 ],
205 components: []
206 });
207 }
pineafan63fc5e22022-08-04 22:04:10 +0100208};
pineafan813bdf42022-07-24 10:39:10 +0100209
210export { command };
211export { callback };