Add Captains counter intent for Alexa

This commit is contained in:
Alex Ellis
2016-12-30 20:06:02 +00:00
parent d181fed5fd
commit 3775506184
9 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,32 @@
"use strict"
module.exports = class Parser {
constructor(cheerio) {
this.modules = {"cheerio": cheerio };
}
sanitize(handle) {
let text = handle.toLowerCase();
if(text[0]== "@") {
text = text.substring(1);
}
if(handle.indexOf("twitter.com") > -1) {
text = text.substring(text.lastIndexOf("\/")+1)
}
return {text: text, valid: text.indexOf("http") == -1};
}
parse(text) {
let $ = this.modules.cheerio.load(text);
let people = $("#captians .twitter_link a");
let handles = [];
people.each((i, person) => {
let handle = person.attribs.href;
handles.push(this.sanitize(handle));
});
return handles;
}
};