New Joke plugin. Updated configuration!

This commit is contained in:
lanxu 2017-07-15 13:58:28 +03:00
parent a07b24bbaa
commit a3c9cf4f76
3 changed files with 75 additions and 5 deletions

View File

@ -8,6 +8,7 @@ var config = {
'Tweet', 'Tweet',
'Url', 'Url',
'Weather', 'Weather',
'Joke',
], ],
irc: { irc: {
connect: true, connect: true,
@ -23,6 +24,10 @@ var config = {
'lanxu2': { 'lanxu2': {
user: /lanxu$/, user: /lanxu$/,
host: /(.*)\.elisa-laajakaista\.fi$/ host: /(.*)\.elisa-laajakaista\.fi$/
},
'lanxu3': {
user: /lanxu/,
host: /(.*)\.kapsi\.fi$/
}, },
'asdfas': { 'asdfas': {
user: /asdfas$/, user: /asdfas$/,
@ -44,6 +49,10 @@ var config = {
user: /mindflaye$/, user: /mindflaye$/,
host: /(.*)opintanner\.fi$/ host: /(.*)opintanner\.fi$/
}, },
'mindflayer2': {
user: /mindflaye$/,
host: /(.*)inet\.fi$/
},
'pariah': { 'pariah': {
user: /rautia$/, user: /rautia$/,
host: /mozart\.cc\.tut\.fi$/ host: /mozart\.cc\.tut\.fi$/

59
plugins/joke.js Normal file
View 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;

View File

@ -27,8 +27,10 @@ class Youtube extends BasePlugin {
var resultString = 'Youtube: '; var resultString = 'Youtube: ';
resultString += result.title; resultString += result.title;
resultString += ', esittäjänä ' + result.channelTitle; resultString += ', esittäjänä ' + result.channelTitle;
if(typeof result.statistics !== 'undefined') {
var rotten = (Number(result.statistics.likeCount)/(Number(result.statistics.likeCount)+Number(result.statistics.dislikeCount))).toFixed(2); 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+' )'; resultString += ' ('+result.duration+', '+ result.statistics.viewCount +' katselukertaa, '+rotten*100+'% tykätty, '+result.url+' )';
}
resolve(resultString); resolve(resultString);
}, function(err) { }, function(err) {
logger.info('Error', err); logger.info('Error', err);