Skip to content

Commit

Permalink
Add eslint rules.
Browse files Browse the repository at this point in the history
Clean up source code.
  • Loading branch information
HaroldPutman committed Nov 9, 2016
1 parent 81e15f9 commit 2399240
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 54 deletions.
12 changes: 11 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
{
"extends": "eslint:recommended"
"extends": "eslint:recommended",
"env": {
"es6": true,
"node": true,
"mocha": true
},
"rules": {
"strict": 0,
"indent": ["error", 2],
"no-console": 2
}
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"main": "dist/main.js",
"license": "ISC",
"author": {
"name": "Harold Putman",
"email": "harold.putman@lexmark.com"
"name": "Harold Putman",
"email": "harold.putman@lexmark.com"
},
"repository": "https://github.com//hubot-taboo-topics.git",
"keywords": [
"hubot-scripts",
"hubot-scripts",
"hubot",
"fun"
] ,
],
"scripts": {
"build": "babel src -d dist",
"start": "babel src -d scripts; hubot --adapter shell --disable-httpd",
Expand All @@ -30,6 +30,7 @@
"chai": "^3.4.1",
"coffee-script": "^1.11.1",
"coveralls": "^2.11.6",
"eslint": "^3.9.1",
"hubot": "^2.19.0",
"hubot-test-helper": "^1.4.4",
"istanbul": "^1.0.0-alpha.2",
Expand Down
54 changes: 27 additions & 27 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ module.exports = (robot) => {
// Recall the Taboo list from brain
const taboolist = robot.brain.get("taboo");
if (taboolist != null) {
for (topic of taboolist) {
for (let topic of taboolist) {
taboo.set(topic, new RegExp(`\\b${topic}\\b`, "i"));
}
}

// Get the frequency at which to complain
// 0 means never, 100 means always
let frequency = parseInt(process.env["HUBOT_TABOO_FREQUENCY"], 10);
if (frequency == NaN | frequency < 0 || frequency > 100) {
if (isNaN(frequency) | frequency < 0 || frequency > 100) {
frequency = 100;
}

Expand Down Expand Up @@ -169,32 +169,32 @@ module.exports = (robot) => {
* Listen for taboo topics.
*/
robot.listen((msg) => {
if (msg.constructor.name === 'CatchAllMessage') {
return false;
}
if (msg.text.match(robotNameRe)) {
// Ignore taboo words spoken to Hubot. This prevents
// getting scolded immediately after setting a taboo topic.
return false;
}
let matched = false;
taboo.forEach((re) => {
if (!matched) {
var match = msg.text.match(re);
if (match) {
matched = match[0]
}
}
});
return matched;
}, (res) => {
// Complain about the use of taboo topic.
if (Math.floor(Math.random() * 99 + 1) <= frequency) {
let response = res.random(data.responses);
response = insert(response, "topic", res.match);
response = insert(response, "user", res.message.user.name);
res.reply(capitalize(response));
if (msg.constructor.name === 'CatchAllMessage') {
return false;
}
if (msg.text.match(robotNameRe)) {
// Ignore taboo words spoken to Hubot. This prevents
// getting scolded immediately after setting a taboo topic.
return false;
}
let matched = false;
taboo.forEach((re) => {
if (!matched) {
var match = msg.text.match(re);
if (match) {
matched = match[0]
}
}
});
return matched;
}, (res) => {
// Complain about the use of taboo topic.
if (Math.floor(Math.random() * 99 + 1) <= frequency) {
let response = res.random(data.responses);
response = insert(response, "topic", res.match);
response = insert(response, "user", res.message.user.name);
res.reply(capitalize(response));
}
});

};
51 changes: 29 additions & 22 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,33 @@ NewMockResponse = (function(superClass) {

describe('hubot', () => {

let room;

beforeEach(function() { room = helper.createRoom({response: NewMockResponse})});
afterEach(function() { room.destroy()});

it('should respond when making topic taboo', (done) => {

room.user.say('alice', 'hubot refactoring is taboo').then(() => {
room.user.say('alice', 'I love the taste of refactoring.').then(() => {
console.log(room.messages);
expect(room.messages).to.eql([
['alice', 'hubot refactoring is taboo'],
['hubot', '@alice Refactoring is now taboo'],
['alice', 'I love the taste of refactoring.'],
['hubot', '@alice Do not speak of refactoring.'],
]);
done();
});
});

});

let room;

beforeEach(function() { room = helper.createRoom({response: NewMockResponse})});
afterEach(function() { room.destroy()});

it('should respond when making topic taboo', (done) => {
room.user.say('alice', 'hubot refactoring is taboo').then(() => {
expect(room.messages).to.eql([
['alice', 'hubot refactoring is taboo'],
['hubot', '@alice Refactoring is now taboo'],
]);
done();
});

});

it('should respond when making topic no longer taboo', (done) => {
room.user.say('becky', 'hubot taboo leverage.').then(() => {
room.user.say('becky', 'hubot untaboo leverage').then(() => {
expect(room.messages).to.eql([
['becky', 'hubot taboo leverage.'],
['hubot', '@becky Leverage is now taboo'],
['becky', 'hubot untaboo leverage'],
['hubot', '@becky Leverage is no longer taboo'],
]);
done();
});
});
});
});

0 comments on commit 2399240

Please sign in to comment.