Skip to content

Commit

Permalink
✨ Add config file for prefix and token.
Browse files Browse the repository at this point in the history
  • Loading branch information
Duelist committed Sep 11, 2019
1 parent aa9dad7 commit 5fdaffc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
24 changes: 3 additions & 21 deletions .gitignore
@@ -1,3 +1,6 @@
# Configs
src/bot/configs/metabot-config.json

# Logs
logs
*.log
Expand All @@ -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
4 changes: 4 additions & 0 deletions src/bot/configs/metabot-config.json.example
@@ -0,0 +1,4 @@
{
"prefix": "!",
"token": "your-discord-bot-token-here"
}
4 changes: 3 additions & 1 deletion 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
7 changes: 5 additions & 2 deletions src/bot/utils/metabot.ts
Expand Up @@ -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 = {
Expand All @@ -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]

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -11,6 +11,7 @@
"@template": ["template.js"],
"@utils/*": ["utils/*"]
},
"resolveJsonModule": true,
"rootDir": "src",
"sourceMap": true,
"target": "es2020",
Expand Down

0 comments on commit 5fdaffc

Please sign in to comment.