<commit_before>'use strict';

var request   = require('request');
var Q         = require('q');
var log       = require('./log');
var config    = require('hi-config');

// If the "slack" property is not present in the config, just return function stubs and do nothing.
if (!config.get('slack')) {
    log.info('No "slack" property found in config.json, will not post status to Slack');
    return {
        send: function(){}
    }
}

var Slack = require('slack-client');
var token = config.get('slack').botToken;
var slack = new Slack(token, true, true);
var self  = {
    statusChannelName: config.get('slack').statusChannel,
    inStatusChannel: false,
    connected: false,

    _statusQueue: [],
    _statusChannel: null,

    flushStatusQueue: function() {
        self._statusQueue.forEach(function (text) {
            self.status(text);
        });
        self._statusQueue = [];
    },
    status: function(text) {
        if (!self.connected) {
            self._statusQueue.push(text);
        } else {
            if (!self.inStatusChannel) return;
            self._statusChannel.send(text);
        }
    }
};

module.exports = self;

// Wait until we've defined module.exports before loading the Twitch IRC lib
var ircClient = require('./twitch_irc');

slack.on('open', function () {
    for (var channel in slack.channels) {
        if (!slack.channels.hasOwnProperty(channel)) continue;

        var c = slack.channels[channel];
        if (c.name !== self.statusChannelName) continue;

        if (!c.is_member) {
            log.error('[slack] Bot has not yet been invited to #%s, will be unable to send post status updates.'
                , self.statusChannelName);
            self.inStatusChannel = false;
        } else {
            self._statusChannel = c;
            self.inStatusChannel = true;
            self.connected = true;
            self.flushStatusQueue();
        }
    }
});

slack.on('message', function(message) {
    if (message.type !== 'message') return;
    var channel = slack.getChannelGroupOrDMByID(message.channel);
    var trimmedMessage = message.text.trim();
    var isCmd = trimmedMessage.charAt(0) === '!';

    if (!isCmd) return;<commit_msg>Ignore commands that aren't from the designated status channel<commit_after>'use strict';

var request   = require('request');
var Q         = require('q');
var log       = require('./log');
var config    = require('hi-config');

// If the "slack" property is not present in the config, just return function stubs and do nothing.
if (!config.get('slack')) {
    log.info('No "slack" property found in config.json, will not post status to Slack');
    return {
        send: function(){}
    }
}

var Slack = require('slack-client');
var token = config.get('slack').botToken;
var slack = new Slack(token, true, true);
var self  = {
    statusChannelName: config.get('slack').statusChannel,
    inStatusChannel: false,
    connected: false,

    _statusQueue: [],
    _statusChannel: null,

    flushStatusQueue: function() {
        self._statusQueue.forEach(function (text) {
            self.status(text);
        });
        self._statusQueue = [];
    },
    status: function(text) {
        if (!self.connected) {
            self._statusQueue.push(text);
        } else {
            if (!self.inStatusChannel) return;
            self._statusChannel.send(text);
        }
    }
};

module.exports = self;

// Wait until we've defined module.exports before loading the Twitch IRC lib
var ircClient = require('./twitch_irc');

slack.on('open', function () {
    for (var channel in slack.channels) {
        if (!slack.channels.hasOwnProperty(channel)) continue;

        var c = slack.channels[channel];
        if (c.name !== self.statusChannelName) continue;

        if (!c.is_member) {
            log.error('[slack] Bot has not yet been invited to #%s, will be unable to send post status updates.'
                , self.statusChannelName);
            self.inStatusChannel = false;
        } else {
            self._statusChannel = c;
            self.inStatusChannel = true;
            self.connected = true;
            self.flushStatusQueue();
        }
    }
});

slack.on('message', function(message) {
    if (message.type !== 'message') return;

    var channel = slack.getChannelGroupOrDMByID(message.channel);
    if (channel.name !== self.statusChannelName) return;

    var trimmedMessage = message.text.trim();
    var isCmd = trimmedMessage.charAt(0) === '!';
    if (!isCmd) return;
{'fraction_non_alphanumeric': 0.13278652183551318, 'fraction_numerical': 0.0004433606739082243, 'mean_word_length': 2.566798418972332, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1717878', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1286, 'n_words': 347}