feat(help): hide non-admin commands from non-admins

This commit is contained in:
2024-08-07 14:46:39 +03:00
parent 2a05039a74
commit 725a998e52

View File

@@ -3,6 +3,7 @@ import { command, commands } from '@/core/commands'
import { DEFAULT_COMMAND_PREFIX } from '@/env'
import { logger } from '@/core/logger'
import { isWhitelisted } from '@/lib/whitelist'
import { isAdministrator } from '@/utils/discord_utils'
interface HelpMessage {
command: string
@@ -17,6 +18,7 @@ export default command({
global: true,
async execute(message, args) {
const whitelisted = await isWhitelisted('commands', message.guild!, message.channel)
const isAdmin = await isAdministrator(message.member!)
let output = ''
const data: HelpMessage[] = []
const name = args[0]
@@ -28,7 +30,8 @@ export default command({
c.aliases.some((a) => a.toLowerCase() === name.toLowerCase())
: true
const isGlobal = c.global ?? false
return [nameMatches, whitelisted || isGlobal].every(Boolean)
const isPermitted = !c.adminOnly || isAdmin
return [nameMatches, whitelisted || isGlobal, isPermitted].every(Boolean)
})
for (const cmd of commandList) {