Allow better configuration

This commit is contained in:
Kegan Myers 2014-08-09 17:49:22 -05:00
parent 283dddfac9
commit bf7fd428a6
2 changed files with 17 additions and 3 deletions

View file

@ -1,4 +1,5 @@
var _ = require('lodash'); var fs = require('fs'),
_ = require('lodash');
module.exports = function(configuration) { module.exports = function(configuration) {
var listenOn = (function(name) { var listenOn = (function(name) {
@ -14,10 +15,23 @@ module.exports = function(configuration) {
return ["phrase"]; return ["phrase"];
} }
})(configuration.command); })(configuration.command);
var phrases = configuration.phrases;
phrases = (typeof phrases === "object" && phrases instanceof Array) ? phrases : [];
if (typeof configuration.phraseFile === "string") {
phrases = _.compact(_.union(phrases, fs.readFileSync(configuration.phraseFile).split("\n")));
}
function phrase() {
if (phrases.length)
return phrases[Math.floor(Math.random() * phrases.length)];
return "This phrase command has not been properly configured."
}
function handler(slack) { function handler(slack) {
try { try {
slack.replyUser(slack.text); slack.replyUser(phrase());
} catch (e) { } catch (e) {
slack.error(e.toString()); slack.error(e.toString());
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "slack-phrase-command", "name": "slack-phrase-command",
"version": "0.0.1", "version": "0.0.2",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {