diff --git a/lib/response.js b/lib/response.js new file mode 100644 index 0000000..ec440fe --- /dev/null +++ b/lib/response.js @@ -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; diff --git a/lib/response.spec.js b/lib/response.spec.js new file mode 100644 index 0000000..2a9d6ca --- /dev/null +++ b/lib/response.spec.js @@ -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'); + }); + }); +}); diff --git a/scripts/lit.js b/scripts/lit.js index e56847b..f2876e1 100644 --- a/scripts/lit.js +++ b/scripts/lit.js @@ -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) => { @@ -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()); } }); };