| const { ChannelType, PermissionFlagsBits } = require('discord.js'); |
| const { createEmbed } = require('../utils/embeds'); |
| const { Colors } = require('../config'); |
|
|
| module.exports = { |
| name: 'permission audit', |
| async execute(client, message) { |
| const guildId = process.env.GUILD_ID; |
| const guild = await client.guilds.fetch(guildId); |
| await guild.channels.fetch(); |
|
|
| const issues = []; |
| const report = []; |
|
|
| const categories = guild.channels.cache |
| .filter(c => c.type === ChannelType.GuildCategory) |
| .sort((a, b) => a.position - b.position); |
|
|
| for (const [, category] of categories) { |
| const catReport = [`π **${category.name}**`]; |
| const children = guild.channels.cache |
| .filter(c => c.parentId === category.id) |
| .sort((a, b) => a.position - b.position); |
|
|
| for (const [, channel] of children) { |
| const everyone = channel.permissionOverwrites.cache.get(guild.roles.everyone.id); |
| const everyoneView = everyone?.deny?.has(PermissionFlagsBits.ViewChannel) ? 'π' : 'ποΈ'; |
| const everyoneSend = everyone?.deny?.has(PermissionFlagsBits.SendMessages) ? 'π' : 'π¬'; |
|
|
| catReport.push(` β ${channel.name} β ${everyoneView} ${everyoneSend}`); |
|
|
| |
| if (!everyone) { |
| issues.push(`β οΈ ${channel.name} β no @everyone override set`); |
| } |
| } |
|
|
| report.push(catReport.join('\n')); |
| } |
|
|
| |
| const legend = '```\nποΈ = @everyone can view\nπ = @everyone cannot view\nπ¬ = @everyone can send\nπ = @everyone cannot send\n```'; |
|
|
| const embed = createEmbed({ |
| title: 'π‘οΈ Permission Audit', |
| description: legend + '\n\n' + report.join('\n\n'), |
| color: Colors.INFO, |
| }); |
|
|
| const parts = []; |
| const embedStr = legend + '\n\n' + report.join('\n\n'); |
|
|
| |
| if (embedStr.length > 4000) { |
| |
| const buffer = Buffer.from(report.join('\n\n'), 'utf-8'); |
| await message.reply({ |
| embeds: [createEmbed({ |
| title: 'π‘οΈ Permission Audit', |
| description: `${legend}\n\nFull report attached (too long for embed).${issues.length ? '\n\n**Issues Found:**\n' + issues.join('\n') : '\n\nβ
No issues found.'}`, |
| color: Colors.INFO, |
| })], |
| files: [{ attachment: buffer, name: 'permission-audit.txt' }], |
| }); |
| } else { |
| const desc = embedStr + (issues.length ? '\n\n**Issues Found:**\n' + issues.join('\n') : '\n\nβ
No issues found.'); |
| await message.reply({ |
| embeds: [createEmbed({ title: 'π‘οΈ Permission Audit', description: desc, color: Colors.INFO })], |
| }); |
| } |
| }, |
| }; |
|
|