Allow better configuration
This commit is contained in:
parent
283dddfac9
commit
bf7fd428a6
18
index.js
18
index.js
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "slack-phrase-command",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in a new issue