Update README, naming

This commit is contained in:
Max Isom 2022-01-18 22:09:07 -06:00
parent 0f0c3eb681
commit 86e9936578
No known key found for this signature in database
GPG key ID: 25C9B1A7F6798880
5 changed files with 3416 additions and 3514 deletions

View file

@ -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(

View file

@ -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);

View file

@ -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}`);
}