hubot-human-goodmorning
Version:
A hubot scripts that says goodmorning only once and after somebody else has said it
86 lines (75 loc) • 1.8 kB
JavaScript
// Description
// A hubot scripts that says goodmorning only once and after somebody else has said it
//
// Configuration:
//
// MORNING_ROOM_ID
//
// Commands
//
// Notes:
//
// Author:
// Farid Nouri Neshat <Farid@Olindata.com>
;
const ONE_HOUR = 1000 * 60 * 60; const ONE_DAY = ONE_HOUR * 24; const random = require('just-random');
const mornings = [
'marnin',
'morning',
'morning',
'morning',
'morning',
'morning',
'morning',
'moin',
];
const place = [
'AWS',
'cloud',
'home',
'the VPC',
'EC2',
'office'
];
const endings = ['', '', '.', '.', '!', '!', '...', '...', '!!!'];
const smileys = ['', '', '', '', '', ' :D', ' :)'];
const isLikely = (p = 0.1) => Math.random() < p;
const isMorning = () => {
const hour = new Date().getHours();
return hour < 11 && hour > 6;
};
module.exports = function (robot) {
let lastTime = null;
robot.hear(/morning|moin/i, res => {
if (process.env.MORNING_ROOM_ID) {
if (res.message.room !== process.env.MORNING_ROOM_ID) {
return;
}
}
const day = Math.floor(Date.now() / ONE_DAY);
if (day > lastTime && isMorning()) {
setTimeout(() => {
let message = random(mornings);
if (isLikely()) {
message += ' people';
}
if (isLikely()) {
message += random(endings) + ' ';
if (isLikely()) {
message += 'I\'m';
}
message += 'working from ' + random(place);
if (isLikely()) {
message += ' today';
}
}
if (isLikely()) {
message += '. Ready for your commands';
}
message += random(endings) + random(smileys);
res.send(message);
}, Math.random() * ONE_HOUR);
lastTime = day;
}
});
};