Skip to content

Commit fd99690

Browse files
committed
robocommand map
1 parent 2c6fce5 commit fd99690

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

index.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@ const Discord = require('discord.js');
22
const bot = new Discord.Client();
33
require('dotenv').config();
44

5-
const PREFIX = 'DG!';
5+
6+
const RoboCommands = (msg) => ({
7+
"website": () => msg.reply('https://www.da-developers.dev'),
8+
"bot info": () => msg.reply('Version 1.0.1')
9+
});
610

711
/**
812
* Handles incoming messages for Robo
913
*/
1014
const handleMessage = (msg) => {
11-
let args = msg.content.substring(PREFIX.length).split(" ");
12-
const {
13-
sendMessage
14-
} = msg.channel;
15-
switch (args[0]) {
16-
case 'website':
17-
sendMessage('da-developers.dev');
18-
break;
19-
case 'info':
20-
(args[1] === 'version') ? sendMessage('Version 1.0.1'): sendMessage('Invalid args')
21-
break;
15+
const PREFIX = 'DG!';
16+
const msgs = msg.content.split(" ")
17+
const roboCommands = RoboCommands(msg);
18+
if (msgs[0] == PREFIX) {
19+
// getting rid of DG! prefix
20+
msgs.splice(0, 1);
21+
if (msgs.length === 0 || msgs == undefined) {
22+
msg.reply('At least one argument is needed to complete a task.');
23+
} else {
24+
if (roboCommands[msgs.join(" ")]) {
25+
roboCommands[msgs.join(" ")]();
26+
} else {
27+
msg.reply('The command you entered is could not be found.')
28+
}
29+
}
2230
}
31+
2332
}
2433

2534
bot.on('ready', () => console.log('Robo is on.'))

0 commit comments

Comments
 (0)