New Joke plugin. Updated configuration!
This commit is contained in:
parent
a07b24bbaa
commit
a3c9cf4f76
|
@ -8,6 +8,7 @@ var config = {
|
|||
'Tweet',
|
||||
'Url',
|
||||
'Weather',
|
||||
'Joke',
|
||||
],
|
||||
irc: {
|
||||
connect: true,
|
||||
|
@ -24,6 +25,10 @@ var config = {
|
|||
user: /lanxu$/,
|
||||
host: /(.*)\.elisa-laajakaista\.fi$/
|
||||
},
|
||||
'lanxu3': {
|
||||
user: /lanxu/,
|
||||
host: /(.*)\.kapsi\.fi$/
|
||||
},
|
||||
'asdfas': {
|
||||
user: /asdfas$/,
|
||||
host: /(.*)\.ssp\.fi$/
|
||||
|
@ -44,6 +49,10 @@ var config = {
|
|||
user: /mindflaye$/,
|
||||
host: /(.*)opintanner\.fi$/
|
||||
},
|
||||
'mindflayer2': {
|
||||
user: /mindflaye$/,
|
||||
host: /(.*)inet\.fi$/
|
||||
},
|
||||
'pariah': {
|
||||
user: /rautia$/,
|
||||
host: /mozart\.cc\.tut\.fi$/
|
||||
|
|
59
plugins/joke.js
Normal file
59
plugins/joke.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
var Promise = require('promise');
|
||||
var requestPromise = require('./helpers/requestPromise.js');
|
||||
var BasePlugin = require('./base.js');
|
||||
var logger = require('winston');
|
||||
|
||||
class Joke extends BasePlugin {
|
||||
constructor(config) {
|
||||
super(config);
|
||||
this.name = 'Joke';
|
||||
}
|
||||
|
||||
test(input) {
|
||||
var res = null;
|
||||
if (res = input.match(/^\.vitsi$/i)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
getJoke() {
|
||||
var urlArgs = {};
|
||||
var url = 'https://icanhazdadjoke.com/';
|
||||
|
||||
var promise = requestPromise(url, urlArgs, {
|
||||
'Accept': 'application/json',
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
result(input) {
|
||||
var that = this;
|
||||
var resultPromise = new Promise(function(resultResolve, resultReject) {
|
||||
var res = null;
|
||||
if (res = input.match(/^\.vitsi$/i)) {
|
||||
that.getJoke().then(function(data) {
|
||||
var text = 'Vitsi: ';
|
||||
|
||||
var joke = data.joke;
|
||||
if(typeof joke === 'undefined' || joke === null) {
|
||||
resultReject('No joke!');
|
||||
}
|
||||
|
||||
text += "\"" + joke + "\"";
|
||||
|
||||
resultResolve(text);
|
||||
|
||||
}, function(error) {
|
||||
resultReject(error);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return resultPromise;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Joke;
|
|
@ -27,8 +27,10 @@ class Youtube extends BasePlugin {
|
|||
var resultString = 'Youtube: ';
|
||||
resultString += result.title;
|
||||
resultString += ', esittäjänä ' + result.channelTitle;
|
||||
var rotten = (Number(result.statistics.likeCount)/(Number(result.statistics.likeCount)+Number(result.statistics.dislikeCount))).toFixed(2);
|
||||
resultString += ' ('+result.duration+', '+ result.statistics.viewCount +' katselukertaa, '+rotten*100+'% tykätty, '+result.url+' )';
|
||||
if(typeof result.statistics !== 'undefined') {
|
||||
var rotten = (Number(result.statistics.likeCount)/(Number(result.statistics.likeCount)+Number(result.statistics.dislikeCount))).toFixed(2);
|
||||
resultString += ' ('+result.duration+', '+ result.statistics.viewCount +' katselukertaa, '+rotten*100+'% tykätty, '+result.url+' )';
|
||||
}
|
||||
resolve(resultString);
|
||||
}, function(err) {
|
||||
logger.info('Error', err);
|
||||
|
|
Loading…
Reference in New Issue
Block a user