Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Submodule Add How is the temperature in / #16

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "weather"]
path = weather
url = https://github.com/cmfatih/weather
83 changes: 71 additions & 12 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 @@ -66,6 +66,9 @@ This bot demonstrates many of the core features of Botkit:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/





if (!process.env.token) {
console.log('Error: Specify token in environment');
process.exit(1);
Expand All @@ -83,7 +86,6 @@ var bot = controller.spawn({
token: process.env.token
}).startRTM();


controller.hears(['hello','hi'],'direct_message,direct_mention,mention',function(bot, message) {

bot.api.reactions.add({
Expand Down Expand Up @@ -133,6 +135,21 @@ controller.hears(['what is my name','who am i'],'direct_message,direct_mention,m
});
});

function isPrime(number) {
var start = 2;
while (start <= Math.sqrt(number)) {
if (number % start++ < 1) return false;
}
return number > 1;
}

controller.hears(['who make you','who made you'],'direct_message,direct_mention,mention',function(bot, message) {

controller.storage.users.get(message.user,function(err, user) {
bot.reply(message,'Metro group made me. Hihi');
});
});


controller.hears(['shutdown'],'direct_message,direct_mention,mention',function(bot, message) {

Expand Down Expand Up @@ -171,30 +188,31 @@ 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) {
bot.reply(message, 'That is not a Fibonacci number!');
}
else {
bot.reply(message, fibonacci.slice(fibonacci.length-10,fibonacci.length).join(', '));
for (var i = 0; i < 5; i++){
fibonacci.push(fibonacci[fibonacci.length-2] + fibonacci[fibonacci.length-1])
}
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]);
}

return fibonacci;
}

Expand Down Expand Up @@ -227,16 +245,17 @@ controller.hears('prime (.*)',['direct_message', 'direct_mention', 'mention'],fu
var parameter = parseInt(message.match[1]);

if (MathHelper.isPrime(parameter)) {
bot.reply(message, "your parameter: " + parameter + " is a Prime number");
var primes = new Array();
var number = parameter + 1;
var number = parameter - 1;

while (primes.length < 10) {
while (primes.length < 10 && number >=0) {

if (MathHelper.isPrime(number)) {
primes.push(number);
}

number++;
number--;
}

var reply = "";
Expand All @@ -247,7 +266,47 @@ controller.hears('prime (.*)',['direct_message', 'direct_mention', 'mention'],fu
return bot.reply(message, reply);
}
else {
return bot.reply(message, "your parameter: " + parameter + " is not Prime number");
bot.reply(message, "your parameter: " + parameter + " is not Prime number");
var primes = new Array();
var number = parameter - 1;

while (primes.length < 10 && number >=0) {

if (MathHelper.isPrime(number)) {
primes.push(number);
}

number--;
}

var reply = "";
for (var i = 0; i < primes.length; i++) {
reply += primes[i] + " ";
}

return bot.reply(message, reply);
}
});

var weather = require('weather-js');

weather.find({search: 'San Francisco, CA', degreeType: 'F'}, function(err, result) {
if(err) console.log(err);

console.log(JSON.stringify(result, null, 2));
});

controller.hears('How is the temperature in (.*)',['direct_message','mention'],function(bot,message) {

var city = message.match[1];
console.log(city);

weather.find({search: city, degreeType: 'C'}, function(err, result) {
if(err) console.log(err);

console.log(JSON.stringify(result, null, 2));

return bot.reply(message,'The temperature is ' + result[0]['current']['temperature'] + ' degree Celcius');
});

});
1 change: 1 addition & 0 deletions weather
Submodule weather added at cc3337