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) {
var listenOn = (function(name) {
@ -14,10 +15,23 @@ module.exports = function(configuration) {
return ["phrase"];
}
})(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) {
try {
slack.replyUser(slack.text);
slack.replyUser(phrase());
} catch (e) {
slack.error(e.toString());
}

View File

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