fixed /user tracks & /settings tracks. Added presets to /server buttons
diff --git a/src/commands/server/buttons.ts b/src/commands/server/buttons.ts
index 74c255c..c89e481 100644
--- a/src/commands/server/buttons.ts
+++ b/src/commands/server/buttons.ts
@@ -20,6 +20,7 @@
import lodash from "lodash";
import getEmojiByName from "../../utils/getEmojiByName.js";
import { modalInteractionCollector } from "../../utils/dualCollector.js";
+import _ from "lodash";
export const command = new SlashCommandSubcommandBuilder()
.setName("buttons")
@@ -50,6 +51,27 @@
createticket: "Create Ticket"
};
+const presetButtons = [
+ {
+ title: "Verify",
+ description: "Click the button below to get verified in the server.",
+ buttons: ["verifybutton"],
+ color: "GREEN"
+ },
+ {
+ title: "Get Roles",
+ description: "Click the button to choose which roles you would like in the server",
+ buttons: ["rolemenu"],
+ color: "BLUE"
+ },
+ {
+ title: "Create Ticket",
+ description: "Click the button below to create a ticket",
+ buttons: ["createticket"],
+ color: "RED"
+ }
+]
+
export const callback = async (interaction: CommandInteraction): Promise<void> => {
const m = await interaction.reply({
embeds: LoadingEmbed,
@@ -58,7 +80,7 @@
});
let closed = false;
- const data: Data = {
+ let data: Data = {
buttons: [],
title: null,
description: null,
@@ -71,7 +93,7 @@
.setCustomId("edit")
.setLabel("Edit Embed")
.setStyle(ButtonStyle.Secondary)
- .setEmoji(getEmojiByName("ICONS.EDIT") as APIMessageComponentEmoji),
+ .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji),
new ButtonBuilder()
.setCustomId("send")
.setLabel("Send")
@@ -95,6 +117,22 @@
)
);
+ const presetSelect = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
+ new StringSelectMenuBuilder()
+ .setCustomId("preset")
+ .setPlaceholder("Select a preset")
+ .setMaxValues(1)
+ .addOptions(
+ presetButtons.map((preset, i) => {
+ return new StringSelectMenuOptionBuilder()
+ .setLabel(preset.title)
+ .setValue(i.toString())
+ .setDescription(preset.description)
+ .setEmoji(getEmojiByName("COLORS." + preset.color, "id") as APIMessageComponentEmoji)
+ })
+ )
+ )
+
const buttonSelect = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()
.setCustomId("button")
@@ -141,7 +179,7 @@
await interaction.editReply({
embeds: [embed],
- components: [colorSelect, buttonSelect, channelMenu, buttons]
+ components: [presetSelect, colorSelect, buttonSelect, channelMenu, buttons]
});
let i: Discord.ButtonInteraction | Discord.ChannelSelectMenuInteraction | Discord.StringSelectMenuInteraction;
@@ -257,6 +295,12 @@
console.log(err);
}
switch (i.customId) {
+ case "preset": {
+ const chosen = presetButtons[parseInt(i.values[0]!)]!;
+ const newColor = colors[chosen.color!]!
+ data = _.assign(data, chosen, { color: newColor });
+ break;
+ }
case "color": {
data.color = colors[i.values[0]!]!;
break;
diff --git a/src/commands/settings/tracks.ts b/src/commands/settings/tracks.ts
index 60a7eae..c81eeed 100644
--- a/src/commands/settings/tracks.ts
+++ b/src/commands/settings/tracks.ts
@@ -171,6 +171,7 @@
const isAdmin = (interaction.member!.permissions as PermissionsBitField).has("Administrator");
if (!current) {
current = _.cloneDeep(defaultTrackData);
+ current.name = "Default";
}
const roleSelect = new ActionRowBuilder<RoleSelectMenuBuilder>().addComponents(
@@ -348,16 +349,15 @@
const callback = async (interaction: CommandInteraction) => {
const m = await interaction.reply({ embeds: LoadingEmbed, fetchReply: true, ephemeral: true });
const config = await client.database.guilds.read(interaction.guild!.id);
- const tracks: ObjectSchema[] = config.tracks;
+ const tracks: ObjectSchema[] = _.cloneDeep(config.tracks);
const roles = await interaction.guild!.roles.fetch();
let page = 0;
let closed = false;
- let modified = false;
do {
const embed = new EmojiEmbed().setTitle("Track Settings").setEmoji("TRACKS.ICON").setStatus("Success");
- const noTracks = config.tracks.length === 0;
+ const noTracks = tracks.length === 0;
let current: ObjectSchema;
const pageSelect = new StringSelectMenuBuilder().setCustomId("page").setPlaceholder("Select a track to manage");
@@ -398,7 +398,7 @@
.setLabel("Save")
.setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji)
.setStyle(ButtonStyle.Success)
- .setDisabled(!modified)
+ .setDisabled(_.isEqual(tracks, config.tracks))
);
if (noTracks) {
embed.setDescription(
@@ -471,13 +471,15 @@
case "add": {
const newPage = await editTrack(i, m, roles);
if (_.isEqual(newPage, defaultTrackData)) break;
- tracks.push();
+ if(!newPage) break;
+ console.log(newPage)
+ tracks.push(newPage);
+ console.log(tracks)
page = tracks.length - 1;
break;
}
case "save": {
await client.database.guilds.write(interaction.guild!.id, { tracks: tracks });
- modified = false;
await client.memory.forceUpdate(interaction.guild!.id);
break;
}
@@ -490,7 +492,6 @@
const edited = await editTrack(i, m, roles, current!);
if (!edited) break;
tracks[page] = edited;
- modified = true;
break;
}
case "delete": {
diff --git a/src/commands/user/track.ts b/src/commands/user/track.ts
index ee69868..92553ff 100644
--- a/src/commands/user/track.ts
+++ b/src/commands/user/track.ts
@@ -97,7 +97,8 @@
selected.length
} roles from this track. `;
conflictDropdown = [];
- if (roles.get(selected[0]!)!.position < memberRoles.highest.position || managed) {
+ const yourRoles = guild.members.cache.get(interaction.user.id)!.roles;
+ if ((roles.get(selected[0]!)!.position < yourRoles.highest.position && roles.get(selected[0]!)!.position < guild.members.me!.roles.highest.position!) || managed) {
generated +=
"In order to promote or demote this user, you must select which role the member should keep.";
selected.forEach((role) => {
@@ -115,8 +116,13 @@
.setPlaceholder("Select a role to keep")
];
} else {
- generated +=
- "You don't have permission to manage one or more of the users roles, and therefore can't select one to keep.";
+ if(roles.get(selected[0]!)!.position >= yourRoles.highest.position) {
+ generated +=
+ "You don't have permission to manage one or more of the user's roles, and therefore can't select one to keep.";
+ } else {
+ generated +=
+ "I don't have permission to manage one or more of the user's roles, and therefore can't select one to keep."
+ }
}
} else {
currentRoleIndex = selected.length === 0 ? -1 : data.track.indexOf(selected[0]!.toString());
@@ -183,6 +189,7 @@
const rolesToRemove = selected.filter(
(role) => role !== (component as StringSelectMenuInteraction).values[0]
);
+
await member.roles.remove(rolesToRemove);
} else if (component.customId === "promote") {
if (