-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjokes.js
32 lines (25 loc) · 1000 Bytes
/
jokes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
const utils = require('./utils');
module.exports = {
gotOne: function (entity, shorthandCMD) {
if (!entity || typeof entity != 'string') return false;
if (!shorthandCMD || typeof shorthandCMD != 'string') return false;
let c_entity = canonicalize(entity);
if (!Object.keys(JOKES).includes(c_entity)) return false;
let options = JOKES[canonicalize(c_entity)];
return Object.keys(options).includes(shorthandCMD);
},
randomIfAny: function (entity, shorthandCMD) {
if (! this.gotOne(entity, shorthandCMD)) return;
let options = JOKES[canonicalize(entity)][shorthandCMD];
return options[utils.randomIntExcl(options.length)];
},
isItAprilFoolDay: function() {
var now = new Date();
return (now.getMonth() == 3 && now.getDate() == 1);
}
}
function canonicalize(entity) {
return entity.toLowerCase();
}
const JOKES = utils.requireIfExists(process.env.JOKES, {});