Skip to content

Commit

Permalink
Implement entertaining responses
Browse files Browse the repository at this point in the history
Currently robotk will come back with a single response at all times.
This could get boring and makes things more bureaucratic than ordinary
users would like to.

We're implementing a specific functionality to register a list of
responses and then return a .random() one when requested.
  • Loading branch information
paroxp committed Dec 22, 2017
1 parent 4710e52 commit f536fa2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
20 changes: 20 additions & 0 deletions lib/response.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Response {
constructor(resp) {
if (resp.constructor === Array) {
this.list = resp;
}
else {
this.list = [resp];
}
}

all() {
return this.list;
}

random() {
return this.list[Math.floor(Math.random() * this.list.length)];
}
}

module.exports = Response;
34 changes: 34 additions & 0 deletions lib/response.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { expect } = require('chai');
const Response = require('./response');

describe('Response', () => {
context('configured with set of responses', () => {
let response;
beforeEach(() => {
response = new Response(Array(999999).fill().map((_, idx) => 0 + idx));
});

it('should return a random() response correctly', () => {
const a = response.random();
const b = response.random();

expect(a).not.to.equal(b);
});
});

context('configured with a single response', () => {
let response;
beforeEach(() => {
response = new Response('success');
});

it('should return a random() response correctly', () => {
expect(response.random()).to.equal('success');
});

it('should return all() responses in a list', () => {
expect(response.all().length).to.equal(1);
expect(response.all()).to.contain('success');
});
});
});
28 changes: 23 additions & 5 deletions scripts/lit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,33 @@
// Author:
// mikestephens/harasho

const Response = require('../lib/response');

const failureMessages = new Response([
"The fuck you talking 'bout fam?",
'You kiss your mother with hat mouth?',
'Who do you think you are...',
'Arse biscuits.',
"nah, i'll pass :troll:"
]);

const successMessages = new Response([
'I gotchu fam',
"You're the boss! :+1:",
'Thought you may ask for that. I liked that too.',
'really? you seriously think that deserves fam? gee...',
'got your back, jack'
]);

// TODO: make this a configurable values
// paro: Just for the time being, let's keep these separate.
const channel = 'lit';
const failureMessage = "The fuck you talking 'bout fam?";
const successMessage = 'I gotchu fam';
const validURL = 'https://hashtaggaming.slack.com/archives/';

function hasAttachments(rawMessage) {
return rawMessage.attachments !== undefined && rawMessage.attachments.length > 0;
return rawMessage !== undefined &&
rawMessage.attachments !== undefined &&
rawMessage.attachments.length > 0;
}

module.exports = (robot) => {
Expand All @@ -31,11 +49,11 @@ module.exports = (robot) => {
}

if (param !== undefined && param.includes(validURL)) {
res.send(successMessage);
res.send(successMessages.random());
robot.messageRoom(channel, param);
}
else {
res.send(failureMessage);
res.send(failureMessages.random());
}
});
};

0 comments on commit f536fa2

Please sign in to comment.