<commit_before>'use strict';
/**
 * Created by Michael on 6/24/2014.
 */

var mongoose = require('mongoose'),
    Syndicate = mongoose.model('Syndicate');

exports.parseMessage = function(text, callback) {
    var helpInfo = {
        'action':'help',
        'message':'Commands: START [NAME] or STOP [NAME].  You are subscribed to [TODO]'
    };

    if (!text)
        return callback({'action': 'error','message': 'Text is empty'});

    var a = text.split(' ');
    var command = a[0].toUpperCase();
    if (a.length < 2 ||  command === 'HELP')
        return callback(helpInfo);

    var target = a[1].toUpperCase();

    Syndicate.findOne({'name':target}, function(err, syndicate){
        switch (command) {
            case 'START':
                if (syndicate) {
                    return callback({
                        'action': command,
                        'data': target,
                        'message': 'You have subscribed to ' + target + ' messages.'
                    });
                }
                break;
            case 'STOP':
                if (syndicate) {
                    return callback({
                        'action': command,
                        'data': target,
                        'message': 'You have unsubscribed.  To resubscribe text START ' + target + ' to this number'
                    });
                }
                break;
            default:
                return callback({
                    'action': command,
                    'data': target,
                    'message': 'I don\'t know what to do with that command.  ' + helpInfo.message
                });
        }

        //fallthrough - unknown command.
        callback({
            'action': 'error ',
            'message': 'Group '+target+' does not exist.'
        });
    });
};<commit_msg>refactoring processor in preparation for future enhancments.<commit_after>'use strict';
/**
 * Created by Michael on 6/24/2014.
 */

var mongoose = require('mongoose'),
    Syndicate = mongoose.model('Syndicate');

exports.parseMessage = function(text, callback) {
    var helpInfo = {
        'action':'help',
        'message':'Commands: START [NAME] or STOP [NAME].  You are subscribed to [TODO]'
    };

    if (!text)
        return callback({'action': 'error','message': 'Text is empty'});

    var a = text.split(' ');
    var command = a[0].toUpperCase();
    if (a.length < 2 ||  command === 'HELP')
        return callback(helpInfo);

    var target = a[1].toUpperCase();

    switch (command) {
        case 'START':
        case 'STOP':
            exports.subscribe(command, target, callback);
            break;
        default:
            return callback({
                'action': command,
                'data': target,
                'message': 'I don\'t know what to do with that command.  ' + helpInfo.message
            });
    }
};

//process subscribe or unsubscribe requests
exports.subscribe = function(command, target, callback){
    Syndicate.findOne({'name':target}, function(err, syndicate){
        switch (command) {
            case 'START':
                if (syndicate) {
                    return callback({
                        'action': command,
                        'data': target,
                     'message': 'You have subscribed! to ' + target + ' messages.'
                    });
                }
                break;
            case 'STOP':
                if (syndicate) {
                    return callback({
                        'action': command,
                        'data': target,
                        'message': 'You have! unsubscribed.  To resubscribe text START ' + target + ' to this number'
                    });
                }
                break;
            default:
                return callback({
                    'action': command,
                    'data': target,
                    'message': 'Internal error: '+command+' is not a subscription command'
                });
        }

        //fallthrough - unknown command.
        callback({
            'action': 'error ',
            'message': 'Group '+target+' does not exist.'
        });
    });
};
{'fraction_non_alphanumeric': 0.1243964129684985, 'fraction_numerical': 0.004598758335249482, 'mean_word_length': 1.3040254237288136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4645335', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1049, 'n_words': 299}