Added an env var to specify which types of files are loaded

This commit is contained in:
Alec LaLonde
2021-05-18 11:13:34 -06:00
committed by Alec LaLonde
parent b845e7d162
commit f653d0879e
5 changed files with 24 additions and 11 deletions

View File

@@ -0,0 +1,7 @@
# MetaGame Discord Bot
## Docker commands / testing
To build: `docker build -f docker/discord-bot/Dockerfile -t discord-bot .`
To run: `docker run discord-bot`

View File

@@ -1,12 +1,15 @@
import { Discord } from '@typeit/discord';
import * as Path from 'path';
// Within a docker container: We are using tsc, so we want to load the compiled files.
// For local dev, we are transpiling: Load the .ts files.
const glob = process.env.RUNTIME_ENV === 'docker' ?
Path.join(__dirname, 'commands', '*.js') :
Path.join(__dirname, 'commands', '*.ts')
@Discord('', {
import: [
// We are using tsc, so we want to load the compiled files
Path.join(__dirname, 'commands', '*.ts'),
Path.join(__dirname, 'commands', '*.js'),
],
import: [glob],
})
export abstract class AppDiscord {
// This is triggered when a particular command doesn't exist

View File

@@ -12,7 +12,6 @@ import {
import { getDiscordId, replyWithUnexpectedError } from '../../utils';
export class GetXpCommand {
// todo rename to xp once previous bot is disabled
@Command('!xp :discordUser')
async getXp(message: CommandMessage) {
let targetUserDiscordId = '';

View File

@@ -3,13 +3,15 @@ import { Client } from '@typeit/discord';
import { CONFIG } from './config';
// Within a docker container: We are using tsc, so we want to load the compiled files.
// For local dev, we are transpiling: Load the .ts files.
const glob = process.env.RUNTIME_ENV === 'docker' ?
`${__dirname}/discord/**/*.js` :
`${__dirname}/discord/**/*.ts`
async function createDiscordClient(): Promise<Client> {
const client = new Client({
classes: [
// We are using tsc, so we want to load the compiled files
`${__dirname}/discord/**/*.ts`, // glob string to load the classes
`${__dirname}/discord/**/*.js`, // glob string to load the classes
],
classes: [glob],
silent: false,
variablesChar: ':',
});