diff --git a/.gitignore b/.gitignore index fd36765..727bd09 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Configs +src/bot/configs/metabot-config.json + # Logs logs *.log @@ -11,26 +14,5 @@ pids *.pid *.seed -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - # Dependency directory node_modules - -# Optional npm cache directory -.npm - -# Optional REPL history -.node_repl_history diff --git a/src/bot/configs/metabot-config.json.example b/src/bot/configs/metabot-config.json.example new file mode 100644 index 0000000..47b85ef --- /dev/null +++ b/src/bot/configs/metabot-config.json.example @@ -0,0 +1,4 @@ +{ + "prefix": "!", + "token": "your-discord-bot-token-here" +} diff --git a/src/bot/configs/metabot.ts b/src/bot/configs/metabot.ts index fa941b1..2be4b4a 100644 --- a/src/bot/configs/metabot.ts +++ b/src/bot/configs/metabot.ts @@ -1,4 +1,6 @@ +import { token as botToken } from '@bot/configs/metabot-config.json' + /** * Discord token for the bot. */ -export const token = process.env.BOT_TOKEN +export const token = process.env.BOT_TOKEN || botToken diff --git a/src/bot/utils/metabot.ts b/src/bot/utils/metabot.ts index 6560ce5..a50bc5e 100644 --- a/src/bot/utils/metabot.ts +++ b/src/bot/utils/metabot.ts @@ -7,6 +7,7 @@ import pingCommand from '@bot/commands/ping' import sonicCommand from '@bot/commands/sonic' import { VOICE_CHANNEL_NAME } from '@bot/commands/sonic/constants' import { COMMAND_ERROR_MESSAGE, PREFIX } from '@constants/metabot' +import { prefix as configPrefix } from '@bot/configs/metabot-config.json' // TODO: Read commands from commands folder using command name as folder name const commands = { @@ -16,17 +17,19 @@ const commands = { sonic: sonicCommand, } +const prefix = configPrefix || PREFIX + /** * Handles the Discord MESSAGE_CREATE event. */ export async function handleMessageCreate(message: Message) { - if (message.content[0] === PREFIX) { + if (message.content[0] === prefix) { // Acknowledge the message await message.react('🔄') // Get the command name and arguments from the message const tokens = _.split(message.content, ' ') - const commandName = _.head(tokens).substring(PREFIX.length) + const commandName = _.head(tokens).substring(prefix.length) const args = _.filter(_.tail(tokens), token => !!token) const command = commands[commandName] diff --git a/tsconfig.json b/tsconfig.json index 6207d17..0936810 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "@template": ["template.js"], "@utils/*": ["utils/*"] }, + "resolveJsonModule": true, "rootDir": "src", "sourceMap": true, "target": "es2020",