blob: 026984da768d7a5f0e3401998d15890fbd0a790a [file] [log] [blame]
TheCodedProf1807fb32023-02-20 14:33:48 -05001import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction } 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
pineafanbd02b4a2022-08-05 22:01:38 +010011const callback = async (interaction: CommandInteraction): Promise<void> => {
TheCodedProf267563a2023-01-21 17:00:57 -050012 await interaction.reply({embeds: LoadingEmbed, ephemeral: true})
TheCodedProf94ff6de2023-02-22 17:47:26 -050013 const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id).catch(() => {
TheCodedProf267563a2023-01-21 17:00:57 -050014 interaction.editReply({ embeds: [
Skyler Grey75ea9172022-08-06 10:22:23 +010015 new EmojiEmbed()
16 .setTitle("Premium")
TheCodedProf94ff6de2023-02-22 17:47:26 -050017 .setDescription(`*You are not currently in the Clicks Server. To gain access to premium please join.*` + firstDescription)
Skyler Grey75ea9172022-08-06 10:22:23 +010018 .setEmoji("NUCLEUS.LOGO")
19 .setStatus("Danger")
TheCodedProf267563a2023-01-21 17:00:57 -050020 ], components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel("Join").setURL("https://discord.gg/bPaNnxe"))] });
TheCodedProf94ff6de2023-02-22 17:47:26 -050021 })
22 if (!member) return;
23 const firstDescription = "\n\nPremium allows servers of your choice to get access to extra features for a fixed price per month.\nThis includes:\n" +
24 `${getEmojiByName("MOD.IMAGES.TOOSMALL")} Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n` +
25 `${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 -050026 const dbMember = await client.database.premium.fetchUser(interaction.user.id)
27 let premium = `You do not have premium! You can't activate premium on any servers.`;
TheCodedProf267563a2023-01-21 17:00:57 -050028 let count = 0;
TheCodedProf1807fb32023-02-20 14:33:48 -050029 const {level, appliesTo} = dbMember ?? {level: 0, appliesTo: []}
TheCodedProf633866f2023-02-03 17:06:00 -050030 if (level === 99) {
TheCodedProf267563a2023-01-21 17:00:57 -050031 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.`;
32 count = 200;
TheCodedProf633866f2023-02-03 17:06:00 -050033 } else if (level === 1) {
TheCodedProf94ff6de2023-02-22 17:47:26 -050034 premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -050035 count = 1;
TheCodedProf633866f2023-02-03 17:06:00 -050036 } else if (level === 2) {
TheCodedProf94ff6de2023-02-22 17:47:26 -050037 premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more server(s).`;
TheCodedProf267563a2023-01-21 17:00:57 -050038 count = 3;
TheCodedProf633866f2023-02-03 17:06:00 -050039 } else if (level === 3) {
TheCodedProf94ff6de2023-02-22 17:47:26 -050040 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 -050041 count = 3;
42 }
TheCodedProf94ff6de2023-02-22 17:47:26 -050043 if (dbMember?.expiresAt) {
44 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`
45 count = 0;
46 }
TheCodedProffc420b72023-01-24 17:14:38 -050047 const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
48 let premiumGuild = ""
TheCodedProf94ff6de2023-02-22 17:47:26 -050049 if (hasPremium) { //FIXME: Check how user applied premium
50 premiumGuild = `**This server has premium! It was ${hasPremium[2] === 3 ? `automatically applied by <@${hasPremium[1]}>` : `given by <@${hasPremium[1]}>`}**\n\n`
51 }
52
53 const components: ActionRowBuilder<ButtonBuilder>[] = []
54 if (level === 0 || dbMember?.expiresAt) {
55 components.push(
56 new ActionRowBuilder<ButtonBuilder>()
57 .addComponents(
58 new ButtonBuilder()
59 .setStyle(ButtonStyle.Link)
60 .setLabel("Join Clicks")
61 .setURL("https://discord.gg/bPaNnxe")
62 )
63 )
64 } else {
65 components.push(
66 new ActionRowBuilder<ButtonBuilder>()
67 .addComponents(
68 new ButtonBuilder()
69 .setStyle(premiumGuild.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Success)
70 .setLabel(premiumGuild.length > 0 ? "This server has premium" : "Activate premium here")
71 .setCustomId("premiumActivate")
72 .setDisabled(count <= 0 || (hasPremium ? hasPremium[0] : false))
73 )
74 )
TheCodedProffc420b72023-01-24 17:14:38 -050075 }
76
TheCodedProf1807fb32023-02-20 14:33:48 -050077 interaction.editReply({
78 embeds: [
79 new EmojiEmbed()
80 .setTitle("Premium")
81 .setDescription(
TheCodedProf94ff6de2023-02-22 17:47:26 -050082 premiumGuild + premium + firstDescription
TheCodedProf1807fb32023-02-20 14:33:48 -050083 )
84 .setEmoji("NUCLEUS.LOGO")
85 .setStatus("Danger")
TheCodedProf94ff6de2023-02-22 17:47:26 -050086 // .setImage("") //TODO: Add image
TheCodedProf1807fb32023-02-20 14:33:48 -050087 ],
TheCodedProf94ff6de2023-02-22 17:47:26 -050088 components: components
TheCodedProf1807fb32023-02-20 14:33:48 -050089 });
90
91 const filter = (i: ButtonInteraction) => i.customId === "premiumActivate" && i.user.id === interaction.user.id;
92 let i;
93 try {
94 i = await interaction.channel!.awaitMessageComponent<2>({ filter, time: 60000 });
95 } catch (e) {
96 return;
97 }
98 i.deferUpdate();
99 const guild = i.guild!;
100 if (count - appliesTo.length <= 0) {
TheCodedProf267563a2023-01-21 17:00:57 -0500101 interaction.editReply({
102 embeds: [
103 new EmojiEmbed()
104 .setTitle("Premium")
105 .setDescription(
TheCodedProf1807fb32023-02-20 14:33:48 -0500106 `You have already activated premium on the maximum amount of servers!` + firstDescription
107 )
108 .setEmoji("NUCLEUS.PREMIUMACTIVATE")
109 .setStatus("Danger")
110 ],
111 components: []
112 });
113 } else {
114 client.database.premium.addPremium(interaction.user.id, guild.id);
115 interaction.editReply({
116 embeds: [
117 new EmojiEmbed()
118 .setTitle("Premium")
119 .setDescription(
120 `You have activated premium on this server!` + firstDescription
TheCodedProf267563a2023-01-21 17:00:57 -0500121 )
122 .setEmoji("NUCLEUS.LOGO")
123 .setStatus("Danger")
124 ],
TheCodedProf1807fb32023-02-20 14:33:48 -0500125 components: []
TheCodedProf267563a2023-01-21 17:00:57 -0500126 });
TheCodedProf1807fb32023-02-20 14:33:48 -0500127 }
pineafan63fc5e22022-08-04 22:04:10 +0100128};
pineafan813bdf42022-07-24 10:39:10 +0100129
pineafan813bdf42022-07-24 10:39:10 +0100130export { command };
131export { callback };