changes
diff --git a/src/commands/mod/viewas.ts b/src/commands/mod/viewas.ts
index 5f7c7de..705c04a 100644
--- a/src/commands/mod/viewas.ts
+++ b/src/commands/mod/viewas.ts
@@ -1,6 +1,8 @@
-import { CategoryChannel, CommandInteraction } from "discord.js";
+import Discord, { CategoryChannel, CommandInteraction } from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
import { WrappedCheck } from "jshaiku";
+import getEmojiByName from "../../utils/getEmojiByName.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
@@ -8,11 +10,47 @@
.setDescription("View the server as a specific member")
.addUserOption(option => option.setName("member").setDescription("The member to view as").setRequired(true))
-const callback = (interaction: CommandInteraction) => {
- let channels = interaction.guild.channels.cache
+const callback = async (interaction: CommandInteraction) => {
+ let channels = []
+ interaction.guild.channels.cache.forEach(channel => {
+ if (!channel.parent && channel.type !== "GUILD_CATEGORY") 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))
- console.log(channels)
+ )
+ let 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.name.localeCompare(b.name)
+ if (autoSortBelow.includes(a.type)) return -1
+ if (autoSortBelow.includes(b.type)) return 1
+ return a.position - b.position
+ }))
+ let member = interaction.options.getMember("member") as Discord.GuildMember
+ await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setEmoji("MEMBER.JOIN")
+ .setTitle("Viewing as " + member.displayName)
+ .setStatus("Success")
+ ], ephemeral: true})
+ let page = 0;
+ while (true) {
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("MEMBER.JOIN")
+ .setTitle("Viewing as " + member.displayName)
+ .setStatus("Success")
+ .setDescription(
+ `${channels[page][0].parent ? channels[page][0].parent.name : "Uncategorised"}` +
+ "Visible:\n" +
+ channels[page].map(c => {
+ console.log(c)
+ return (channels[page] as Discord.GuildChannel).permissionsFor(member).has("VIEW_CHANNEL") ?
+ `${getEmojiByName("ICONS.CHANNEL." + c.type)} ${c.name}\n` : ""
+ }).join("")
+ )
+ ]})
+ break
+ }
}
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {