blob: 9d2c2b1a49b7f83412b6f05d7736776bc1730f9a [file] [log] [blame]
TheCodedProf267563a2023-01-21 17:00:57 -05001import { ActionRowBuilder, ButtonBuilder, 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";
pineafan813bdf42022-07-24 10:39:10 +01006
7const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Grey11236ba2022-08-08 21:13:33 +01008 builder.setName("premium").setDescription("Information about Nucleus Premium");
pineafan813bdf42022-07-24 10:39:10 +01009
pineafanbd02b4a2022-08-05 22:01:38 +010010const callback = async (interaction: CommandInteraction): Promise<void> => {
TheCodedProf267563a2023-01-21 17:00:57 -050011 await interaction.reply({embeds: LoadingEmbed, ephemeral: true})
12 const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id)
13 const firstDescription = "\n\nPremium allows your server to get access to extra features, for a fixed price per month.\nThis includes:\n" +
14 "- Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n" +
15 "- Ticket Transcripts - Gives a link to view the history of a ticket after it has been closed.\n"
16 if(!member) {
17 interaction.editReply({ embeds: [
Skyler Grey75ea9172022-08-06 10:22:23 +010018 new EmojiEmbed()
19 .setTitle("Premium")
20 .setDescription(
TheCodedProf267563a2023-01-21 17:00:57 -050021 `*You are not currently in the Clicks Server. To gain access to premium please join.*` + firstDescription
Skyler Grey75ea9172022-08-06 10:22:23 +010022 )
23 .setEmoji("NUCLEUS.LOGO")
24 .setStatus("Danger")
TheCodedProf267563a2023-01-21 17:00:57 -050025 ], components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel("Join").setURL("https://discord.gg/bPaNnxe"))] });
26 return;
27 }
TheCodedProf633866f2023-02-03 17:06:00 -050028 const dbMember = await client.database.premium.fetchUser(interaction.user.id)
29 let premium = `You do not have premium! You can't activate premium on any servers.`;
TheCodedProf267563a2023-01-21 17:00:57 -050030 let count = 0;
TheCodedProf633866f2023-02-03 17:06:00 -050031 const {level, appliesTo} = dbMember || {level: 0, appliesTo: []}
32 if (level === 99) {
TheCodedProf267563a2023-01-21 17:00:57 -050033 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.`;
34 count = 200;
TheCodedProf633866f2023-02-03 17:06:00 -050035 } else if (level === 1) {
36 premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more servers.`;
TheCodedProf267563a2023-01-21 17:00:57 -050037 count = 1;
TheCodedProf633866f2023-02-03 17:06:00 -050038 } else if (level === 2) {
39 premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more servers.`;
TheCodedProf267563a2023-01-21 17:00:57 -050040 count = 3;
TheCodedProf633866f2023-02-03 17:06:00 -050041 } else if (level === 3) {
42 premium = `You have Premium Mod! You can give premium to ${3 - appliesTo.length} more servers, as well as automatically giving premium to all servers you have a "manage" permission in.`
TheCodedProf267563a2023-01-21 17:00:57 -050043 count = 3;
44 }
TheCodedProffc420b72023-01-24 17:14:38 -050045 const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
46 let premiumGuild = ""
47 if (hasPremium) {
48 premiumGuild = `\n\n**This server has premium!**`
49 }
50
51 let closed = false;
TheCodedProf267563a2023-01-21 17:00:57 -050052 do {
53 interaction.editReply({
54 embeds: [
55 new EmojiEmbed()
56 .setTitle("Premium")
57 .setDescription(
TheCodedProffc420b72023-01-24 17:14:38 -050058 premium + firstDescription + premiumGuild
TheCodedProf267563a2023-01-21 17:00:57 -050059 )
60 .setEmoji("NUCLEUS.LOGO")
61 .setStatus("Danger")
62 ],
63 components: [
64 new ActionRowBuilder<ButtonBuilder>()
65 .addComponents(
66 new ButtonBuilder()
67 .setStyle(ButtonStyle.Primary)
68 .setLabel("Activate Premium here")
69 .setCustomId("premiumActivate")
TheCodedProffc420b72023-01-24 17:14:38 -050070 .setDisabled(count <= 0 && hasPremium)
TheCodedProf267563a2023-01-21 17:00:57 -050071 )
72 ]
73 });
74
75 const filter = (i: any) => i.customId === "premiumActivate" && i.user.id === interaction.user.id;
TheCodedProffc420b72023-01-24 17:14:38 -050076 let i;
77 try {
78 i = await interaction.channel!.awaitMessageComponent({ filter, time: 60000 });
79 } catch (e) {
80 return;
81 }
82 if (i) {
83 i.deferUpdate();
84 let guild = i.guild!;
TheCodedProf633866f2023-02-03 17:06:00 -050085 if (count - appliesTo.length <= 0) {
TheCodedProffc420b72023-01-24 17:14:38 -050086 interaction.editReply({
87 embeds: [
88 new EmojiEmbed()
89 .setTitle("Premium")
90 .setDescription(
91 `You have already activated premium on the maximum amount of servers!` + firstDescription
92 )
TheCodedProf1c3ad3c2023-01-25 17:58:36 -050093 .setEmoji("NUCLEUS.PREMIUMACTIVATE")
TheCodedProffc420b72023-01-24 17:14:38 -050094 .setStatus("Danger")
95 ],
96 components: []
97 });
98 closed = true;
99 } else {
100 client.database.premium.addPremium(interaction.user.id, guild.id);
101 interaction.editReply({
102 embeds: [
103 new EmojiEmbed()
104 .setTitle("Premium")
105 .setDescription(
106 `You have activated premium on this server!` + firstDescription
107 )
108 .setEmoji("NUCLEUS.LOGO")
109 .setStatus("Danger")
110 ],
111 components: []
112 });
113 closed = true;
114 }
115 }
116
117 } while (!closed);
pineafan63fc5e22022-08-04 22:04:10 +0100118};
pineafan813bdf42022-07-24 10:39:10 +0100119
pineafan813bdf42022-07-24 10:39:10 +0100120export { command };
121export { callback };