<commit_before>
var ejs = require('ejs');
var http = require('http');
var https = require('https');
var moment = require('moment');
var CheckEvent = require('../../models/checkEvent');

exports.initWebApp = function(options) {
    var config = options.config.slack;

    CheckEvent.on('afterInsert', function(checkEvent) {
        if (!config.event[checkEvent.message]) {
            return;
        }
        checkEvent.findCheck(function(err, check) {
            if (err) {
                return console.error(err);
            }
            var matches = config.webhook.match(/(http|https):\/\/([^\/]+)(\/.*)?/);
            if (matches === null) {
                return console.error('Problem parsing Slack Webhook URL: ' + config.webhook);
            }
            var options = {
                host: matches[2],
                path: matches[3] || '/',
                method: 'POST'
            };
            var templateDir = __dirname + '/views/';
            var filename = templateDir + checkEvent.message + '.ejs';
            var renderOptions = {
                check: check,
                checkEvent: checkEvent,
                url: options.config.url,
                moment: moment,
                filename: filename
            };
            var lines = ejs.render(fs.readFileSync(filename, 'utf8'), renderOptions).split('\n');
            var postdata = {
                channel: config.channel || '#dev',
                username: config.username || 'Uptime Alert',
                text: lines.join('\n'),
                icon_emoji: config.icon_emoji || ':turtle:'
            }
            if (config.icon_url) {
                delete postdata.icon_emoji;
                postdata.icon_url = config.icon_url;
            }
            var req = (
                matches[1] == 'https' ? https.request : http.request
            )(options, function(res) {
                if (res.statusCode == 200) {
                    res.setEncoding('utf8');
                    res.on('data', function (chunk) {
                        console.log('Slack plugin response data: ' + chunk);
                    });
                } else {
                    console.error('Slack plugin response code: ' + res.statusCode);
                    console.error('Slack plugin response headers: ' + JSON.stringify(res.headers));
                }
            });
            req.on('error', function(_err) {
                console.error('Slack plugin response error: ' + _err.message);
            });
            req.write(JSON.stringify(postdata));
            req.end();
        });
    });

    console.log('Enabled Email notifications');
}<commit_msg>Bug fix: removed duplicate var options<commit_after>
var ejs = require('ejs');
var http = require('http');
var https = require('https');
var moment = require('moment');
var CheckEvent = require('../../models/checkEvent');

exports.initWebApp = function(options) {
    var config = options.config.slack;

    CheckEvent.on('afterInsert', function(checkEvent) {
        if (!config.event[checkEvent.message]) {
            return;
        }
        checkEvent.findCheck(function(err, check) {
            if (err) {
                return console.error(err);
            }
            var matches = config.webhook.match(/(http|https):\/\/([^\/]+)(\/.*)?/);
            if (matches === null) {
                return console.error('Problem parsing Slack Webhook URL: ' + config.webhook);
            }
            var templateDir = __dirname + '/views/';
            var filename = templateDir + checkEvent.message + '.ejs';
            var renderOptions = {
                check: check,
                checkEvent: checkEvent,
                url: options.config.url,
                moment: moment,
                filename: filename
            };
            var lines = ejs.render(fs.readFileSync(filename, 'utf8'), renderOptions).split('\n');
            var postdata = {
                channel: config.channel || '#dev',
                username: config.username || 'Uptime Alert',
                text: lines.join('\n'),
                icon_emoji: config.icon_emoji || ':turtle:'
            }
            if (config.icon_url) {
                delete postdata.icon_emoji;
                postdata.icon_url = config.icon_url;
            }
            var req = (
                matches[1] == 'https' ? https.request : http.request
            )({
                host: matches[2],
                path: matches[3] || '/',
                method: 'POST'
            }, function(res) {
                if (res.statusCode == 200) {
                    res.setEncoding('utf8');
                    res.on('data', function (chunk) {
                        console.log('Slack plugin response data: ' + chunk);
                    });
                } else {
                    console.error('Slack plugin response code: ' + res.statusCode);
                    console.error('Slack plugin response headers: ' + JSON.stringify(res.headers));
                }
            });
            req.on('error', function(_err) {
                console.error('Slack plugin response error: ' + _err.message);
            });
            req.write(JSON.stringify(postdata));
            req.end();
        });
    });

    console.log('Enabled Email notifications');
}
{'fraction_non_alphanumeric': 0.1350693143499438, 'fraction_numerical': 0.0029973772948669914, 'mean_word_length': 1.4878844361602983, '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': '429305', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1342, 'n_words': 286}