Working on viewas
diff --git a/src/commands/mod/info.ts b/src/commands/mod/about.ts
similarity index 98%
rename from src/commands/mod/info.ts
rename to src/commands/mod/about.ts
index fac87a0..c69f4a9 100644
--- a/src/commands/mod/info.ts
+++ b/src/commands/mod/about.ts
@@ -1,4 +1,4 @@
-import { LoadingEmbed } from './../../utils/defaultEmbeds.js';
+import { LoadingEmbed } from '../../utils/defaultEmbeds.js';
import type { HistorySchema } from "../../utils/database.js";
import Discord, {
CommandInteraction,
@@ -22,8 +22,8 @@
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
- .setName("info")
- // .setNameLocalizations({"ru": "about", "zh-CN": "history", "zh-TW": "notes", "pt-BR": "flags"})
+ .setName("about")
+ // .setNameLocalizations({"ru": "info", "zh-CN": "history", "zh-TW": "notes", "pt-BR": "flags"})
.setDescription("Shows moderator information about a user")
.addUserOption((option) =>
option.setName("user").setDescription("The user to get information about").setRequired(true)
diff --git a/src/commands/mod/ban.ts b/src/commands/mod/ban.ts
index ba60d1e..330edfd 100644
--- a/src/commands/mod/ban.ts
+++ b/src/commands/mod/ban.ts
@@ -59,6 +59,7 @@
)
.setColor("Danger")
.addReasonButton(reason ?? "")
+ .setFailedMessage("No changes were made", "Success", "PUNISH.BAN.GREEN")
.send(reason !== null);
reason = reason ?? "";
if (confirmation.cancelled) timedOut = true;
@@ -66,116 +67,103 @@
else if (confirmation.newReason) reason = confirmation.newReason;
else if (confirmation.components) notify = confirmation.components["notify"]!.active;
} while (!timedOut && !chosen)
- if (timedOut) return;
- if (confirmation.success) {
- reason = reason.length ? reason : null
- let dmSent = false;
- let dmMessage;
- const config = await client.database.guilds.read(interaction.guild.id);
- try {
- if (notify) {
- if (reason) { reason = reason.split("\n").map((line) => "> " + line).join("\n") }
- const messageData: {
- embeds: EmojiEmbed[];
- components: ActionRowBuilder<ButtonBuilder>[];
- } = {
- embeds: [
- new EmojiEmbed()
- .setEmoji("PUNISH.BAN.RED")
- .setTitle("Banned")
- .setDescription(
- `You have been banned in ${interaction.guild.name}` +
- (reason ? ` for:\n${reason}` : ".\n*No reason was provided.*")
- )
- .setStatus("Danger")
- ],
- components: []
- };
- if (config.moderation.ban.text && config.moderation.ban.link) {
- messageData.embeds[0]!.setFooter(LinkWarningFooter)
- messageData.components.push(new ActionRowBuilder<Discord.ButtonBuilder>()
- .addComponents(new ButtonBuilder()
- .setStyle(ButtonStyle.Link)
- .setLabel(config.moderation.ban.text)
- .setURL(config.moderation.ban.link)
- )
- )
- }
- dmMessage = await (interaction.options.getMember("user") as GuildMember).send(messageData);
- dmSent = true;
- }
- } catch {
- dmSent = false;
- }
- try {
- const member = interaction.options.getMember("user") as GuildMember;
- const days: number = interaction.options.get("delete")?.value as number | null ?? 0;
- member.ban({
- deleteMessageSeconds: days * 24 * 60 * 60,
- reason: reason ?? "*No reason provided*"
- });
- await client.database.history.create("ban", interaction.guild.id, member.user, interaction.user, reason);
- const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
- const data = {
- meta: {
- type: "memberBan",
- displayName: "Member Banned",
- calculateType: "guildMemberPunish",
- color: NucleusColors.red,
- emoji: "PUNISH.BAN.RED",
- timestamp: new Date().getTime()
- },
- list: {
- memberId: entry(member.user.id, `\`${member.user.id}\``),
- name: entry(member.user.id, renderUser(member.user)),
- banned: entry(new Date().getTime().toString(), renderDelta(new Date().getTime())),
- bannedBy: entry(interaction.user.id, renderUser(interaction.user)),
- reason: entry(reason, reason ? `\n> ${reason}` : "*No reason provided.*"),
- accountCreated: entry(member.user.createdAt.toString(), renderDelta(member.user.createdAt.getTime())),
- serverMemberCount: interaction.guild.memberCount
- },
- hidden: {
- guild: interaction.guild.id
- }
- };
- log(data);
- } catch {
- await interaction.editReply({
+ if (timedOut || !confirmation.success) return;
+ reason = reason.length ? reason : null
+ let dmSent = false;
+ let dmMessage;
+ const config = await client.database.guilds.read(interaction.guild.id);
+ try {
+ if (notify) {
+ if (reason) { reason = reason.split("\n").map((line) => "> " + line).join("\n") }
+ const messageData: {
+ embeds: EmojiEmbed[];
+ components: ActionRowBuilder<ButtonBuilder>[];
+ } = {
embeds: [
new EmojiEmbed()
.setEmoji("PUNISH.BAN.RED")
- .setTitle("Ban")
- .setDescription("Something went wrong and the user was not banned")
+ .setTitle("Banned")
+ .setDescription(
+ `You have been banned in ${interaction.guild.name}` +
+ (reason ? ` for:\n${reason}` : ".\n*No reason was provided.*")
+ )
.setStatus("Danger")
],
components: []
- });
- if (dmSent && dmMessage) await dmMessage.delete();
- return;
+ };
+ if (config.moderation.ban.text && config.moderation.ban.link) {
+ messageData.embeds[0]!.setFooter(LinkWarningFooter)
+ messageData.components.push(new ActionRowBuilder<Discord.ButtonBuilder>()
+ .addComponents(new ButtonBuilder()
+ .setStyle(ButtonStyle.Link)
+ .setLabel(config.moderation.ban.text)
+ .setURL(config.moderation.ban.link)
+ )
+ )
+ }
+ dmMessage = await (interaction.options.getMember("user") as GuildMember).send(messageData);
+ dmSent = true;
}
- const failed = !dmSent && notify;
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji(`PUNISH.BAN.${failed ? "YELLOW" : "GREEN"}`)
- .setTitle("Ban")
- .setDescription("The member was banned" + (failed ? ", but could not be notified" : ""))
- .setStatus(failed ? "Warning" : "Success")
- ],
- components: []
- });
- } else {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("PUNISH.BAN.GREEN")
- .setTitle("Ban")
- .setDescription("No changes were made")
- .setStatus("Success")
- ],
- components: []
- });
+ } catch {
+ dmSent = false;
}
+ try {
+ const member = interaction.options.getMember("user") as GuildMember;
+ const days: number = interaction.options.get("delete")?.value as number | null ?? 0;
+ member.ban({
+ deleteMessageSeconds: days * 24 * 60 * 60,
+ reason: reason ?? "*No reason provided*"
+ });
+ await client.database.history.create("ban", interaction.guild.id, member.user, interaction.user, reason);
+ const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ const data = {
+ meta: {
+ type: "memberBan",
+ displayName: "Member Banned",
+ calculateType: "guildMemberPunish",
+ color: NucleusColors.red,
+ emoji: "PUNISH.BAN.RED",
+ timestamp: new Date().getTime()
+ },
+ list: {
+ memberId: entry(member.user.id, `\`${member.user.id}\``),
+ name: entry(member.user.id, renderUser(member.user)),
+ banned: entry(new Date().getTime().toString(), renderDelta(new Date().getTime())),
+ bannedBy: entry(interaction.user.id, renderUser(interaction.user)),
+ reason: entry(reason, reason ? `\n> ${reason}` : "*No reason provided.*"),
+ accountCreated: entry(member.user.createdAt.toString(), renderDelta(member.user.createdAt.getTime())),
+ serverMemberCount: interaction.guild.memberCount
+ },
+ hidden: {
+ guild: interaction.guild.id
+ }
+ };
+ log(data);
+ } catch {
+ await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("PUNISH.BAN.RED")
+ .setTitle("Ban")
+ .setDescription("Something went wrong and the user was not banned")
+ .setStatus("Danger")
+ ],
+ components: []
+ });
+ if (dmSent && dmMessage) await dmMessage.delete();
+ return;
+ }
+ const failed = !dmSent && notify;
+ await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji(`PUNISH.BAN.${failed ? "YELLOW" : "GREEN"}`)
+ .setTitle("Ban")
+ .setDescription("The member was banned" + (failed ? ", but could not be notified" : ""))
+ .setStatus(failed ? "Warning" : "Success")
+ ],
+ components: []
+ });
};
const check = async (interaction: CommandInteraction) => {
diff --git a/src/commands/mod/kick.ts b/src/commands/mod/kick.ts
index 88b6e14..a4b9774 100644
--- a/src/commands/mod/kick.ts
+++ b/src/commands/mod/kick.ts
@@ -47,6 +47,7 @@
notify
)
.addReasonButton(reason ?? "")
+ .setFailedMessage("No changes were made", "Success", "PUNISH.KICK.GREEN")
.send(reason !== null);
reason = reason ?? "";
if (confirmation.cancelled) timedOut = true;
@@ -56,20 +57,7 @@
notify = confirmation.components["notify"]!.active;
}
} while (!timedOut && !success)
- if (timedOut) return;
- if (!confirmation.success) {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("PUNISH.KICK.GREEN")
- .setTitle("Kick")
- .setDescription("No changes were made")
- .setStatus("Success")
- ],
- components: []
- });
- return;
- }
+ if (timedOut || !confirmation.success) return;
let dmSent = false;
let dmMessage;
const config = await client.database.guilds.read(interaction.guild.id);
diff --git a/src/commands/mod/mute.ts b/src/commands/mod/mute.ts
index d68272b..b558e87 100644
--- a/src/commands/mod/mute.ts
+++ b/src/commands/mod/mute.ts
@@ -207,6 +207,7 @@
notify
)
.addReasonButton(reason ?? "")
+ .setFailedMessage("No changes were made", "Success", "PUNISH.MUTE.GREEN")
.send(true);
reason = reason ?? "";
if (confirmation.cancelled) timedOut = true;
@@ -217,20 +218,7 @@
createAppealTicket = confirmation.components["appeal"]!.active;
}
} while (!timedOut && !success)
- if (timedOut) return;
- if (!confirmation.success) {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("PUNISH.BAN.GREEN")
- .setTitle("Softban")
- .setDescription("No changes were made")
- .setStatus("Success")
- ],
- components: []
- });
- return;
- }
+ if (timedOut || !confirmation.success) return;
const status: {timeout: boolean | null, role: boolean | null, dm: boolean | null} = {timeout: null, role: null, dm: null};
let dmMessage;
try {
diff --git a/src/commands/mod/nick.ts b/src/commands/mod/nick.ts
index 81935a2..c5e45b6 100644
--- a/src/commands/mod/nick.ts
+++ b/src/commands/mod/nick.ts
@@ -169,22 +169,22 @@
const check = (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember;
- const me = interaction.guild.me!;
+ const me = interaction.guild!.members.me!;
const apply = interaction.options.getMember("user") as GuildMember;
- if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles.cache.size ? member.roles.highest.position : 0;
const mePos = me.roles.cache.size ? me.roles.highest.position : 0;
const applyPos = apply.roles.cache.size ? apply.roles.highest.position : 0;
+ if (!interaction.guild) return false;
// Do not allow any changing of the owner
if (member.id === interaction.guild.ownerId) throw new Error("You cannot change the owner's nickname");
// Check if Nucleus can change the nickname
if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to change the nickname
- if (!me.permissions.has("MANAGE_NICKNAMES")) throw new Error("I do not have the *Manage Nicknames* permission");
+ if (!me.permissions.has("ManageNicknames")) throw new Error("I do not have the *Manage Nicknames* permission");
// Allow the owner to change anyone's nickname
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has manage_nicknames permission
- if (!member.permissions.has("MANAGE_NICKNAMES"))
+ if (!member.permissions.has("ManageNicknames"))
throw new Error("You do not have the *Manage Nicknames* permission");
// Allow changing your own nickname
if (member === apply) return true;
diff --git a/src/commands/mod/purge.ts b/src/commands/mod/purge.ts
index 3020eb8..5425714 100644
--- a/src/commands/mod/purge.ts
+++ b/src/commands/mod/purge.ts
@@ -240,113 +240,153 @@
})
)
.setColor("Danger")
+ .setFailedMessage("No changes were made", "Success", "CHANNEL.PURGE.GREEN")
.send();
- if (confirmation.cancelled) return;
- if (confirmation.success) {
- let messages;
- try {
- if (!user) {
- const toDelete = await (interaction.channel as TextChannel).messages.fetch({
- limit: interaction.options.get("amount")?.value as number
- });
- messages = await (channel as TextChannel).bulkDelete(toDelete, true);
- } else {
- const toDelete = (
- await (
- await (interaction.channel as TextChannel).messages.fetch({
- limit: 100
- })
- ).filter((m) => m.author.id === user.id)
- ).first(interaction.options.get("amount")?.value as number);
- messages = await (channel as TextChannel).bulkDelete(toDelete, true);
- }
- } catch (e) {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.RED")
- .setTitle("Purge")
- .setDescription("Something went wrong and no messages were deleted")
- .setStatus("Danger")
- ],
- components: []
+ if (confirmation.cancelled || !confirmation.success) return;
+ let messages;
+ try {
+ if (!user) {
+ const toDelete = await (interaction.channel as TextChannel).messages.fetch({
+ limit: interaction.options.get("amount")?.value as number
});
+ messages = await (channel as TextChannel).bulkDelete(toDelete, true);
+ } else {
+ const toDelete = (
+ await (
+ await (interaction.channel as TextChannel).messages.fetch({
+ limit: 100
+ })
+ ).filter((m) => m.author.id === user.id)
+ ).first(interaction.options.get("amount")?.value as number);
+ messages = await (channel as TextChannel).bulkDelete(toDelete, true);
}
- if (!messages) {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.RED")
- .setTitle("Purge")
- .setDescription("No messages could be deleted")
- .setStatus("Danger")
- ],
- components: []
- });
- return;
- }
- if (user) {
- await client.database.history.create(
- "purge",
- interaction.guild.id,
- user.user,
- interaction.user,
- (interaction.options.get("reason")?.value as (string | null)) ?? "*No reason provided*",
- null,
- null,
- messages.size.toString()
- );
- }
- const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
- const data = {
- meta: {
- type: "channelPurge",
- displayName: "Channel Purged",
- calculateType: "messageDelete",
- color: NucleusColors.red,
- emoji: "PUNISH.BAN.RED",
- timestamp: new Date().getTime()
- },
- list: {
- memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
- purgedBy: entry(interaction.user.id, renderUser(interaction.user)),
- channel: entry(interaction.channel!.id, renderChannel(interaction.channel! as GuildChannel)),
- messagesCleared: entry(messages.size.toString(), messages.size.toString())
- },
- hidden: {
- guild: interaction.guild.id
- }
- };
- log(data);
- let out = "";
- messages.reverse().forEach((message) => {
- if (!message) {
- out += "Unknown message\n\n"
- } else {
- const author = message.author ?? { username: "Unknown", discriminator: "0000", id: "Unknown" };
- out += `${author.username}#${author.discriminator} (${author.id}) [${new Date(
- message.createdTimestamp
- ).toISOString()}]\n`;
- if (message.content) {
- const lines = message.content.split("\n");
- lines.forEach((line) => {
- out += `> ${line}\n`;
- });
- }
- if (message.attachments.size > 0) {
- message.attachments.forEach((attachment) => {
- out += `Attachment > ${attachment.url}\n`;
- });
- }
- out += "\n\n";
- }
+ } catch (e) {
+ await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.RED")
+ .setTitle("Purge")
+ .setDescription("Something went wrong and no messages were deleted")
+ .setStatus("Danger")
+ ],
+ components: []
});
- const attachmentObject = {
- attachment: Buffer.from(out),
- name: `purge-${channel.id}-${Date.now()}.txt`,
- description: "Purge log"
- };
- const m = (await interaction.editReply({
+ }
+ if (!messages) {
+ await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.RED")
+ .setTitle("Purge")
+ .setDescription("No messages could be deleted")
+ .setStatus("Danger")
+ ],
+ components: []
+ });
+ return;
+ }
+ if (user) {
+ await client.database.history.create(
+ "purge",
+ interaction.guild.id,
+ user.user,
+ interaction.user,
+ (interaction.options.get("reason")?.value as (string | null)) ?? "*No reason provided*",
+ null,
+ null,
+ messages.size.toString()
+ );
+ }
+ const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
+ const data = {
+ meta: {
+ type: "channelPurge",
+ displayName: "Channel Purged",
+ calculateType: "messageDelete",
+ color: NucleusColors.red,
+ emoji: "PUNISH.BAN.RED",
+ timestamp: new Date().getTime()
+ },
+ list: {
+ memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
+ purgedBy: entry(interaction.user.id, renderUser(interaction.user)),
+ channel: entry(interaction.channel!.id, renderChannel(interaction.channel! as GuildChannel)),
+ messagesCleared: entry(messages.size.toString(), messages.size.toString())
+ },
+ hidden: {
+ guild: interaction.guild.id
+ }
+ };
+ log(data);
+ let out = "";
+ messages.reverse().forEach((message) => {
+ if (!message) {
+ out += "Unknown message\n\n"
+ } else {
+ const author = message.author ?? { username: "Unknown", discriminator: "0000", id: "Unknown" };
+ out += `${author.username}#${author.discriminator} (${author.id}) [${new Date(
+ message.createdTimestamp
+ ).toISOString()}]\n`;
+ if (message.content) {
+ const lines = message.content.split("\n");
+ lines.forEach((line) => {
+ out += `> ${line}\n`;
+ });
+ }
+ if (message.attachments.size > 0) {
+ message.attachments.forEach((attachment) => {
+ out += `Attachment > ${attachment.url}\n`;
+ });
+ }
+ out += "\n\n";
+ }
+ });
+ const attachmentObject = {
+ attachment: Buffer.from(out),
+ name: `purge-${channel.id}-${Date.now()}.txt`,
+ description: "Purge log"
+ };
+ const m = (await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.GREEN")
+ .setTitle("Purge")
+ .setDescription("Messages cleared")
+ .setStatus("Success")
+ ],
+ components: [
+ new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
+ new Discord.ButtonBuilder()
+ .setCustomId("download")
+ .setLabel("Download transcript")
+ .setStyle(ButtonStyle.Success)
+ .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
+ ])
+ ]
+ })) as Discord.Message;
+ let component;
+ try {
+ component = await m.awaitMessageComponent({
+ filter: (m) => m.user.id === interaction.user.id,
+ time: 300000
+ });
+ } catch {
+ return;
+ }
+ if (component.customId === "download") {
+ interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.GREEN")
+ .setTitle("Purge")
+ .setDescription("Transcript uploaded above")
+ .setStatus("Success")
+ ],
+ components: [],
+ files: [attachmentObject]
+ });
+ } else {
+ interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
@@ -354,58 +394,6 @@
.setDescription("Messages cleared")
.setStatus("Success")
],
- components: [
- new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
- new Discord.ButtonBuilder()
- .setCustomId("download")
- .setLabel("Download transcript")
- .setStyle(ButtonStyle.Success)
- .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
- ])
- ]
- })) as Discord.Message;
- let component;
- try {
- component = await m.awaitMessageComponent({
- filter: (m) => m.user.id === interaction.user.id,
- time: 300000
- });
- } catch {
- return;
- }
- if (component.customId === "download") {
- interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle("Purge")
- .setDescription("Transcript uploaded above")
- .setStatus("Success")
- ],
- components: [],
- files: [attachmentObject]
- });
- } else {
- interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle("Purge")
- .setDescription("Messages cleared")
- .setStatus("Success")
- ],
- components: []
- });
- }
- } else {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle("Purge")
- .setDescription("No changes were made")
- .setStatus("Success")
- ],
components: []
});
}
diff --git a/src/commands/mod/slowmode.ts b/src/commands/mod/slowmode.ts
index b565deb..9bd994d 100644
--- a/src/commands/mod/slowmode.ts
+++ b/src/commands/mod/slowmode.ts
@@ -47,45 +47,33 @@
}) + "Are you sure you want to set the slowmode in this channel?"
)
.setColor("Danger")
+ .setFailedMessage("No changes were made", "Danger", "CHANNEL.SLOWMODE.ON")
.send();
- if (confirmation.cancelled) return;
- if (confirmation.success) {
- try {
- (interaction.channel as TextChannel).setRateLimitPerUser(time);
- } catch (e) {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.SLOWMODE.OFF")
- .setTitle("Slowmode")
- .setDescription("Something went wrong while setting the slowmode")
- .setStatus("Danger")
- ],
- components: []
- });
- }
+ if (confirmation.cancelled || !confirmation.success) return;
+ try {
+ (interaction.channel as TextChannel).setRateLimitPerUser(time);
+ } catch (e) {
await interaction.editReply({
embeds: [
new EmojiEmbed()
- .setEmoji("CHANNEL.SLOWMODE.ON")
+ .setEmoji("CHANNEL.SLOWMODE.OFF")
.setTitle("Slowmode")
- .setDescription("The channel slowmode was set successfully")
- .setStatus("Success")
- ],
- components: []
- });
- } else {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.SLOWMODE.ON")
- .setTitle("Slowmode")
- .setDescription("No changes were made")
- .setStatus("Success")
+ .setDescription("Something went wrong while setting the slowmode")
+ .setStatus("Danger")
],
components: []
});
}
+ await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.SLOWMODE.ON")
+ .setTitle("Slowmode")
+ .setDescription("The channel slowmode was set successfully")
+ .setStatus("Success")
+ ],
+ components: []
+ });
};
const check = (interaction: CommandInteraction) => {
diff --git a/src/commands/mod/viewas.ts b/src/commands/mod/viewas.ts
index a713f55..8b2864a 100644
--- a/src/commands/mod/viewas.ts
+++ b/src/commands/mod/viewas.ts
@@ -1,13 +1,13 @@
import Discord, {
- CategoryChannel,
CommandInteraction,
GuildMember,
ActionRowBuilder,
ButtonBuilder,
- SelectMenuBuilder,
- ButtonStyle
+ ButtonStyle,
+ NonThreadGuildBasedChannel
} from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import type { GuildBasedChannel } from "discord.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import getEmojiByName from "../../utils/getEmojiByName.js";
import pageIndicator from "../../utils/createPageIndicator.js";
@@ -19,145 +19,185 @@
.addUserOption((option) => option.setName("member").setDescription("The member to view as").setRequired(true));
const callback = async (interaction: CommandInteraction): Promise<void> => {
- let channels = [];
- let m;
- interaction.guild.channels.cache.forEach((channel) => {
- if (!channel.parent && channel.type !== "GUILD_CATEGORY") channels.push(channel);
+ /*
+ * {
+ categoryObject: channel[],
+ categoryObject: channel[],
+ "null": channel[]
+ }
+ */
+
+ const channels: Record<string, GuildBasedChannel[]> = {"": [] as GuildBasedChannel[]};
+
+ interaction.guild!.channels.fetch().then(channelCollection => {
+ channelCollection.forEach(channel => {
+ if (!channel) return; // if no channel
+ if (channel.type === Discord.ChannelType.GuildCategory) {
+ if(!channels[channel!.id]) channels[channel!.id] = [channel];
+ } else if (channel.parent) {
+ if (!channels[channel.parent.id]) channels[channel.parent.id] = [channel];
+ else (channels[channel.parent.id as string])!.push(channel);
+ } else {
+ channels[""]!.push(channel);
+ }
+ });
});
- channels = [channels];
- channels = channels.concat(
- interaction.guild.channels.cache
- .filter((c) => c.type === "GUILD_CATEGORY")
- .map((c) => (c as CategoryChannel).children.map((c) => c))
- );
- const autoSortBelow = ["GUILD_VOICE", "GUILD_STAGE_VOICE"];
- channels = channels.map((c) =>
- c.sort((a, b) => {
- if (autoSortBelow.includes(a.type) && autoSortBelow.includes(b.type)) return a.position - b.position;
+
+ const member = interaction.options.getMember("member") as Discord.GuildMember;
+ const autoSortBelow = [Discord.ChannelType.GuildVoice, Discord.ChannelType.GuildStageVoice];
+ // for each category, sort its channels. This should be based on the order of the channels, with voice and stage channels sorted below text
+ channels = Object.values(channels).map((c) => {
+ return c.sort((a: GuildBasedChannel, b: GuildBasedChannel) => {
+ if (a.type === Discord.ChannelType.PrivateThread || b.type === Discord.ChannelType.PrivateThread)
+ if (autoSortBelow.includes(a.type) && autoSortBelow.includes(b.type)) return a.position ?? 0 - b.position ;
if (autoSortBelow.includes(a.type)) return 1;
if (autoSortBelow.includes(b.type)) return -1;
- return a.position - b.position;
- })
- );
- // Sort all arrays by the position of the first channels parent position
- channels = channels.sort((a, b) => {
- if (!a[0].parent) return -1;
- if (!b[0].parent) return 1;
- return a[0].parent.position - b[0].parent.position;
- });
- const member = interaction.options.getMember("member") as Discord.GuildMember;
- m = await interaction.reply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("MEMBER.JOIN")
- .setTitle("Viewing as " + member.displayName)
- .setStatus("Success")
- ],
- ephemeral: true,
- fetchReply: true
- });
- let page = 0;
- let timedOut = false;
- while (!timedOut) {
- m = await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("MEMBER.JOIN")
- .setTitle("Viewing as " + member.displayName)
- .setStatus("Success")
- .setDescription(
- `**${channels[page][0].parent ? channels[page][0].parent.name : "Uncategorised"}**` +
- "\n" +
- channels[page]
- .map((c) => {
- let channelType = c.type;
- if (interaction.guild.rulesChannelId === c.id) channelType = "RULES";
- else if ("nsfw" in c && c.nsfw) channelType += "_NSFW";
- return c.permissionsFor(member).has("VIEW_CHANNEL")
- ? `${getEmojiByName("ICONS.CHANNEL." + channelType)} ${c.name}\n` +
- (() => {
- if ("threads" in c && c.threads.cache.size > 0) {
- return (
- c.threads.cache
- .map(
- (t) =>
- ` ${
- getEmojiByName("ICONS.CHANNEL.THREAD_PIPE") +
- " " +
- getEmojiByName("ICONS.CHANNEL.THREAD_CHANNEL")
- } ${t.name}`
- )
- .join("\n") + "\n"
- );
- }
- return "";
- })()
- : "";
- })
- .join("") +
- "\n" +
- pageIndicator(channels.length, page)
- )
- ],
- components: [
- new ActionRowBuilder().addComponents([
- new SelectMenuBuilder()
- .setOptions(
- channels.map((c, index) => ({
- label: c[0].parent ? c[0].parent.name : "Uncategorised",
- value: index.toString(),
- default: page === index
- }))
- )
- .setCustomId("select")
- .setMaxValues(1)
- .setMinValues(1)
- .setPlaceholder("Select a category")
- ]),
- new ActionRowBuilder().addComponents([
- new ButtonBuilder()
- .setLabel(
- page === 0
- ? ""
- : channels[page - 1][0].parent
- ? channels[page - 1][0].parent.name
- : "Uncategorised"
- )
- .setDisabled(page === 0)
- .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
- .setStyle(ButtonStyle.Primary)
- .setCustomId("previous"),
- new ButtonBuilder()
- .setLabel(
- page === channels.length - 1
- ? ""
- : channels[page + 1][0].parent
- ? channels[page + 1][0].parent.name
- : "Uncategorised"
- )
- .setDisabled(page === channels.length - 1)
- .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
- .setStyle(ButtonStyle.Primary)
- .setCustomId("next")
- ])
- ]
+ return a - b;
});
- let i;
- try {
- i = await m.awaitMessageComponent({ time: 300000 });
- } catch (e) {
- timedOut = true;
- continue;
- }
- i.deferUpdate();
- if (i.customId === "next") {
- page++;
- } else if (i.customId === "previous") {
- page--;
- } else if (i.customId === "select") {
- page = parseInt(i.values[0]);
- }
}
+
+
+ //OLD CODE START
+ // const unprocessedChannels: GuildBasedChannel[] = [];
+ // let m;
+ // interaction.guild!.channels.cache.forEach((channel) => {
+ // if (!channel.parent && channel.type !== Discord.ChannelType.GuildCategory) unprocessedChannels.push(channel);
+ // });
+ // let channels: GuildBasedChannel[][] = [unprocessedChannels];
+ // channels = channels.concat(
+ // interaction.guild!.channels.cache
+ // .filter((c) => c.type === Discord.ChannelType.GuildCategory)
+ // .map((c) => (c as CategoryChannel).children.map((c) => c))
+ // );
+ // const autoSortBelow = ["GUILD_VOICE", "GUILD_STAGE_VOICE"];
+ // channels = channels.map((c) =>
+ // c.sort((a, b) => {
+ // if (autoSortBelow.includes(a.type) && autoSortBelow.includes(b.type)) return a.position - b.position;
+ // if (autoSortBelow.includes(a.type)) return 1;
+ // if (autoSortBelow.includes(b.type)) return -1;
+ // return a.position - b.position;
+ // })
+ // );
+ // // Sort all arrays by the position of the first channels parent position
+ // channels = channels.sort((a, b) => {
+ // if (!a[0].parent) return -1;
+ // if (!b[0].parent) return 1;
+ // return a[0].parent.position - b[0].parent.position;
+ // });
+ // const member = interaction.options.getMember("member") as Discord.GuildMember;
+ // m = await interaction.reply({
+ // embeds: [
+ // new EmojiEmbed()
+ // .setEmoji("MEMBER.JOIN")
+ // .setTitle("Viewing as " + member.displayName)
+ // .setStatus("Success")
+ // ],
+ // ephemeral: true,
+ // fetchReply: true
+ // });
+ // let page = 0;
+ // let timedOut = false;
+ // while (!timedOut) {
+ // m = await interaction.editReply({
+ // embeds: [
+ // new EmojiEmbed()
+ // .setEmoji("MEMBER.JOIN")
+ // .setTitle("Viewing as " + member.displayName)
+ // .setStatus("Success")
+ // .setDescription(
+ // `**${channels[page][0].parent ? channels[page][0].parent.name : "Uncategorised"}**` +
+ // "\n" +
+ // channels[page]
+ // .map((c) => {
+ // let channelType = c.type;
+ // if (interaction.guild.rulesChannelId === c.id) channelType = "RULES";
+ // else if ("nsfw" in c && c.nsfw) channelType += "_NSFW";
+ // return c.permissionsFor(member).has("VIEW_CHANNEL")
+ // ? `${getEmojiByName("ICONS.CHANNEL." + channelType)} ${c.name}\n` +
+ // (() => {
+ // if ("threads" in c && c.threads.cache.size > 0) {
+ // return (
+ // c.threads.cache
+ // .map(
+ // (t) =>
+ // ` ${
+ // getEmojiByName("ICONS.CHANNEL.THREAD_PIPE") +
+ // " " +
+ // getEmojiByName("ICONS.CHANNEL.THREAD_CHANNEL")
+ // } ${t.name}`
+ // )
+ // .join("\n") + "\n"
+ // );
+ // }
+ // return "";
+ // })()
+ // : "";
+ // })
+ // .join("") +
+ // "\n" +
+ // pageIndicator(channels.length, page)
+ // )
+ // ],
+ // components: [
+ // new ActionRowBuilder().addComponents([
+ // new SelectMenuBuilder()
+ // .setOptions(
+ // channels.map((c, index) => ({
+ // label: c[0].parent ? c[0].parent.name : "Uncategorised",
+ // value: index.toString(),
+ // default: page === index
+ // }))
+ // )
+ // .setCustomId("select")
+ // .setMaxValues(1)
+ // .setMinValues(1)
+ // .setPlaceholder("Select a category")
+ // ]),
+ // new ActionRowBuilder().addComponents([
+ // new ButtonBuilder()
+ // .setLabel(
+ // page === 0
+ // ? ""
+ // : channels[page - 1][0].parent
+ // ? channels[page - 1][0].parent.name
+ // : "Uncategorised"
+ // )
+ // .setDisabled(page === 0)
+ // .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
+ // .setStyle(ButtonStyle.Primary)
+ // .setCustomId("previous"),
+ // new ButtonBuilder()
+ // .setLabel(
+ // page === channels.length - 1
+ // ? ""
+ // : channels[page + 1][0].parent
+ // ? channels[page + 1][0].parent.name
+ // : "Uncategorised"
+ // )
+ // .setDisabled(page === channels.length - 1)
+ // .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
+ // .setStyle(ButtonStyle.Primary)
+ // .setCustomId("next")
+ // ])
+ // ]
+ // });
+ // let i;
+ // try {
+ // i = await m.awaitMessageComponent({ time: 300000 });
+ // } catch (e) {
+ // timedOut = true;
+ // continue;
+ // }
+ // i.deferUpdate();
+ // if (i.customId === "next") {
+ // page++;
+ // } else if (i.customId === "previous") {
+ // page--;
+ // } else if (i.customId === "select") {
+ // page = parseInt(i.values[0]);
+ // }
+ // }
+
};
const check = (interaction: CommandInteraction) => {
diff --git a/src/commands/mod/warn.ts b/src/commands/mod/warn.ts
index d920bb0..c4aa7c3 100644
--- a/src/commands/mod/warn.ts
+++ b/src/commands/mod/warn.ts
@@ -56,6 +56,7 @@
notify
)
.addReasonButton(reason ?? "")
+ .setFailedMessage("No changes were made", "Success", "PUNISH.WARN.GREEN")
.send(reason !== null);
reason = reason ?? "";
if (confirmation.cancelled) timedOut = true;
@@ -66,20 +67,7 @@
createAppealTicket = confirmation.components["appeal"]!.active;
}
} while (!timedOut && !success)
- if (timedOut) return;
- if (!confirmation.success) {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("PUNISH.WARN.GREEN")
- .setTitle("Warn")
- .setDescription("No changes were made")
- .setStatus("Success")
- ],
- components: []
- });
- return;
- }
+ if (timedOut || !confirmation.success) return;
let dmSent = false;
const config = await client.database.guilds.read(interaction.guild.id);
try {