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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/.idea
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.git
42 changes: 37 additions & 5 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ var bot = controller.spawn({
token: process.env.token
}).startRTM();

const weather = require('./weather/lib/weather.js');

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

var input1 = message.match[1];
var input2 = message.match[2];
console.log(input1);
console.log(input2);
weather.find({search: input1 + " " + input2, degreeType: 'C'}, function (err, result) {
console.log(JSON.stringify(result, null, 2));
if(result !== undefined){
bot.reply(message, JSON.stringify(result[0].current.temperature, null, 2));
}else{
bot.reply(message, "You dont make any sence");
}
});
});

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

Expand Down Expand Up @@ -171,7 +188,7 @@ 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');
}
});

Expand All @@ -184,17 +201,28 @@ controller.hears(['fibonacci ([0-9]+)'], 'direct_message,direct_mention,mention'
bot.reply(message, 'That is not a Fibonacci number!');
}
else {
bot.reply(message, fibonacci.slice(fibonacci.length-10,fibonacci.length).join(', '));
var a = fibonacci[fibonacci.length-1];
var b;
if(fibonacci.length>1){
b=fibonacci[fibonacci.length-2];
}else{
b=0;
}
var nextFive = [];
for(var i = 0; i<5; i++){
nextFive.push(a+b);
b = a;
a = nextFive[i];
}
bot.reply(message, nextFive.slice(0,nextFive.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 @@ -235,8 +263,12 @@ controller.hears('prime (.*)',['direct_message', 'direct_mention', 'mention'],fu
if (MathHelper.isPrime(number)) {
primes.push(number);
}

if(number ==0) {
break;
}

number++;
number--;
}

var reply = "";
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"jfs": "^0.2.6",
"mustache": "^2.2.1",
"request": "^2.67.0",
"ws": "^1.0.0"
"ws": "^1.0.0",
"xml2js": "*"
},
"devDependencies": {
"jscs": "^2.7.0",
Expand All @@ -20,6 +21,7 @@
"tap-spec": "^4.1.1",
"tape": "^4.4.0",
"winston": "^2.1.1"

},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions weather
Submodule weather added at cc3337