Skip to content
This repository was archived by the owner on Mar 26, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
20 changes: 12 additions & 8 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This bot demonstrates many of the core features of Botkit:
Run your bot from the command line:

set token=<MY TOKEN>

node bot.js

# USE THE BOT:
Expand Down Expand Up @@ -171,33 +171,37 @@ controller.hears(['uptime','identify yourself','who are you','what is your name'

controller.hears(['fibonacci'], 'direct_message,direct_mention,mention', function(bot, message) {
if (message.text === 'fibonacci') {
bot.reply(message, '1, 1, 2, 3, 5, 8, 13, 21, 34, 55');
bot.reply(message, '1, 1, 2, 3, 5');
}
});

controller.hears(['fibonacci ([0-9]+)'], 'direct_message,direct_mention,mention', function(bot, message) {
var parameter = parseInt(message.match[1]);

var fibonacci = calculateFibonacciUpto(parameter);
if (fibonacci[fibonacci.length-1] !== parameter) {

if (fibonacci[fibonacci.length-6] !== parameter) {
bot.reply(message, 'That is not a Fibonacci number!');
}
else {
bot.reply(message, fibonacci.slice(fibonacci.length-10,fibonacci.length).join(', '));
bot.reply(message, fibonacci.slice(fibonacci.length-5,fibonacci.length).join(', '));
}
});

function calculateFibonacciUpto(goal) {
var fibonacci = [1, 1];

while (fibonacci[fibonacci.length-1] < goal) {
fibonacci.push(fibonacci[fibonacci.length-2] + fibonacci[fibonacci.length-1]);
}

for(i=0; i< 5 ; i++){
fibonacci.push(fibonacci[fibonacci.length-2] + fibonacci[fibonacci.length-1]);
}

return fibonacci;
}


function formatUptime(uptime) {
var unit = 'second';
if (uptime > 60) {
Expand Down