forked from krismuniz/slash-command
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (24 loc) · 738 Bytes
/
index.js
File metadata and controls
27 lines (24 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'use strict';
const slashCommand = function(s) {
if (typeof s !== 'string') {
throw new TypeError('Argument must be a string.');
}
var cmds = s.split(' ')[0].match(/\/([\w-=:.@]+)/ig);
var slashcmds = null;
var subcmds = null;
var body = s.trim() || null;
if (cmds) {
slashcmds = cmds.join('');
cmds = cmds.map(function(x) { return x.replace('/',''); });
subcmds = cmds.length > 1 ? cmds.filter(function(v) { return v !== cmds[0]}) : null;
body = s.split(' ').filter(function(v, i) {return i > 0}).join(' ').trim() || null;
}
return {
slashcommand: slashcmds,
command: cmds ? cmds[0] : null,
subcommands: subcmds,
body: body,
original: s
};
};
module.exports = slashCommand;