Skip to content

Commit

Permalink
chore: minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Pkmmte committed May 10, 2024
1 parent d462ed1 commit 9f386f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions packages/robo/src/cli/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ export async function registerCommands(
const addedContextChanges = addedContextCommands.map((cmd) => color.green(`${color.bold(cmd)} (new)`))
const removedContextChanges = removedContextCommands.map((cmd) => color.red(`${color.bold(cmd)} (deleted)`))
const updatedContextChanges = changedContextCommands.map((cmd) => color.blue(`${color.bold(cmd)} (updated)`))
const userinstall_enabled: boolean = config.userinstall_enabled
const allChanges = [...addedChanges, ...removedChanges, ...updatedChanges]
const allContextChanges = [...addedContextChanges, ...removedContextChanges, ...updatedContextChanges]
if (allChanges.length > 0) {
Expand All @@ -351,15 +350,18 @@ export async function registerCommands(
...contextMessageCommands.map((command) => command.toJSON()),
...contextUserCommands.map((command) => command.toJSON())
]
if (userinstall_enabled == true) {
logger.info('User install is enabled, injecting user install ')
slashCommands.map((command) => {
const commandData = command.toJSON()
commandData.integration_types = [0, 1] // Injecting the integration_types property
commandData.contexts = [0, 1, 2] // Injecting the context property
return commandData

// Inject user install if enabled
if (config.experimental?.userInstall) {
commandData.forEach((command) => {
// @ts-expect-error - Types outdated
command.integration_types = [0, 1]
// @ts-expect-error - Types outdated
command.contexts = [0, 1, 2]
})
}

// Get existing commands
const existingCommands = (await rest.get(
guildId ? Routes.applicationGuildCommands(clientId, guildId) : Routes.applicationCommands(clientId)
)) as APIApplicationCommand[]
Expand Down Expand Up @@ -411,7 +413,12 @@ export async function registerCommands(
}

const endTime = Date.now() - startTime
const commandType = guildId ? 'guild' : 'global'
let commandType = guildId ? 'guild' : 'global'

if (config.experimental?.userInstall) {
commandType += ' and user install'
}

logger.info(`Successfully updated ${color.bold(commandType + ' commands')} in ${endTime}ms`)
logger.info(color.dim('It may take a while for the changes to reflect in Discord.'))
await Flashcore.delete(FLASHCORE_KEYS.commandRegisterError)
Expand Down
2 changes: 1 addition & 1 deletion packages/robo/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { ClientOptions, PermissionsString } from 'discord.js'
import type { Plugin, SageOptions } from './index.js'

export interface Config {
userinstall_enabled: boolean
clientOptions?: ClientOptions
defaults?: {
dev?: boolean
Expand All @@ -14,6 +13,7 @@ export interface Config {
buildDirectory?: string
disableBot?: boolean
incrementalBuilds?: boolean
userInstall?: boolean
}
flashcore?: {
keyv?: unknown
Expand Down

0 comments on commit 9f386f2

Please sign in to comment.