Commit edda1c86 authored by Farid Neshat's avatar Farid Neshat

WIP

parent aea1d8b5
// Description
// A hubot scripts that says good morning and logs the timeoffs
//
// Configuration:
// MORNING_ROOM_ID
//
// Commands
//
// Notes:
//
// Author: Farid Nouri Neshat <Farid@Olindata.com>
'use strict';
const moment = require('moment');
function scheduleForNextWorkingTime() {
const currentTime = new Date();
let nextMorning = moment(start).nextWorkingTime();
setTimeout(() => {
heardMorning({
});
scheduleForNextWorkingTime();
}, nextMorning - currentTime);
}
scheduleForNextWorkingTime();
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;
};
let lastTime = null;
function heardMorning(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;
}
}
module.exports = function (robot) {
robot.hear(/morning|moin/i, heardMorning);
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment