diff --git a/index.js b/index.js index fb44ed4..f7114be 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ const sqlite = require('sqlite3'); let joinedVoiceChannels = []; let modules = []; +let commandHandlers = new Map(); const bot = new Discord.Client(); @@ -56,6 +57,10 @@ const api = { const conn = api.getConnectionForVoiceChannel(channel); const filepath = await api.generateVoice(message); if (conn) conn.play(filepath); + }, + + registerCommand: async (commandString, commandFunc) => { + commandHandlers.set(commandString, commandFunc); } } @@ -69,5 +74,17 @@ function registerModules() { modules.forEach((mod) => mod(bot, api)); } +function handleMessage(message) { + if (message.contents.startsWith(process.env.PREFIX)) { + const args = message.contents.split(" "); + const command = args[0].substr(1, args[0].length); + const execution = commandHandlers.get(command); + if (command) { + command(args, message); + } + } +} + registerModules(); -bot.login(process.env.TOKEN); \ No newline at end of file +bot.login(process.env.TOKEN); +bot.on('message', handleMessage); \ No newline at end of file