'use strict';

module.exports = function(config, ircbot) {
	const Rcon = require('rcon');
	const client = new Rcon(config.rcon.host, config.rcon.port, config.rcon.password);
	
	client.on('auth', function() {
		console.log('RCON authentication successful');
	}).on('response', function(str) {
		console.log('RCON got response: ' + str);
	}).on('end', function() {
		console.log('RCON socket closed');
	});

	client.connect();
	
	ircbot.addListener('action', function(from, to, text) {
		if (to !== config.channel) {
			return;
		}
		
		client.send('say * ' + from + ' ' + text);
	});
	
	ircbot.addListener('message' + config.channel, function(from, text) {
		client.send('say <' + from + '> ' + text);
	});
};

'use strict';

module.exports = function(config, ircbot) {
	const Rcon = require('rcon');
	const client = new Rcon(config.rcon.host, config.rcon.port, config.rcon.password);

	client.on('auth', function() {
		console.log('RCON authentication successful');
	}).on('response', function(str) {
		console.log('RCON got response: ' + str);
	}).on('end', function() {
		console.log('RCON socket closed');
	}).on('error', function(e) {
		console.log('RCON socket connection failed: ' + e.message);
	});

	client.connect();
	
	ircbot.addListener('action', function(from, to, text) {
		if (to !== config.channel) {
			return;
		}
		
		client.send('say * ' + from + ' ' + text);
	});
	
	ircbot.addListener('message' + config.channel, function(from, text) {
		client.send('say <' + from + '> ' + text);
	});
};

Fix uncaught exception if minecraft server is offline when the bot starts