Skip to content

Instantly share code, notes, and snippets.

@mudge
Last active December 17, 2015 12:49
Show Gist options
  • Save mudge/5612814 to your computer and use it in GitHub Desktop.
Save mudge/5612814 to your computer and use it in GitHub Desktop.
A Hubot script to suggest names from Clive Murray's project namer.
# Description:
# Suggesting solid gold, business appropriate business names since 2013. Using Clive Murray's excellent
# http://codenames.clivemurray.com/
#
# Dependencies:
# "rsvp": "1.2.0"
#
# Configuration:
# None
#
# Commands:
# hubot suggest a name - Receive a project name
#
# Author:
# mudge
rsvp = require 'rsvp'
module.exports = (robot) ->
getJSON = (url) ->
promise = new rsvp.Promise
robot.http(url).get() (err, res, body) ->
promise.resolve JSON.parse(body)
promise
titlecase = (word) ->
word[0].toUpperCase() + word[1..-1].toLowerCase()
allPrefixes = getJSON 'http://codenames.clivemurray.com/data/prefixes.json'
allAnimals = getJSON 'http://codenames.clivemurray.com/data/animals.json'
robot.respond /suggest a( project)? name/i, (msg) ->
rsvp.all([allPrefixes, allAnimals]).then (words) ->
[prefixes, animals] = words
prefix = msg.random(prefixes).title
animal = msg.random(animals).title
msg.reply "How about #{titlecase(prefix)}#{titlecase(animal)}?"
/* Description:
* Suggesting solid gold, business appropriate business names since 2013. Using Clive Murray's excellent
* http://codenames.clivemurray.com/
*
* Dependencies:
* "rsvp": "1.2.0"
*
* Configuration:
* None
*
* Commands:
* hubot suggest a name - Receive a project name
*
* Author:
* mudge
*/
var rsvp = require('rsvp');
module.exports = function (robot) {
var getJSON = function (url) {
var promise = new rsvp.Promise();
robot.http(url).get()(function (err, res, body) {
promise.resolve(JSON.parse(body));
});
return promise;
};
var titleCase = function (word) {
return word[0].toUpperCase() + word.slice(1).toLowerCase();
};
var allPrefixes = getJSON('http://codenames.clivemurray.com/data/prefixes.json'),
allAnimals = getJSON('http://codenames.clivemurray.com/data/animals.json');
robot.respond(/suggest a( project)? name/i, function (msg) {
rsvp.all([allPrefixes, allAnimals]).then(function (words) {
var prefixes = words[0],
animals = words[1],
prefix = msg.random(prefixes).title,
animal = msg.random(animals).title;
msg.reply('How about ' + titleCase(prefix) + titleCase(animal) + '?');
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment