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

Report on Issues #20

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
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
readme.md
2 changes: 2 additions & 0 deletions .tokens
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xoxb-22472064529-JAIGuEXDPHAcHAJo0ibisUEY
xoxb-22472064529-JAIGuEXDPHAcHAJo0ibisUEY
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 0.12.0
23 changes: 23 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# Bug Report
---
## Nature of bug
Choose an Email ?
_____

Choose a password
******

Describe why you want to register
____
_____

Gender
male/female

Which of these features will you need?
[+] simplicity
[-] Don't know
[-] complete

[ok]
9 changes: 9 additions & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Issue Report
---

- [ ] a task list item
- [ ] list syntax required
- [ ] normal **formatting**, @mentions, #1234 refs
- [ ] incomplete
- [x] completed
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node bot.js
100 changes: 99 additions & 1 deletion bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ This bot demonstrates many of the core features of Botkit:

-> http://howdy.ai/botkit

Test line
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


Expand All @@ -73,6 +74,7 @@ if (!process.env.token) {

var Botkit = require('./lib/Botkit.js');
var os = require('os');
var botmath = require('./botmath.js');

var controller = Botkit.slackbot({
debug: true,
Expand All @@ -88,7 +90,7 @@ controller.hears(['hello','hi'],'direct_message,direct_mention,mention',function
bot.api.reactions.add({
timestamp: message.ts,
channel: message.channel,
name: 'robot_face',
name: 'robot_face'
},function(err, res) {
if (err) {
bot.botkit.log('Failed to add emoji reaction :(',err);
Expand Down Expand Up @@ -121,6 +123,37 @@ controller.hears(['call me (.*)'],'direct_message,direct_mention,mention',functi
});
});

controller.hears(['prime (.*)'], 'direct_message,direct_mention,mention', function(bot, message) {
var matches = message.text.match(/prime (.*)/i);
var number = parseInt(matches[1]);
var primes = nextTenPrimes(number);
var primes = lastTenPrimes(number);
if (number >=0){
if(isPrime(number)) {
bot.reply(message, 'number is a prime');
} else {

//bot.reply(message, 'number is not a prime, next 10 primes are ' + primes.toString());

bot.reply(message, 'number is not a prime, last 10 primes are ' + primes.toString());
}
}



});

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

var i = message.text.lastIndexOf('.');
if (i != -1) {
bot.reply(message, '2, 3, 5, 7, 11, 13, 17, 19, 23, 29');

}
});



controller.hears(['what is my name','who am i'],'direct_message,direct_mention,mention',function(bot, message) {

controller.storage.users.get(message.user,function(err, user) {
Expand All @@ -132,6 +165,16 @@ controller.hears(['what is my name','who am i'],'direct_message,direct_mention,m
});
});

controller.hears(['who made you'], 'direct_message,direct_mention,mention', function(bot, message) {
controller.storage.users.get(message.user,function(err, user) {
if (user && user.name) {
bot.reply(message,'You made me - master ' + user.name + '!!');
} else {
bot.reply(message,'I don\'t know yet!.');
}
});
});


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

Expand Down Expand Up @@ -169,6 +212,12 @@ controller.hears(['uptime','identify yourself','who are you','what is your name'

});

controller.hears(['how old are you'],'direct_message,direct_mention,mention',function(bot, message) {

bot.reply(message,':robot_face: I am a bot named <@' + bot.identity.name + '>. I am ' + uptime + ' old');

});

function formatUptime(uptime) {
var unit = 'second';
if (uptime > 60) {
Expand All @@ -186,3 +235,52 @@ function formatUptime(uptime) {
uptime = uptime + ' ' + unit;
return uptime;
}


function isPrime(n) {
if (isNaN(n) || !isFinite(n) || n%1 || n<2) return false;
if (n%2==0) return (n==2);
var m=Math.sqrt(n);
for (var i=3;i<=m;i+=2) {
if (n%i==0) return false;
}
return true;
}

function nextTenPrimes(n) {
var primes = [];

do{
if(isPrime(n)){
primes.push(n);
}
n++;
}while(primes.length <10)
return primes;
}

function lastTenPrimes(n) {
var primes = [];

do{
if(isPrime(n)){
primes.push(n);
}
n--;
if(n < 1) break;
}while(primes.length <10)
return primes;
}

controller.hears('what is (.*) \\+ (.*)',['direct_message', 'direct_mention', 'mention'],function(bot,message) {

var num1 = message.match[1];
var num2 = message.match[2];

if (num1 != null && num2 != null) {
return bot.reply(message, num1 + ' + ' + num2 + ' = ' + botmath.sum(num1, num2));
}
});

module.exports.isPrime = isPrime;
module.exports.lastTenPrimes = lastTenPrimes;
5 changes: 5 additions & 0 deletions botmath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var sum = function (num1, num2) {
return parseFloat(num1) + parseFloat(num2);
}

module.exports.sum = sum;
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"eventemitter2": "0.4.14",
"express": "^4.13.3",
"jfs": "^0.2.6",
"mocha": "^2.4.5",
"mustache": "^2.2.1",
"request": "^2.67.0",
"ws": "^1.0.0"
Expand All @@ -21,6 +22,9 @@
"tape": "^4.4.0",
"winston": "^2.1.1"
},
"scripts": {
"test": "mocha tests/*.js"
},
"repository": {
"type": "git",
"url": "https://github.com/juhovan/botkit.git"
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ npm install --production

2) First make a bot integration inside of your Slack channel. Go here:

https://my.slack.com/services/new/bot


Enter a name for your bot.
Make it something fun and friendly, but avoid a single task specific name.
Expand Down
16 changes: 16 additions & 0 deletions tests/botmathTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var assert = require('assert');
var bothmath = require('../botmath.js');

describe('botmath', function() {
describe('sum', function () {
it('should return sum of 2 values', function () {
assert.equal(-2, bothmath.sum(-2, 0));
assert.equal(1, bothmath.sum(-1, 2));
assert.equal(6.5, bothmath.sum(3.5, 3));
assert.equal(1337, bothmath.sum(1338.2, -1.2));
})
it('should return NaN if both values are not numeric', function () {
assert.ok(isNaN(bothmath.sum(1335, 'a')));
});
});
});
15 changes: 15 additions & 0 deletions tests/lastTenPrimesTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Created by olegba on 24/02/16.
*/
var assert = require('assert');
var bot = require('../bot.js');
var lastTenPrimes = bot.lastTenPrimes;


describe('Is prime', function() {
it('should return an array of last ten prime numbers when the value is not a prime, or less then ten values', function () {
assert.deepEqual([19,17,13,11,7,5,3,2], lastTenPrimes(20));
assert.deepEqual([31,29,23,19,17,13,11,7,5,3], lastTenPrimes(33));
assert.deepEqual([], lastTenPrimes(1));
});
});
15 changes: 15 additions & 0 deletions tests/primeTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Created by olegba on 23/02/16.
*/
var assert = require('assert');
var bot = require('../bot.js');
var isPrime = bot.isPrime;


describe('Is prime', function() {
it('should return false when the value is not a prime number or true if the number is prime', function () {
assert.equal(false, isPrime(8));
assert.equal(true, isPrime(7));
assert.equal(false, isPrime(0));
});
});
10 changes: 10 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var assert = require('assert');

describe('Array', function() {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal(-1, [1,2,3].indexOf(5));
assert.equal(-1, [1,2,3].indexOf(0));
});
});
});
1 change: 1 addition & 0 deletions text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Line of text
16 changes: 16 additions & 0 deletions weather/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See editorconfig.org

root = true

[*]

indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

[*.md]

trim_trailing_whitespace = false
17 changes: 17 additions & 0 deletions weather/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
* text=auto

*.png binary
*.jpg binary
*.gif binary
*.ico binary

*.txt text
*.md text
*.html text
*.css text
*.js text
*.json text

*.bat text
*.sh text
*.exe binary
14 changes: 14 additions & 0 deletions weather/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules/
npm-debug.log

.DS_Store
.idea

*.log
*.heapsnapshot
.coverrun
.coverdata
dump.rdb
xunit.xml

sources/
28 changes: 28 additions & 0 deletions weather/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"node": true,
"browser": false,
"esnext": true,
"strict": true,
"unused": true,
"undef": true,
"quotmark": "single",
"indent": 2,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,

"globals": {
},

"predef": [
"describe",
"it",
"before",
"beforeEach",
"after",
"afterEach"
]
}
5 changes: 5 additions & 0 deletions weather/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.12"
- "0.10"
- "iojs"
Loading