mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-24 03:31:04 +00:00
feat(bots/discord)!: add admin config
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
import type { Command } from '$commands/types'
|
||||
import { listAllFilesRecursive } from '$utils/fs'
|
||||
|
||||
export const loadCommands = async (dir: string) => {
|
||||
const commandsMap: Record<string, Command> = {}
|
||||
const files = listAllFilesRecursive(dir)
|
||||
const commands = await Promise.all(
|
||||
files.map(async file => {
|
||||
const command = await import(file)
|
||||
return command.default
|
||||
}),
|
||||
)
|
||||
|
||||
for (const command of commands) {
|
||||
if (command) commandsMap[command.data.name] = command
|
||||
}
|
||||
|
||||
return commandsMap
|
||||
}
|
||||
11
bots/discord/src/utils/discord/permissions.ts
Normal file
11
bots/discord/src/utils/discord/permissions.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { GuildMember, type User } from 'discord.js'
|
||||
import type { Config } from 'config.schema'
|
||||
|
||||
export const isAdmin = (userOrMember: User | GuildMember, adminConfig: Config['admin']) => {
|
||||
return adminConfig?.users?.includes(userOrMember.id) || (userOrMember instanceof GuildMember && isMemberAdmin(userOrMember, adminConfig))
|
||||
}
|
||||
|
||||
export const isMemberAdmin = (member: GuildMember, adminConfig: Config['admin']) => {
|
||||
const roles = new Set(member.roles.cache.keys())
|
||||
return Boolean(adminConfig?.roles?.[member.guild.id]?.some(role => roles.has(role)))
|
||||
}
|
||||
Reference in New Issue
Block a user