Development (#29)
diff --git a/src/actions/roleMenu.ts b/src/actions/roleMenu.ts
index 8b15539..27b5f07 100644
--- a/src/actions/roleMenu.ts
+++ b/src/actions/roleMenu.ts
@@ -79,7 +79,7 @@
"Self roles are currently disabled. Please contact a staff member or try again later."
)
.setStatus("Danger")
- .setEmoji("GUILD.GREEN")
+ .setEmoji("GUILD.RED")
],
ephemeral: true
});
@@ -92,7 +92,7 @@
"There are no roles available. Please contact a staff member if you believe this is a mistake."
)
.setStatus("Danger")
- .setEmoji("GUILD.GREEN")
+ .setEmoji("GUILD.RED")
],
ephemeral: true
});
diff --git a/src/api/index.ts b/src/api/index.ts
index f8873f0..c37b25d 100644
--- a/src/api/index.ts
+++ b/src/api/index.ts
@@ -14,7 +14,7 @@
const runServer = (client: NucleusClient) => {
app.get("/", (_req: express.Request, res: express.Response) => {
- res.status(200).send(client.ws.ping);
+ res.status(200).send(client.ws.ping.toString());
});
app.post("/verify/:code", jsonParser, async function (req: express.Request, res: express.Response) {
diff --git a/src/commands/nucleus/premium.ts b/src/commands/nucleus/premium.ts
index 721bc5c..0b0f553 100644
--- a/src/commands/nucleus/premium.ts
+++ b/src/commands/nucleus/premium.ts
@@ -93,7 +93,7 @@
if (i.isButton()) {
closed = true;
} else {
- const response = client.database.premium.removePremium(interaction.user.id, i.values[0]!);
+ const response = await client.database.premium.removePremium(interaction.user.id, i.values[0]!);
console.log(response);
}
} while (!closed);
@@ -163,9 +163,10 @@
const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
let premiumGuild = "";
if (hasPremium) {
+ const gaveUser = await client.users.fetch(hasPremium[1]);
premiumGuild = `**This server has premium! It was ${
hasPremium[2] === 3 && hasPremium[3]
- ? `automatically applied by <@${hasPremium[1]}>`
+ ? `automatically applied by ${gaveUser.username}#${gaveUser.discriminator}`
: `given by <@${hasPremium[1]}>`
}**\n\n`;
}
@@ -192,6 +193,9 @@
);
}
+ let userPremiumServers;
+ if ((dbMember?.appliesTo.length ?? 0) > 0) userPremiumServers = "\nIf you want to remove premium from a server, run this command in your DMs with me.";
+
interaction.editReply({
embeds: [
new EmojiEmbed()
@@ -219,7 +223,7 @@
new EmojiEmbed()
.setTitle("Premium")
.setDescription(
- `You have already activated premium on the maximum amount of servers!` + firstDescription
+ `You have already activated premium on the maximum amount of servers!` + userPremiumServers + firstDescription
)
.setEmoji("NUCLEUS.PREMIUMACTIVATE")
.setStatus("Danger")
@@ -232,7 +236,7 @@
embeds: [
new EmojiEmbed()
.setTitle("Premium")
- .setDescription(`You have activated premium on this server!` + firstDescription)
+ .setDescription(`You have activated premium on this server!` + userPremiumServers + firstDescription)
.setEmoji("NUCLEUS.LOGO")
.setStatus("Danger")
],
diff --git a/src/commands/settings/tracks.ts b/src/commands/settings/tracks.ts
index 20972f4..cbc5f17 100644
--- a/src/commands/settings/tracks.ts
+++ b/src/commands/settings/tracks.ts
@@ -163,7 +163,7 @@
current = {
name: "",
retainPrevious: false,
- nullable: false,
+ nullable: true,
track: [],
manageableBy: []
};
@@ -173,6 +173,7 @@
new RoleSelectMenuBuilder().setCustomId("addRole").setPlaceholder("Select a role to add").setDisabled(!isAdmin)
);
let closed = false;
+ let previousMessage = "";
do {
const editableRoles: string[] = current.track
.map((r) => {
@@ -224,9 +225,9 @@
new ButtonBuilder()
.setCustomId("nullable")
.setLabel(`Role ${current.nullable ? "Not " : ""}Required`)
- .setStyle(current.nullable ? ButtonStyle.Success : ButtonStyle.Danger)
+ .setStyle(current.nullable ? ButtonStyle.Danger : ButtonStyle.Success)
.setEmoji(
- getEmojiByName("CONTROL." + (current.nullable ? "TICK" : "CROSS"), "id") as APIMessageComponentEmoji
+ getEmojiByName("CONTROL." + (current.nullable ? "CROSS" : "TICK"), "id") as APIMessageComponentEmoji
)
);
@@ -247,7 +248,7 @@
}need a role in this track\n` +
`${getEmojiByName("CONTROL." + (current.retainPrevious ? "TICK" : "CROSS"))} Members ${
current.retainPrevious ? "" : "don't "
- }keep all roles below their current highest\n\n` +
+ }keep all roles below their current highest\n\n` + (previousMessage ? previousMessage + "\n\n": "") +
createVerticalTrack(
mapped.map((role) => renderRole(role)),
new Array(current.track.length).fill(false),
@@ -316,13 +317,20 @@
}
}
} else {
+ out.deferUpdate();
switch (out.customId) {
case "addRole": {
const role = out.values![0]!;
- if (!current.track.includes(role)) {
- current.track.push(role);
+ const roleObj = roles.get(role)!;
+ if (roleObj.position >= (interaction.member as GuildMember).roles.highest.position){
+ previousMessage = "You can't add a role that is higher than your highest role.";
} else {
- out.reply({ content: "That role is already on this track", ephemeral: true });
+ if (!current.track.includes(role)) {
+ current.track.push(role);
+ await interaction.editReply({ embeds: LoadingEmbed, components: [] });
+ } else {
+ previousMessage = "That role is already on this track";
+ }
}
break;
}
diff --git a/src/utils/database.ts b/src/utils/database.ts
index 5d86275..b6864b8 100644
--- a/src/utils/database.ts
+++ b/src/utils/database.ts
@@ -804,10 +804,10 @@
return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true });
}
- removePremium(user: string, guild: string) {
+ async removePremium(user: string, guild: string) {
// console.log("Premium removePremium");
this.cache.set(guild, [false, "", 0, false, new Date(Date.now() + this.cacheTimeout)]);
- return this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } });
+ return await this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } });
}
}
diff --git a/src/utils/migration/migration.ts b/src/utils/migration/migration.ts
index 215c7d6..0f54724 100644
--- a/src/utils/migration/migration.ts
+++ b/src/utils/migration/migration.ts
@@ -12,7 +12,7 @@
rsmData = JSON.parse(fs.readFileSync(`${dir}/${file}`, 'utf8'));
} catch { continue }
if (!rsmData.version || rsmData.version < 3) continue;
- const nucleusData = await client.database.guilds.read(rsmData.guild_info.id)
+ const nucleusData = await client.database.guilds.readOld(rsmData.guild_info.id)
const rsmToNucleus = {
id: rsmData.guild_info.id,
version: 1,
@@ -74,6 +74,6 @@
// console.log(rsmToNucleus)
const merged = _.merge(nucleusData, rsmToNucleus);
// console.log(merged)
- await client.database.guilds.write(merged.id, merged);
+ await client.database.guilds.write(merged.id!, merged);
}