forked from Talon/tardis-bot
		
	Add command helper
This commit is contained in:
		
							
								
								
									
										19
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								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); | ||||
| bot.login(process.env.TOKEN); | ||||
| bot.on('message', handleMessage); | ||||
		Reference in New Issue
	
	Block a user