index.js
1.59 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
const logger = require('komodo-sdk/logger');
const commandParser = require('../command-parser');
const commandError = require('./error');
const handlerHelp = require('./help');
const handlerBuy = require('./buy');
const handlerBalance = require('./balance');
const handlerPrice = require('./price');
const handlerListDownline = require('./listdownline');
const handlerDownlineInfo = require('./downlineinfo');
const handlerAddDownline = require('./adddownline');
function execute(msg, params, cb) {
if ( typeof msg !== 'string' || !msg.trim() ) {
cb(commandError.ERR_EMPTY_MESSAGE);
return;
}
const tokens = commandParser.splitToken(msg);
const commandGroup = commandParser.extractCommandGroup(tokens);
logger.verbose('Got new message from partner', {msg: msg, params: params, tokens: tokens, commandGroup: commandGroup});
if (!commandGroup || commandGroup === 'buy') {
handlerBuy(tokens, params, cb);
}
else if (commandGroup === 'balance') {
handlerBalance(tokens, params, cb);
}
else if (commandGroup === 'price') {
handlerPrice(tokens, params, cb);
}
else if (commandGroup === 'listdownline') {
handlerListDownline(tokens, params, cb);
}
else if (commandGroup === 'downlineinfo') {
handlerDownlineInfo(tokens, params, cb);
}
else if (commandGroup === 'adddownline') {
handlerAddDownline(tokens, params, cb);
}
else if (commandGroup === 'help') {
handlerHelp(cb)
}
else {
cb(commandError.ERR_NOT_IMPLEMENTED);
}
}
module.exports = execute;