<commit_before>#!/usr/bin/env node

var irc = require('irc');
var fs = require('fs');
var http = require('http');
var request = require('request');

var control = require('./control');

var config = JSON.parse(fs.readFileSync('config.json', 'utf8'));

var ircbot = new irc.Client(
	config.irc.server,
	config.irc.nickname,
	config.irc.options
);

// error handler
ircbot.addListener('error', function(message) {
    console.error('IRCBOT', message);
});

// whois
ircbot.addListener('whois', function(info) {
    console.info(info.nick, 'is', info.user + '@' + info.host, '*', info.realname);
    console.info(info.nick, 'on', info.channels.join(' '));
    console.info(info.nick, 'using', info.server, info.serverinfo);
    console.info(info.nick, 'End of /WHOIS list.');
});

// help
ircbot.addListener('raw', function(message) {
    switch (message.rawCommand) {
        case '704':
        case '705':
        case '706':
            console.log(message.args[2]);
        break;
    }
});

// channel list
ircbot.addListener('channellist_start', function() {
    console.info('Listing channels...');
});

ircbot.addListener('channellist_item', function(info) {
    console.info(info.name, info.users, info.topic);
});

function ircConnect() {
	ircbot.connect(Math.pow(2, 32) - 1);
}

// misc
ircbot.addListener('action', function(from, to, message) {
    if (to.indexOf('#') === 0 && message === 'kicks ' + config.irc.nickname) {
        ircbot.say(to, 'ouch!');
    }
});

ircbot.addListener('message', function (from, to, message) {
    if (to !== config.irc.announceChannel) {
        return;
    }
    switch (message) {
        case '!weather':
            request({
                url: 'https://cassie.initlab.org/weather.json',
                json: true
            }, function(error, response, body) {
                if (error !== null || response.statusCode !== 200) {
                    ircbot.say(to, 'Error getting data');
                    return;
                }
                
                ircbot.say(to, 'Temperature: ' + body.temp_in.toFixed(1) + ' °C in / ' + body.temp_out.toFixed(1) + ' °C out');
                ircbot.say(to, 'Humidity: ' + body.hum_in.toFixed(0) + ' % in / ' + body.hum_out.toFixed(0) + ' % out');
                ircbot.say(to, 'Pressure: ' + body.abs_pressure.toFixed(1) + ' hPa');
            });
            break;
        case '!who':
            request({
                url: 'https://fauna.initlab.org/api/users/present.json',
                json: true
            }, function(error, response, body) {
                if (error !== null || response.statusCode !== 200) {
                    ircbot.say(to, 'Error getting data');
                    return;
                }
                var users = body.map(function(user) {
                    return user.username + ' (' + user.name + ')';
                }).join(', ');
                ircbot.say(to, 'People in init Lab: ' + users);
            });
            break;
    }
});

// control socket
var controlSocket = new control.Socket(config.socket.path, ircConnect, function(cmd) {
    var args = cmd.split(' ');
    var cmd = args.shift().toLowerCase();
    
    var argsOptional = false;
    var knownCmd = true;
    var sendCmd = true;
    
    switch (cmd) {
        case 'quote':
            cmd = 'send';
        case 'send':
            // no need to modify args
        break;
        case 'join':
            args = [<commit_msg>Add door status (#4)<commit_after>#!/usr/bin/env node

var irc = require('irc');
var fs = require('fs');
var http = require('http');
var request = require('request');

var control = require('./control');

var config = JSON.parse(fs.readFileSync('config.json', 'utf8'));

var ircbot = new irc.Client(
	config.irc.server,
	config.irc.nickname,
	config.irc.options
);

// error handler
ircbot.addListener('error', function(message) {
    console.error('IRCBOT', message);
});

// whois
ircbot.addListener('whois', function(info) {
    console.info(info.nick, 'is', info.user + '@' + info.host, '*', info.realname);
    console.info(info.nick, 'on', info.channels.join(' '));
    console.info(info.nick, 'using', info.server, info.serverinfo);
    console.info(info.nick, 'End of /WHOIS list.');
});

// help
ircbot.addListener('raw', function(message) {
    switch (message.rawCommand) {
        case '704':
        case '705':
        case '706':
            console.log(message.args[2]);
        break;
    }
});

// channel list
ircbot.addListener('channellist_start', function() {
    console.info('Listing channels...');
});

ircbot.addListener('channellist_item', function(info) {
    console.info(info.name, info.users, info.topic);
});

function ircConnect() {
	ircbot.connect(Math.pow(2, 32) - 1);
}

// misc
ircbot.addListener('action', function(from, to, message) {
    if (to.indexOf('#') === 0 && message === 'kicks ' + config.irc.nickname) {
        ircbot.say(to, 'ouch!');
    }
});

ircbot.addListener('message', function (from, to, message) {
    if (to !== config.irc.announceChannel) {
        return;
    }
    switch (message) {
        case '!weather':
            request({
                url: 'https://cassie.initlab.org/weather.json',
                json: true
            }, function(error, response, body) {
                if (error !== null || response.statusCode !== 200) {
                    ircbot.say(to, 'Error getting data');
                    return;
                }
                
                ircbot.say(to, 'Temperature: ' + body.temp_in.toFixed(1) + ' °C in / ' + body.temp_out.toFixed(1) + ' °C out');
                ircbot.say(to, 'Humidity: ' + body.hum_in.toFixed(0) + ' % in / ' + body.hum_out.toFixed(0) + ' % out');
                ircbot.say(to, 'Pressure: ' + body.abs_pressure.toFixed(1) + ' hPa');
            });
            break;
        case '!who':
            request({
                url: 'https://fauna.initlab.org/api/users/present.json',
                json: true
            }, function(error, response, body) {
                if (error !== null || response.statusCode !== 200) {
                    ircbot.say(to, 'Error getting data');
                    return;
                }
                var users = body.map(function(user) {
                    return user.username + ' (' + user.name + ')';
                }).join(', ');
                ircbot.say(to, 'People in init Lab: ' + users);
            });
            break;
        case '!door':
            request({
                url: 'https://fauna.initlab.org/api/door/status.json',
                json: true
            }, function(error, response, body) {
                ircbot.say(to, 'The door is ' + body.latch + ' and ' + body.door);
            });
            break;
    }
});

// control socket
var controlSocket = new control.Socket(config.socket.path, ircConnect, function(cmd) {
    var args = cmd.split(' ');
    var cmd = args.shift().toLowerCase();
    
    var argsOptional = false;
    var knownCmd = true;
    var sendCmd = true;
    
    switch (cmd) {
        case 'quote':
            cmd = 'send';
        case 'send':
            // no need to modify args
        break;
        case 'join':
            args = [
{'fraction_non_alphanumeric': 0.16786305908337934, 'fraction_numerical': 0.0075924903368304805, 'mean_word_length': 1.979029605263158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 5, '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': '1934973', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2223, 'n_words': 461}