Fixed rolemenu (should be usable now)

pull/91/head
pineafan 3 years ago
parent def38a72e0
commit 72659cc74b
Signed by: Pinea
GPG Key ID: E5E1C2D43B0E4AB3

@ -45,7 +45,8 @@ interface ObjectSchema {
export const configToDropdown = ( export const configToDropdown = (
placeholder: string, placeholder: string,
currentPageData: ObjectSchema, currentPageData: ObjectSchema,
selectedRoles?: string[] selectedRoles?: string[],
disabled?: boolean
): ActionRowBuilder<StringSelectMenuBuilder> => { ): ActionRowBuilder<StringSelectMenuBuilder> => {
return new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( return new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder() new StringSelectMenuBuilder()
@ -53,6 +54,7 @@ export const configToDropdown = (
.setPlaceholder(placeholder) .setPlaceholder(placeholder)
.setMinValues(currentPageData.min) .setMinValues(currentPageData.min)
.setMaxValues(currentPageData.max) .setMaxValues(currentPageData.max)
.setDisabled(disabled)
.addOptions( .addOptions(
currentPageData.options.map((option: { name: string; description: string | null; role: string }) => { currentPageData.options.map((option: { name: string; description: string | null; role: string }) => {
const builder = new StringSelectMenuOptionBuilder() const builder = new StringSelectMenuOptionBuilder()

@ -119,9 +119,21 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
], ],
components: [ components: [
new Discord.ActionRowBuilder<ButtonBuilder>().addComponents( new Discord.ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setCustomId("accept:Suggestion").setLabel("Accept").setStyle(ButtonStyle.Success).setDisabled(disabled), new ButtonBuilder()
new ButtonBuilder().setCustomId("deny:Suggestion").setLabel("Deny").setStyle(ButtonStyle.Danger).setDisabled(disabled), .setCustomId("accept:Suggestion")
new ButtonBuilder().setCustomId("close:Suggestion").setLabel("Close").setStyle(ButtonStyle.Secondary).setDisabled(disabled), .setLabel("Accept")
.setStyle(ButtonStyle.Success)
.setDisabled(disabled),
new ButtonBuilder()
.setCustomId("deny:Suggestion")
.setLabel("Deny")
.setStyle(ButtonStyle.Danger)
.setDisabled(disabled),
new ButtonBuilder()
.setCustomId("close:Suggestion")
.setLabel("Close")
.setStyle(ButtonStyle.Secondary)
.setDisabled(disabled),
new ButtonBuilder() new ButtonBuilder()
.setCustomId("implemented:Suggestion") .setCustomId("implemented:Suggestion")
.setLabel("Implemented") .setLabel("Implemented")
@ -134,8 +146,16 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
.setDisabled(disabled) .setDisabled(disabled)
), ),
new Discord.ActionRowBuilder<ButtonBuilder>().addComponents( new Discord.ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setCustomId("lock:Comment").setLabel("Lock").setStyle(ButtonStyle.Danger).setDisabled(disabled), new ButtonBuilder()
new ButtonBuilder().setCustomId("spam:Suggestion").setLabel("Mark as Spam").setStyle(ButtonStyle.Danger).setDisabled(disabled) .setCustomId("lock:Comment")
.setLabel("Lock")
.setStyle(ButtonStyle.Danger)
.setDisabled(disabled),
new ButtonBuilder()
.setCustomId("spam:Suggestion")
.setLabel("Mark as Spam")
.setStyle(ButtonStyle.Danger)
.setDisabled(disabled)
) )
] ]
}); });

@ -120,6 +120,7 @@ const editNameDescription = async (
.setStyle(TextInputStyle.Short) .setStyle(TextInputStyle.Short)
.setValue(name ?? "") .setValue(name ?? "")
.setRequired(true) .setRequired(true)
.setMaxLength(100)
), ),
new ActionRowBuilder<TextInputBuilder>().addComponents( new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder() new TextInputBuilder()
@ -128,6 +129,8 @@ const editNameDescription = async (
.setPlaceholder("A short description of the role (e.g. A role for people who code)") .setPlaceholder("A short description of the role (e.g. A role for people who code)")
.setStyle(TextInputStyle.Short) .setStyle(TextInputStyle.Short)
.setValue(description ?? "") .setValue(description ?? "")
.setRequired(false)
.setMaxLength(100)
) )
); );
const button = new ActionRowBuilder<ButtonBuilder>().addComponents( const button = new ActionRowBuilder<ButtonBuilder>().addComponents(
@ -159,15 +162,15 @@ const editNameDescription = async (
if (!out) return [name, description]; if (!out) return [name, description];
if (out.isButton()) return [name, description]; if (out.isButton()) return [name, description];
name = out.fields.fields.find((f) => f.customId === "name")?.value ?? name; name = out.fields.fields.find((f) => f.customId === "name")?.value ?? name;
description = out.fields.fields.find((f) => f.customId === "description")?.value ?? description; description = out.fields.fields.find((f) => f.customId === "description")?.value ?? "";
return [name, description]; return [name, description];
}; };
const defaultRoleMenuData = { const defaultRoleMenuData = {
name: "Role Menu Page", name: "New Page",
description: "A new role menu page", description: "",
min: 0, min: 0,
max: 0, max: 1,
options: [] options: []
}; };
@ -196,17 +199,20 @@ const editRoleMenuPage = async (
); );
let back = false; let back = false;
if (data.options.length === 0) {
data.options = [{ name: "Role 1", description: null, role: "No role set" }];
}
do { do {
const previewSelect = configToDropdown("Edit Roles", { const noRoles = data.options.length === 0;
name: data.name, const previewSelect = configToDropdown(
description: data.description, "Edit Roles",
min: 1, {
max: 1, name: data.name,
options: data.options description: data.description,
}); min: 1,
max: 1,
options: noRoles ? [{ name: "Role 1", description: null, role: "No role set" }] : data.options
},
undefined,
noRoles
);
const embed = new EmojiEmbed() const embed = new EmojiEmbed()
.setTitle(`${data.name}`) .setTitle(`${data.name}`)
.setStatus("Success") .setStatus("Success")
@ -215,7 +221,8 @@ const editRoleMenuPage = async (
`**Min:** ${data.min}` + `**Min:** ${data.min}` +
(data.min === 0 ? " (Members will be given a skip button)" : "") + (data.min === 0 ? " (Members will be given a skip button)" : "") +
"\n" + "\n" +
`**Max:** ${data.max}\n` `**Max:** ${data.max}\n` +
`\n**Roles:** ${data.options.length === 0 ? "*No roles set*" : data.options.length}`
); );
await interaction.editReply({ embeds: [embed], components: [previewSelect, buttons] }); await interaction.editReply({ embeds: [embed], components: [previewSelect, buttons] });
@ -237,7 +244,8 @@ const editRoleMenuPage = async (
await createRoleMenuOptionPage( await createRoleMenuOptionPage(
interaction, interaction,
m, m,
data.options.find((o) => o.role === (i as StringSelectMenuInteraction).values[0]) data.options.find((o) => o.role === (i as StringSelectMenuInteraction).values[0]),
false
); );
} }
} else if (i.isButton()) { } else if (i.isButton()) {
@ -255,7 +263,8 @@ const editRoleMenuPage = async (
} }
case "addRole": { case "addRole": {
await i.deferUpdate(); await i.deferUpdate();
data.options.push(await createRoleMenuOptionPage(interaction, m)); const out = await createRoleMenuOptionPage(interaction, m, undefined, true);
if (out) data.options.push(out);
break; break;
} }
} }
@ -268,8 +277,10 @@ const editRoleMenuPage = async (
const createRoleMenuOptionPage = async ( const createRoleMenuOptionPage = async (
interaction: StringSelectMenuInteraction | ButtonInteraction, interaction: StringSelectMenuInteraction | ButtonInteraction,
m: Message, m: Message,
data?: { name: string; description: string | null; role: string } data?: { name: string; description: string | null; role: string },
newRole: boolean = false
) => { ) => {
const initialData = _.cloneDeep(data);
const { renderRole } = client.logger; const { renderRole } = client.logger;
if (!data) if (!data)
data = { data = {
@ -281,19 +292,29 @@ const createRoleMenuOptionPage = async (
const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder() new ButtonBuilder()
.setCustomId("back") .setCustomId("back")
.setLabel("Back") .setLabel(newRole ? "Add" : "Back")
.setStyle(ButtonStyle.Secondary) .setStyle(newRole ? ButtonStyle.Success : ButtonStyle.Secondary)
.setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji), .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji),
new ButtonBuilder() new ButtonBuilder()
.setCustomId("edit") .setCustomId("edit")
.setLabel("Edit Details") .setLabel("Edit Details")
.setStyle(ButtonStyle.Primary) .setStyle(ButtonStyle.Primary)
.setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji) .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji),
new ButtonBuilder()
.setCustomId("delete")
.setLabel("Delete")
.setStyle(ButtonStyle.Danger)
.setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji),
new ButtonBuilder()
.setCustomId("cancel")
.setLabel("Cancel")
.setStyle(ButtonStyle.Secondary)
.setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji)
); );
do { do {
const roleSelect = new RoleSelectMenuBuilder() const roleSelect = new RoleSelectMenuBuilder()
.setCustomId("role") .setCustomId("role")
.setPlaceholder(data.role ? "Set role to" : "Set the role"); .setPlaceholder(data.role ? "Change role to" : "Select a role");
const embed = new EmojiEmbed() const embed = new EmojiEmbed()
.setTitle(`${data.name}`) .setTitle(`${data.name}`)
.setStatus("Success") .setStatus("Success")
@ -325,6 +346,12 @@ const createRoleMenuOptionPage = async (
if (i.customId === "role") { if (i.customId === "role") {
await i.deferUpdate(); await i.deferUpdate();
data.role = (i as RoleSelectMenuInteraction).values[0]!; data.role = (i as RoleSelectMenuInteraction).values[0]!;
await interaction.editReply({
embeds: [
new EmojiEmbed().setTitle(`Applying changes`).setStatus("Danger").setEmoji("NUCLEUS.LOADING")
],
components: []
});
} }
} else if (i.isButton()) { } else if (i.isButton()) {
switch (i.customId) { switch (i.customId) {
@ -334,7 +361,6 @@ const createRoleMenuOptionPage = async (
break; break;
} }
case "edit": { case "edit": {
await i.deferUpdate();
const [name, description] = await editNameDescription( const [name, description] = await editNameDescription(
i, i,
interaction, interaction,
@ -345,6 +371,15 @@ const createRoleMenuOptionPage = async (
data.description = description ? description : data.description; data.description = description ? description : data.description;
break; break;
} }
case "delete": {
await i.deferUpdate();
return null;
}
case "cancel": {
await i.deferUpdate();
if (newRole) return null;
else return initialData;
}
} }
} }
} while (!back); } while (!back);
@ -383,6 +418,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
.setValue("delete") .setValue("delete")
.setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji) .setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji)
); );
console.log(page);
const buttonRow = new ActionRowBuilder<ButtonBuilder>().addComponents( const buttonRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder() new ButtonBuilder()
.setCustomId("back") .setCustomId("back")
@ -422,7 +458,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
actionSelect.setDisabled(true); actionSelect.setDisabled(true);
pageSelect.addOptions(new StringSelectMenuOptionBuilder().setLabel("No role menu pages").setValue("none")); pageSelect.addOptions(new StringSelectMenuOptionBuilder().setLabel("No role menu pages").setValue("none"));
} else { } else {
page = Math.min(page, Object.keys(currentObject).length - 1); page = Math.max(Math.min(page, currentObject.length - 1), 0);
current = currentObject[page]!; current = currentObject[page]!;
embed.setDescription( embed.setDescription(
`**Currently Editing:** ${current.name}\n\n` + `**Currently Editing:** ${current.name}\n\n` +

@ -19,21 +19,23 @@ import { Embed } from "../utils/defaults.js";
export default async (guild: Guild | null, interaction?: CommandInteraction) => { export default async (guild: Guild | null, interaction?: CommandInteraction) => {
let m: Message; let m: Message;
if (guild) { if (guild) {
let c: GuildTextBasedChannel | null = guild.publicUpdatesChannel ? guild.publicUpdatesChannel : guild.systemChannel; let c: GuildTextBasedChannel | null = guild.publicUpdatesChannel
? guild.publicUpdatesChannel
: guild.systemChannel;
c = c c = c
? c ? c
: (guild.channels.cache.find( : (guild.channels.cache.find(
(ch) => (ch) =>
[ [
ChannelType.GuildText, ChannelType.GuildText,
ChannelType.GuildAnnouncement, ChannelType.GuildAnnouncement,
ChannelType.PublicThread, ChannelType.PublicThread,
ChannelType.PrivateThread, ChannelType.PrivateThread,
ChannelType.AnnouncementThread ChannelType.AnnouncementThread
].includes(ch.type) && ].includes(ch.type) &&
ch.permissionsFor(guild.roles.everyone).has("SendMessages") && ch.permissionsFor(guild.roles.everyone).has("SendMessages") &&
ch.permissionsFor(guild.members.me!).has("EmbedLinks") ch.permissionsFor(guild.members.me!).has("EmbedLinks")
) as GuildTextBasedChannel | undefined) ?? null; ) as GuildTextBasedChannel | undefined) ?? null;
if (interaction) c = interaction.channel as GuildTextBasedChannel; if (interaction) c = interaction.channel as GuildTextBasedChannel;
if (!c) { if (!c) {
return; return;

@ -226,7 +226,8 @@ class confirmationMessage {
try { try {
component = await m.awaitMessageComponent({ component = await m.awaitMessageComponent({
filter: (i) => filter: (i) =>
i.user.id === this.interaction.user.id && (i.channel ? (i.channel!.id === this.interaction.channel!.id) : true), i.user.id === this.interaction.user.id &&
(i.channel ? i.channel!.id === this.interaction.channel!.id : true),
time: 300000 time: 300000
}); });
} catch (e) { } catch (e) {

@ -54,7 +54,7 @@ function defaultInteractionFilter(i: MessageComponentInteraction, user: User, m:
return i.channel!.id === m.channel!.id && i.user.id === user.id; return i.channel!.id === m.channel!.id && i.user.id === user.id;
} }
function defaultModalFilter(i: ModalSubmitInteraction, user: User, m: Message) { function defaultModalFilter(i: ModalSubmitInteraction, user: User, m: Message) {
return (i.channel ? (i.channel!.id === m.channel!.id) : true) && i.user.id === user.id; return (i.channel ? i.channel!.id === m.channel!.id : true) && i.user.id === user.id;
} }
export async function modalInteractionCollector( export async function modalInteractionCollector(

Loading…
Cancel
Save