sayhi-ai
Advanced tools
Comparing version 1.0.0 to 1.0.1
30
index.js
@@ -14,2 +14,7 @@ var request = require('request-json'); | ||
function rand(min,max) | ||
{ | ||
return Math.floor(Math.random()*(max-min+1)+min); | ||
} | ||
module.exports = { | ||
@@ -25,2 +30,6 @@ init: function (email, password, callback) { | ||
}, | ||
initWithToken: function(_token, callback) { | ||
token = _token; | ||
loadData(callback); | ||
}, | ||
getData: function() { | ||
@@ -34,8 +43,25 @@ return data; | ||
}; | ||
client.post("/addphrase", posting, function(error, res, body) { | ||
client.post("/addphrase", posting, function (error, res, body) { | ||
data = body; | ||
callback(data); | ||
}); | ||
}, | ||
say: function(phrase, persona) { | ||
var _phrase = data.phrases.find(function(item) {return item.name == phrase}); | ||
if (!_phrase) { | ||
throw "Phrase doesn't exist. Add it by calling addResponse()"; | ||
} | ||
var _persona = data.personas.find(function(item) {return item.name == persona}); | ||
if (!_persona) { | ||
throw "Persona doesn't exist! Add it by calling addResponse()"; | ||
} | ||
var responses = data.responses.filter(function(item) { | ||
return item.phrase == phrase && item.persona == persona; | ||
}); | ||
if (responses.length < 1) { | ||
throw "Response doesn't exist! Add it by calling addResponse()"; | ||
} | ||
var ran = rand(0, responses.length - 1); | ||
return responses[ran]; | ||
} | ||
}; |
{ | ||
"name": "sayhi-ai", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
17880
61