"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'); const handlerAddBalance = require('./addbalance'); const handlerTransferBalance = require('./transferbalance'); 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 === 'addbalance') { handlerAddBalance(tokens, params, cb); } else if (commandGroup === 'transferbalance') { handlerTransferBalance(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;