Kernel plugin introduced
This commit is contained in:
parent
62c8bcd584
commit
4babc165f8
52
app.js
52
app.js
|
@ -36,6 +36,7 @@ var getDiceString = require('./plugins/getDice')();
|
|||
var getUrlString = require('./plugins/getUrl')();
|
||||
var getTweet = require('./plugins/getTweet')(config);
|
||||
var getInstantAnswer = require('./plugins/getInstantAnswer')(config);
|
||||
var getKernelData = require('./plugins/getKernel')();
|
||||
|
||||
// Configure logger
|
||||
// create a write stream (in append mode)
|
||||
|
@ -120,6 +121,53 @@ var handleMessage = function(from, to, message) {
|
|||
})
|
||||
}
|
||||
|
||||
// Kernel version
|
||||
if (res = message.match(/^\.kernel( (.+))?/i)) {
|
||||
console.log('Search kernel version ' + res[2]);
|
||||
var version = res[2];
|
||||
getKernelData().then(function(data) {
|
||||
var text = 'kernel: ';
|
||||
|
||||
// Store current versions!
|
||||
var releaseToVersion = {};
|
||||
data.releases.forEach(function(val) {
|
||||
var regex = /([0-9]+?)(\.([0-9]+))?(\.([0-9]+))?/;
|
||||
var result = val.version.match(regex);
|
||||
|
||||
var major = result[1];
|
||||
var minor = result[3];
|
||||
|
||||
if(typeof major !== 'undefined' && typeof minor !== 'undefined') {
|
||||
var releaseWithVersion = val.moniker + '-' + major + '-' + minor;
|
||||
var release = val.moniker + '';
|
||||
|
||||
if(typeof releaseToVersion[releaseWithVersion] !== 'undefined') {
|
||||
if(releaseToVersion[releaseWithVersion] !== val.version) {
|
||||
// new release
|
||||
|
||||
}
|
||||
}
|
||||
if(typeof releaseToVersion[release] === 'undefined') {
|
||||
releaseToVersion[release] = val.version;
|
||||
}
|
||||
|
||||
releaseToVersion[releaseWithVersion] = val.version;
|
||||
}
|
||||
});
|
||||
|
||||
if(typeof releaseToVersion[version] !== 'undefined') {
|
||||
text += 'Viimeisin versio on ' + releaseToVersion[version] + ' (' + version + ')';
|
||||
} else {
|
||||
|
||||
text += 'Viimeisin vakaa versio on ' + data.latest_stable.version;
|
||||
}
|
||||
console.log(text);
|
||||
|
||||
client.say(to, text);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Throw dice
|
||||
if (res = message.match(/^\.heit(a|ä) ([0-9]+)d([0-9]+)$/i)) {
|
||||
var th = getDiceString(res[2], res[3]);
|
||||
|
@ -146,8 +194,8 @@ var handleMessage = function(from, to, message) {
|
|||
}
|
||||
|
||||
// Url specific handling
|
||||
if (res = message.match(/http(s)?:\/\/(www\.)?((youtu\.be\/([a-zA-Z0-9_-]*))|(youtube\.com\/watch\?v=([a-zA-Z0-9_-]*)))/)) {
|
||||
|
||||
//if (res = message.match(/http(s)?:\/\/(www\.)?((youtu\.be\/([a-zA-Z0-9_-]*))|(youtube\.com\/watch\?v=([a-zA-Z0-9_-]*)))/)) {
|
||||
if(res = message.match(/http(s)?:\/\/(www\.)?((youtu\.be\/([a-zA-Z0-9_-]*))|(youtube\.com\/watch\?([a-zA-Z0-9_=#-]+&)*v=([a-zA-Z0-9_-]+)))/)) {
|
||||
console.log(res);
|
||||
var id = res[7];
|
||||
if(typeof id === 'undefined') {
|
||||
|
|
46
appTest.js
46
appTest.js
|
@ -1,4 +1,48 @@
|
|||
|
||||
var getKernelData = require('./plugins/getKernel')();
|
||||
|
||||
var res = 'longterm';
|
||||
|
||||
getKernelData(res).then(function(data) {
|
||||
var version = res;
|
||||
var text = 'kernel: ';
|
||||
|
||||
// Store current versions!
|
||||
var releaseToVersion = {};
|
||||
data.releases.forEach(function(val) {
|
||||
var regex = /([0-9]+?)(\.([0-9]+))?(\.([0-9]+))?/;
|
||||
var result = val.version.match(regex);
|
||||
|
||||
var major = result[1];
|
||||
var minor = result[3];
|
||||
|
||||
if(typeof major !== 'undefined' && typeof minor !== 'undefined') {
|
||||
var releaseWithVersion = val.moniker + '-' + major + '-' + minor;
|
||||
var release = val.moniker + '';
|
||||
|
||||
if(typeof releaseToVersion[releaseWithVersion] !== 'undefined') {
|
||||
if(releaseToVersion[releaseWithVersion] !== val.version) {
|
||||
// new release
|
||||
|
||||
}
|
||||
}
|
||||
if(typeof releaseToVersion[release] === 'undefined') {
|
||||
releaseToVersion[release] = val.version;
|
||||
}
|
||||
|
||||
releaseToVersion[releaseWithVersion] = val.version;
|
||||
}
|
||||
});
|
||||
|
||||
if(typeof releaseToVersion[version] !== 'undefined') {
|
||||
text += 'Viimeisin versio on ' + releaseToVersion[version] + ' (' + version + ')';
|
||||
} else {
|
||||
|
||||
text += 'Viimeisin vakaa versio on ' + data.latest_stable.version;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
var text = 'Hei! https://youtu.be/TLW6eTV8F_I hienoo';
|
||||
var text = 'Hei! https://www.youtube.com/watch?v=AMlf-KXVOsQ hienoo';
|
||||
var text = 'Hei! https://www.youtu.be/TLW6eTV8F_I https://www.youtube.com/watch?v=AMlf-KXVOsQ hienoo';
|
||||
|
@ -19,7 +63,7 @@ ddg.instantAnswer('dw', {skip_disambig: '0'}, function(err, response) {
|
|||
console.log(response);
|
||||
console.log('"' + response.RelatedTopics[0].Text + '" | ' + response.RelatedTopics[0].FirstURL);
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
|
33
plugins/getKernel.js
Normal file
33
plugins/getKernel.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
var request = require('request');
|
||||
var Promise = require('promise');
|
||||
var requestPromise = function(url, urlArgs) {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
request({
|
||||
url: url,
|
||||
qs: urlArgs,
|
||||
json: false
|
||||
}, function(error, response, body) {
|
||||
if(!error && response.statusCode == 200) {
|
||||
resolve(JSON.parse(body));
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
};
|
||||
|
||||
module.exports = function(config) {
|
||||
'use strict';
|
||||
var getKernelData = function(queryText) {
|
||||
var urlArgs = {};
|
||||
var url = 'https://www.kernel.org/releases.json';
|
||||
|
||||
var promise = requestPromise(url, urlArgs);
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
return getKernelData;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user