Skip to content

Commit

Permalink
I promise it's done now...
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Jun 10, 2021
1 parent f984e42 commit e1b5a19
Showing 1 changed file with 25 additions and 45 deletions.
70 changes: 25 additions & 45 deletions src/listeners/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,14 @@ client.once("ready", async () => {
} else {
//Create a guild wide command
const cmd = await client.guilds.cache.get("549503328472530974")!.commands.create(convertToDiscordCommand(command))
const permissions: Discord.ApplicationCommandPermissionData[] = []
command.roleWhitelist?.forEach(id => {
//Add whitelisted roles
permissions.push({
type: "ROLE",
id,
permission: true
})
})
command.roleBlacklist?.forEach(id => {
//Add blacklisted roles
permissions.push({
type: "ROLE",
id,
permission: false
})
})
if (permissions.length) await cmd.setPermissions(permissions)
await setPermissions(cmd)
}
console.log(`Published command ${command.name}!`)
}

//Only update global commands in production
//TODO add check to delete commands that have been removed
if (process.env.NODE_ENV === "production") {
if (process.env.NODE_ENV === "dev") {
const globalCommands = await client.application!.commands.fetch()
if (!globalCommands)
client.commands.filter(c => !!c.allowDM).forEach(async command => await publishCommand(command))
Expand All @@ -57,32 +40,8 @@ client.once("ready", async () => {
const guildCommands = await client.guilds.cache.get("549503328472530974")!.commands.fetch()
if (!guildCommands) client.commands.filter(c => !c.allowDM).forEach(async command => await publishCommand(command))
else client.guilds.cache.get("549503328472530974")!.commands.set(constructDiscordCommands())
} else {
client.guilds.cache.get("549503328472530974")!.commands.set(constructDiscordCommands())
.then(commands =>
commands.forEach(async cmd => {
const permissions: Discord.ApplicationCommandPermissionData[] = [],
command = client.commands.get(cmd.name)!
command.roleWhitelist?.forEach(id => {
//Add whitelisted roles
permissions.push({
type: "ROLE",
id,
permission: true
})
})
command.roleBlacklist?.forEach(id => {
//Add blacklisted roles
permissions.push({
type: "ROLE",
id,
permission: false
})
})
if (permissions.length) await cmd.setPermissions(permissions)
})
)
}
} else client.guilds.cache.get("549503328472530974")!.commands.set(constructDiscordCommands())
.then(commands => commands.forEach(async command => await setPermissions(command)))

//Get server boosters and staff for the status
let boostersStaff: string[] = []
Expand Down Expand Up @@ -130,6 +89,27 @@ client.once("ready", async () => {
}, 60000)
})

const setPermissions = async (command: Discord.ApplicationCommand) => {
const permissions: Discord.ApplicationCommandPermissionData[] = [],
clientCmd = client.commands.get(command.name)!
clientCmd.roleWhitelist?.forEach(id => {
//Add whitelisted roles
permissions.push({
type: "ROLE",
id,
permission: true
})
})
clientCmd.roleBlacklist?.forEach(id => {
//Add blacklisted roles
permissions.push({
type: "ROLE",
id,
permission: false
})
})
if (permissions.length) await command.setPermissions(permissions)
}
const constructDiscordCommands = () => {
const returnCommands: Discord.ApplicationCommandData[] = []
let clientCommands = client.commands
Expand Down

0 comments on commit e1b5a19

Please sign in to comment.