Implemented automatic OP

This commit is contained in:
lanxu 2015-06-20 15:08:25 +03:00
parent e15cb27d57
commit f36f278c20

172
app.js
View File

@ -3,15 +3,63 @@ var config = {
irc: {
server: 'irc.elisa.fi',
nick: 'Ookami-dev',
channels: ['#kulmapaikka-dev', '#hi-tech', '#kulmapaikka']
channels: ['#kulmapaikka-dev']
}
};
var members = [
{
nick: 'lanxu',
hostmask: ''
var members = {
'lanxu': {
user: /julankin$/,
host: /^jumi\.lut\.fi$/
},
'asdfas': {
user: /asdfas$/,
host: /(.*)\.ssp\.fi$/
},
'asdfas2': {
user: /Asdfas$/,
host: /(.*)\.elisa-mobile\.fi$/
},
'cbd': {
user: /cbd$/,
host: /kapsi\.fi$/
},
'fitzhood': {
user: /Fitzhood$/,
host: /(.*)ssp\.fi$/
},
'mindflayer': {
user: /mindflaye$/,
host: /(.*)opintanner\.fi$/
},
'pariah': {
user: /rautia$/,
host: /mozart\.cc\.tut\.fi$/
},
'zoid': {
user: /jolaakso$/,
host: /kapsi\.fi$/
},
'palin': {
user: /Palin$/,
host: /(.*)\.elisa-mobile\.fi$/
},
'rootmer': {
user: /ror$/,
host: /(.*)\.inet\.fi$/
},
'masaKapsi': {
user: /maruohon$/,
host: /kapsi\.fi$/
},
'masaJumi': {
user: /maruohon$/,
host: /jumi\.lut\.fi$/
},
'masaAura': {
user: /masa$/,
host: /(.*)\.ssp\.fi$/
}
];
};
var irc = require('irc');
var penaapi = require('./penaapi')();
@ -23,6 +71,28 @@ var owmCityIds = {
Lappeenranta: 648900
};
var iconCodeToText = {
'01d': 'selkeää',
'02d': 'puolipilvistä',
'03d': 'pilvistä',
'04d': 'pilvipeite rakoilee',
'09d': 'sadekuuroja',
'10d': 'vesisadetta',
'11d': 'ukkostaa',
'13d': 'lumisadetta',
'50d': 'sumua',
'01n': 'selkeää',
'02n': 'puolipilvistä',
'03n': 'pilvistä',
'04n': 'pilvipeite rakoilee',
'09n': 'sadekuuroja',
'10n': 'vesisadetta',
'11n': 'ukkostaa',
'13n': 'lumisadetta',
'50n': 'sumua'
};
var getTemperatureString = function() {
var Promise = require('promise');
var promise = new Promise(function(resolve, reject) {
@ -32,26 +102,20 @@ var getTemperatureString = function() {
penaapi.getTemperatures()
]).then(function(results) {
var resultString = '';
//console.log(results);
// OWM
results[0].list.forEach(function(data) {
//console.log('' + data.name + ': ' +(data.main.temp-273.15).toFixed(1));
var city = data.name;
var temp = (data.main.temp-273.15).toFixed(1);
var code = data.weather[0].icon;
resultString += '' + city + ' ('+temp+' °C), ';
resultString += '' + city + ' ('+temp+' °C, '+iconCodeToText[code]+'), ';
});
if(results[1].length > 0) {
//console.log(result[0].temp);
var temp = Number(results[1][0].temp).toFixed(1);
resultString += 'Aura (' + temp + ' °C)';
}
//console.log('Temp:', resultString);
// Pena
resolve(resultString);
});
@ -91,8 +155,11 @@ var getDiceString = function(numThrows, sides) {
return resultString;
};
/*
getTemperatureString().then(function(result) {
console.log(result);
});
*/
/*
var res = null;
@ -112,15 +179,25 @@ if (res = message.match(/^\.heita ([0-9]+)d([0-9]+)$/i)) {
console.log('Eioo');
} else {
var city = result.name;
var country = result.sys.country;
var temp = (result.main.temp-273.15).toFixed(1);
console.log(city, temp);
var sunriseDate = new Date(result.sys.sunrise*1000);
var sunsetDate = new Date(result.sys.sunset*1000);
var sunrise = sunriseDate.getHours() + '.' + sunriseDate.getMinutes();
var sunset = sunsetDate.getHours() + '.' + sunsetDate.getMinutes();
var humidity = result.main.humidity;
var pressure = result.main.pressure;
console.log(city, temp, country, sunrise, sunset, humidity, pressure);
}
}, function(error) {
console.log('fas',error);
});
}
*/
*/
var client = new irc.Client(config.irc.server, config.irc.nick, {
debug: true,
@ -145,9 +222,22 @@ client.addListener('message', function (from, to, message) {
client.say(to, 'Eioo: ' + res[2]);
} else {
var city = result.name;
var country = result.sys.country;
var temp = (result.main.temp-273.15).toFixed(1);
//console.log(city, temp);
client.say(to, 'Sää: '+city+' ('+temp+' °C)');
var code = result.weather[0].icon;
var sunriseDate = new Date(result.sys.sunrise*1000);
var sunsetDate = new Date(result.sys.sunset*1000);
var sunrise = sunriseDate.getHours() + '.' + sunriseDate.getMinutes();
var sunset = sunsetDate.getHours() + '.' + sunsetDate.getMinutes();
var humidity = result.main.humidity;
var pressure = result.main.pressure;
var windspeed = result.wind.speed;
//console.log(city, temp, code);
client.say(to, 'Sää: '+city+', '+country+' ('+temp+' °C, '+ iconCodeToText[code] +', ilmankosteus: '+humidity+' %, ilmanpaine: '+pressure+' hPa, tuulen nopeus: '+windspeed+' m/s)');
}
}, function(error) {
console.log('ERROR ',error);
@ -162,11 +252,53 @@ client.addListener('message', function (from, to, message) {
if (message.match(/^\.heit(a|ä) voltti homo$/i)) {
client.say(to, 'steam://run/1250');
}
if (message.match(/^\.op$/i)) {
client.send('NAMES', to);
}
}
});
client.addListener('join', function(channel, who) {
client.whois(who, function(result) {
console.log(result);
for(var memberNick in members) {
var member = members[memberNick];
if(result.host.match(member.host) && result.user.match(member.user)) {
client.send('MODE', channel, '+o', result.nick);
}
}
});
setTimeout(function() {
// client.say(channel, 'Moi ' + who + '!');
}, 4000);
});
client.addListener('error', function(message) {
console.log('error: ', message);
});
client.addListener('names', function(channel, nicks) {
console.log('names', channel, nicks);
if(typeof nicks[config.irc.nick] !== 'undefined' && nicks[config.irc.nick] === '@') {
// go through nicks
for(var nick in nicks) {
if(nicks[nick] !== '@') {
client.whois(nick, function(result) {
for(var memberNick in members) {
var member = members[memberNick];
if(result.host.match(member.host) && result.user.match(member.user)) {
console.log('testing', channel, result.nick);
client.send('MODE', channel, '+o', result.nick);
}
}
});
}
}
}
});