diff options
| author | Max Isom <[email protected]> | 2022-01-18 22:09:07 -0600 |
|---|---|---|
| committer | Max Isom <[email protected]> | 2022-01-18 22:09:07 -0600 |
| commit | 86e9936578d19c2115fc03acae1794532a09d62e (patch) | |
| tree | f4a16f6a06f76df9dbf439adf0537ace53493cc4 /src | |
| parent | 0f0c3eb6813391917c604629ae0523da3f35f012 (diff) | |
| download | muse-86e9936578d19c2115fc03acae1794532a09d62e.tar.xz muse-86e9936578d19c2115fc03acae1794532a09d62e.zip | |
Update README, naming
Diffstat (limited to 'src')
| -rw-r--r-- | src/bot.ts | 21 | ||||
| -rw-r--r-- | src/events/guild-create.ts | 2 | ||||
| -rw-r--r-- | src/services/config.ts | 6 |
3 files changed, 12 insertions, 17 deletions
@@ -13,32 +13,24 @@ import Config from './services/config.js'; import {generateDependencyReport} from '@discordjs/voice'; import {REST} from '@discordjs/rest'; import {Routes} from 'discord-api-types/v9'; -import {Promise} from 'bluebird'; @injectable() export default class { private readonly client: Client; private readonly token: string; - private readonly isProduction: boolean; + private readonly shouldRegisterCommandsOnBot: boolean; private readonly commandsByName!: Collection<string, Command>; private readonly commandsByButtonId!: Collection<string, Command>; constructor(@inject(TYPES.Client) client: Client, @inject(TYPES.Config) config: Config) { this.client = client; this.token = config.DISCORD_TOKEN; - this.isProduction = config.IS_PRODUCTION; + this.shouldRegisterCommandsOnBot = config.REGISTER_COMMANDS_ON_BOT; this.commandsByName = new Collection(); this.commandsByButtonId = new Collection(); } public async listen(): Promise<void> { - // Log environment - if (this.isProduction) { - console.log('Production environment\n'); - } else { - console.log('Development environment\n'); - } - // Load in commands container.getAll<Command>(TYPES.Command).forEach(command => { // TODO: remove ! @@ -122,18 +114,19 @@ export default class { this.client.once('ready', async () => { debug(generateDependencyReport()); - spinner.text = '📡 Updating commands in all guilds...'; - // Update commands const rest = new REST({version: '9'}).setToken(this.token); - if (this.isProduction) { + if (this.shouldRegisterCommandsOnBot) { + spinner.text = '📡 updating commands on bot...'; + await rest.put( Routes.applicationCommands(this.client.user!.id), {body: this.commandsByName.map(command => command.slashCommand ? command.slashCommand.toJSON() : null)}, ); } else { - // If development, set commands guild-wide + spinner.text = '📡 updating commands in all guilds...'; + await Promise.all( this.client.guilds.cache.map(async guild => { await rest.put( diff --git a/src/events/guild-create.ts b/src/events/guild-create.ts index 008e22b..e7a6467 100644 --- a/src/events/guild-create.ts +++ b/src/events/guild-create.ts @@ -17,7 +17,7 @@ export default async (guild: Guild): Promise<void> => { const config = container.get<Config>(TYPES.Config); // Setup slash commands - if (!config.IS_PRODUCTION) { + if (!config.REGISTER_COMMANDS_ON_BOT) { const commands: ApplicationCommandData[] = container.getAll<Command>(TYPES.Command) .filter(command => command.slashCommand?.name) .map(command => command.slashCommand as ApplicationCommandData); diff --git a/src/services/config.ts b/src/services/config.ts index ae7ef4b..34e612c 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -12,7 +12,7 @@ const CONFIG_MAP = { YOUTUBE_API_KEY: process.env.YOUTUBE_API_KEY, SPOTIFY_CLIENT_ID: process.env.SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET: process.env.SPOTIFY_CLIENT_SECRET, - IS_PRODUCTION: process.env.NODE_ENV === 'production', + REGISTER_COMMANDS_ON_BOT: process.env.REGISTER_COMMANDS_ON_BOT === 'true', DATA_DIR, CACHE_DIR: path.join(DATA_DIR, 'cache'), CACHE_LIMIT_IN_BYTES: xbytes.parseSize(process.env.CACHE_LIMIT ?? '2GB'), @@ -24,7 +24,7 @@ export default class Config { readonly YOUTUBE_API_KEY!: string; readonly SPOTIFY_CLIENT_ID!: string; readonly SPOTIFY_CLIENT_SECRET!: string; - readonly IS_PRODUCTION!: boolean; + readonly REGISTER_COMMANDS_ON_BOT!: boolean; readonly DATA_DIR!: string; readonly CACHE_DIR!: string; readonly CACHE_LIMIT_IN_BYTES!: number; @@ -40,6 +40,8 @@ export default class Config { this[key as ConditionalKeys<typeof CONFIG_MAP, number>] = value; } else if (typeof value === 'string') { this[key as ConditionalKeys<typeof CONFIG_MAP, string>] = value; + } else if (typeof value === 'boolean') { + this[key as ConditionalKeys<typeof CONFIG_MAP, boolean>] = value; } else { throw new Error(`Unsupported type for ${key}`); } |
