made minor fixes

pull/11/head
TheCodedProf 3 years ago
parent 429c2d8753
commit 8d577fa079

@ -11,7 +11,6 @@ import getEmojiByName from "../../utils/getEmojiByName.js";
const command = (builder: SlashCommandSubcommandBuilder) => builder const command = (builder: SlashCommandSubcommandBuilder) => builder
.setName("nick") .setName("nick")
// .setNameLocalizations({"ru": "name", "zh-CN": "nickname"})
.setDescription("Changes a users nickname") .setDescription("Changes a users nickname")
.addUserOption((option) => option.setName("user").setDescription("The user to change").setRequired(true)) .addUserOption((option) => option.setName("user").setDescription("The user to change").setRequired(true))
.addStringOption((option) => .addStringOption((option) =>

@ -1,74 +1,94 @@
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, StringSelectMenuBuilder } from "discord.js"; import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, ComponentType, Message, StringSelectMenuBuilder, StringSelectMenuInteraction } from "discord.js";
import type { SlashCommandSubcommandBuilder } from "discord.js"; import type { SlashCommandSubcommandBuilder } from "discord.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import client from "../../utils/client.js"; import client from "../../utils/client.js";
import { LoadingEmbed } from "../../utils/defaults.js"; import { LoadingEmbed } from "../../utils/defaults.js";
import getEmojiByName from "../../utils/getEmojiByName.js"; import getEmojiByName from "../../utils/getEmojiByName.js";
import type { PremiumSchema } from "../../utils/database.js";
const command = (builder: SlashCommandSubcommandBuilder) => const command = (builder: SlashCommandSubcommandBuilder) =>
builder.setName("premium").setDescription("Information about Nucleus Premium"); builder.setName("premium").setDescription("Information about Nucleus Premium");
//TODO: Allow User to remove Premium //TODO: Allow User to remove Premium
const dmcallback = async (interaction: CommandInteraction, dbUser: PremiumSchema | null, firstDescription: string): Promise<void> => { const dmcallback = async (interaction: CommandInteraction, firstDescription: string, msg: Message): Promise<void> => {
let closed = false;
if(!dbUser) { do {
await interaction.editReply({embeds: [ const dbUser = await client.database.premium.fetchUser(interaction.user.id);
new EmojiEmbed() if(!dbUser) {
.setTitle("Premium") await interaction.editReply({embeds: [
.setDescription(`*You do not have premium! You can't activate premium on any servers.*` + firstDescription) new EmojiEmbed()
.setEmoji("NUCLEUS.LOGO") .setTitle("Premium")
.setStatus("Danger") .setDescription(`*You do not have premium! You can't activate premium on any servers.*` + firstDescription)
]}); .setEmoji("NUCLEUS.LOGO")
return; .setStatus("Danger")
} ]});
const premiumGuilds = dbUser.appliesTo.map((guildID) => { return;
const guild = client.guilds.cache.get(guildID); }
if(!guild) return undefined; const premiumGuilds = dbUser.appliesTo.map((guildID) => {
return guild.name; const guild = client.guilds.cache.get(guildID);
}); if(!guild) return undefined;
return guild.name;
});
const options = premiumGuilds.filter((guild) => guild !== undefined) as string[]; const options = premiumGuilds.filter((guild) => guild !== undefined) as string[];
const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>() const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>()
.addComponents( .addComponents(
new StringSelectMenuBuilder() new StringSelectMenuBuilder()
.setCustomId("currentPremium") .setCustomId("currentPremium")
.setPlaceholder("Select a server to remove premium from") .setPlaceholder("Select a server to remove premium from")
.setDisabled(premiumGuilds.length === 0) .setDisabled(premiumGuilds.length === 0)
.addOptions(options.map((guild) => { .addOptions(options.slice(0, Math.min(options.length, 24)).map((guild) => {
return {label: guild, value: guild} return {label: guild, value: guild}
})) }))
); );
const removeButton = new ActionRowBuilder<ButtonBuilder>() const cancel = new ActionRowBuilder<ButtonBuilder>()
.addComponents( .addComponents(
new ButtonBuilder() new ButtonBuilder()
.setCustomId("removePremium") .setCustomId("cancel")
.setLabel("Remove Premium") .setLabel("Close")
.setStyle(ButtonStyle.Danger) .setStyle(ButtonStyle.Danger)
.setDisabled(premiumGuilds.length === 0) );
);
await interaction.editReply(
{
embeds: [
new EmojiEmbed()
.setTitle("Premium")
.setDescription(`*You have premium on the following servers:*` + firstDescription)
.setEmoji("NUCLEUS.LOGO")
.setStatus("Success")
],
components: [removeRow, removeButton]
});
//TODO Finish this.
const components: ActionRowBuilder<StringSelectMenuBuilder | ButtonBuilder>[] = [cancel];
if(options.length > 0) components.unshift(removeRow);
await interaction.editReply(
{
embeds: [
new EmojiEmbed()
.setTitle("Premium")
.setDescription(
`*You have premium on the following servers:*\n\n` +
(options.length > 0 ? options.join(', ') : `You have not activated premium in any guilds`) +
firstDescription)
.setEmoji("NUCLEUS.LOGO")
.setStatus("Success")
],
components: components
});
let i: StringSelectMenuInteraction | ButtonInteraction;
try {
const filter = (i: StringSelectMenuInteraction | ButtonInteraction) => i.user.id === interaction.user.id;
i = await msg.awaitMessageComponent<ComponentType.StringSelect | ComponentType.Button>({time: 300000, filter})
} catch (e) {
await interaction.deleteReply();
closed = true;
break;
}
await i.deferUpdate();
if(i.isButton()) {
closed = true;
} else {
const response = client.database.premium.removePremium(interaction.user.id, i.values[0]!);
console.log(response)
}
} while (!closed);
await interaction.deleteReply();
} }
const callback = async (interaction: CommandInteraction): Promise<void> => { const callback = async (interaction: CommandInteraction): Promise<void> => {
if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {}); if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {});
await interaction.reply({embeds: LoadingEmbed, ephemeral: true}) const m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true})
const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id).catch(() => { const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id).catch(() => {
interaction.editReply({ embeds: [ interaction.editReply({ embeds: [
new EmojiEmbed() new EmojiEmbed()
@ -103,14 +123,13 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
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` 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`
count = 0; count = 0;
} }
if(!interaction.guild) return await dmcallback(interaction, dbMember, firstDescription); if(!interaction.guild) return await dmcallback(interaction, firstDescription, m);
const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id); const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
let premiumGuild = "" let premiumGuild = ""
if (hasPremium) { if (hasPremium) {
premiumGuild = `**This server has premium! It was ${hasPremium[2] === 3 && hasPremium[3] ? `automatically applied by <@${hasPremium[1]}>` : `given by <@${hasPremium[1]}>`}**\n\n` premiumGuild = `**This server has premium! It was ${hasPremium[2] === 3 && hasPremium[3] ? `automatically applied by <@${hasPremium[1]}>` : `given by <@${hasPremium[1]}>`}**\n\n`
} }
const components: ActionRowBuilder<ButtonBuilder>[] = [] const components: ActionRowBuilder<ButtonBuilder>[] = []
if (level === 0 || dbMember?.expiresAt) { if (level === 0 || dbMember?.expiresAt) {
components.push( components.push(
@ -144,7 +163,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
) )
.setEmoji("NUCLEUS.LOGO") .setEmoji("NUCLEUS.LOGO")
.setStatus("Danger") .setStatus("Danger")
// .setImage("") //TODO: Add image .setImage("https://assets.clicks.codes/ads/ads/nucleus-premium.png")
], ],
components: components components: components
}); });

@ -7,7 +7,7 @@ import * as crypto from "crypto";
const mongoClient = new MongoClient(config.mongoUrl); const mongoClient = new MongoClient(config.mongoUrl);
await mongoClient.connect(); await mongoClient.connect();
const database = mongoClient.db("Nucleus"); const database = mongoClient.db();
export class Guilds { export class Guilds {
guilds: Collection<GuildConfig>; guilds: Collection<GuildConfig>;

Loading…
Cancel
Save