|
|
@ -31,30 +31,7 @@ let kara = new Vue({ |
|
|
|
location: '' |
|
|
|
location: '' |
|
|
|
}, |
|
|
|
}, |
|
|
|
notes: [], |
|
|
|
notes: [], |
|
|
|
reactions: [ |
|
|
|
reactions: [] |
|
|
|
{ |
|
|
|
|
|
|
|
includeAll: false, |
|
|
|
|
|
|
|
keywords: [ |
|
|
|
|
|
|
|
'hi', 'hallo', 'servas', 'servus', 'hello' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
responses: [ |
|
|
|
|
|
|
|
'Hey! :)', |
|
|
|
|
|
|
|
'Hello!', |
|
|
|
|
|
|
|
'How are you?' |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
includeAll: true, |
|
|
|
|
|
|
|
keywords: [ |
|
|
|
|
|
|
|
'how', 'are', 'you' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
responses: [ |
|
|
|
|
|
|
|
'I\'m good! Thanks for asking! :) How about you?', |
|
|
|
|
|
|
|
'A bit tired from trying to do that think called "thinking".. i\'ll figure it out one day.', |
|
|
|
|
|
|
|
'Wooo! I\'m hyped for party! You\'re in?' |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
mounted() { |
|
|
|
this.getSavedData(); |
|
|
|
this.getSavedData(); |
|
|
@ -207,25 +184,25 @@ let kara = new Vue({ |
|
|
|
getReaction(message) { |
|
|
|
getReaction(message) { |
|
|
|
message = this.cleanupMessage(message); |
|
|
|
message = this.cleanupMessage(message); |
|
|
|
|
|
|
|
|
|
|
|
let phrases = message.split(' '); |
|
|
|
let keywords = message.split(' '); |
|
|
|
let answer = undefined; |
|
|
|
let answer = undefined; |
|
|
|
|
|
|
|
|
|
|
|
if (this.lastMessageData.joke && this.includesOneOf(phrases, ['another', 'more'])) { |
|
|
|
if (this.lastMessageData.joke && this.includesOneOf(keywords, ['another', 'more'])) { |
|
|
|
this.tellJoke(this.lastMessageData.category); |
|
|
|
this.tellJoke(this.lastMessageData.category); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.lastMessageData = {}; |
|
|
|
this.lastMessageData = {}; |
|
|
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['change', 'my', 'name'])) { |
|
|
|
if (this.includesAllOf(keywords, ['change', 'my', 'name'])) { |
|
|
|
this.askedForName = true; |
|
|
|
this.askedForName = true; |
|
|
|
return "Please tell me how i should call you."; |
|
|
|
return "Please tell me how i should call you."; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['new', 'note']) || |
|
|
|
if (this.includesAllOf(keywords, ['new', 'note']) || |
|
|
|
this.includesAllOf(phrases, ['new', 'task']) || |
|
|
|
this.includesAllOf(keywords, ['new', 'task']) || |
|
|
|
this.includesAllOf(phrases, ['take', 'note']) || |
|
|
|
this.includesAllOf(keywords, ['take', 'note']) || |
|
|
|
this.includesAllOf(phrases, ['save', 'to', 'clipboard']) |
|
|
|
this.includesAllOf(keywords, ['save', 'to', 'clipboard']) |
|
|
|
) { |
|
|
|
) { |
|
|
|
this.takeNote = true; |
|
|
|
this.takeNote = true; |
|
|
|
return this.oneOf([ |
|
|
|
return this.oneOf([ |
|
|
@ -235,56 +212,56 @@ let kara = new Vue({ |
|
|
|
]); |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['clear', 'chat'])) { |
|
|
|
if (this.includesAllOf(keywords, ['clear', 'chat'])) { |
|
|
|
this.clearChat(); |
|
|
|
this.clearChat(); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['weather']) && |
|
|
|
if (this.includesAllOf(keywords, ['weather']) && |
|
|
|
this.includesOneOf(phrases, ['how', 'whats']) |
|
|
|
this.includesOneOf(keywords, ['how', 'whats']) |
|
|
|
) { |
|
|
|
) { |
|
|
|
this.checkWeather(); |
|
|
|
this.checkWeather(); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['knock', 'joke'])) { |
|
|
|
if (this.includesAllOf(keywords, ['knock', 'joke'])) { |
|
|
|
this.tellJoke('knock-knock'); |
|
|
|
this.tellJoke('knock-knock'); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['joke']) && this.includesOneOf(phrases, ['coding', 'programming', 'code', 'it'])) { |
|
|
|
if (this.includesAllOf(keywords, ['joke']) && this.includesOneOf(keywords, ['coding', 'programming', 'code', 'it'])) { |
|
|
|
this.tellJoke('programming'); |
|
|
|
this.tellJoke('programming'); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['tell', 'joke']) || |
|
|
|
if (this.includesAllOf(keywords, ['tell', 'joke']) || |
|
|
|
this.includesAllOf(phrases, ['something', 'funny']) || |
|
|
|
this.includesAllOf(keywords, ['something', 'funny']) || |
|
|
|
this.includesAllOf(phrases, ['cheer', 'me', 'up']) |
|
|
|
this.includesAllOf(keywords, ['cheer', 'me', 'up']) |
|
|
|
) { |
|
|
|
) { |
|
|
|
this.tellJoke('general'); |
|
|
|
this.tellJoke('general'); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['whats', 'the', 'time']) || this.includesAllOf(phrases, ['how', 'late'])) { |
|
|
|
if (this.includesAllOf(keywords, ['whats', 'the', 'time']) || this.includesAllOf(keywords, ['how', 'late'])) { |
|
|
|
return "It's " + moment().format('LT'); |
|
|
|
return "It's " + moment().format('LT'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['what', 'day', 'it'])) { |
|
|
|
if (this.includesAllOf(keywords, ['what', 'day', 'it'])) { |
|
|
|
return "It's " + moment().format('dddd') + "."; |
|
|
|
return "It's " + moment().format('dddd') + "."; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['what', 'date', 'it']) || this.includesAllOf(phrases, ['whats', 'the', 'date'])) { |
|
|
|
if (this.includesAllOf(keywords, ['what', 'date', 'it']) || this.includesAllOf(keywords, ['whats', 'the', 'date'])) { |
|
|
|
return "It's " + moment().format('dddd') + ", " + moment().format('MMMM Do YYYY') + "."; |
|
|
|
return "It's " + moment().format('dddd') + ", " + moment().format('MMMM Do YYYY') + "."; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.reactions.forEach((answerOption) => { |
|
|
|
this.reactions.forEach((reactionOption) => { |
|
|
|
if (answerOption.includeAll === true) { |
|
|
|
if (reactionOption.includeAll === true) { |
|
|
|
if (this.includesAllOf(phrases, answerOption.keywords)) { |
|
|
|
if (this.includesAllOf(keywords, reactionOption.keywords)) { |
|
|
|
answer = this.oneOf(answerOption.responses); |
|
|
|
answer = this.oneOf(reactionOption.responses); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (this.includesOneOf(phrases, answerOption.keywords)) { |
|
|
|
if (this.includesOneOf(keywords, reactionOption.keywords)) { |
|
|
|
answer = this.oneOf(answerOption.responses); |
|
|
|
answer = this.oneOf(reactionOption.responses); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -389,7 +366,6 @@ let kara = new Vue({ |
|
|
|
|
|
|
|
|
|
|
|
axios.get(url) |
|
|
|
axios.get(url) |
|
|
|
.then(function (response) { |
|
|
|
.then(function (response) { |
|
|
|
console.log(response); |
|
|
|
|
|
|
|
let joke = response.data[0]; |
|
|
|
let joke = response.data[0]; |
|
|
|
|
|
|
|
|
|
|
|
vue.botMessage(joke.setup); |
|
|
|
vue.botMessage(joke.setup); |
|
|
@ -463,9 +439,6 @@ let kara = new Vue({ |
|
|
|
let savedMessages = JSON.parse(localStorage.getItem('messages')); |
|
|
|
let savedMessages = JSON.parse(localStorage.getItem('messages')); |
|
|
|
this.messages = savedMessages ? savedMessages : []; |
|
|
|
this.messages = savedMessages ? savedMessages : []; |
|
|
|
|
|
|
|
|
|
|
|
let savedAnswers = JSON.parse(localStorage.getItem('answers')); |
|
|
|
|
|
|
|
this.reactions = savedAnswers !== [] ? savedAnswers : this.reactions; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedNotes = JSON.parse(localStorage.getItem('notes')); |
|
|
|
let savedNotes = JSON.parse(localStorage.getItem('notes')); |
|
|
|
this.notes = savedNotes ? savedNotes : []; |
|
|
|
this.notes = savedNotes ? savedNotes : []; |
|
|
|
|
|
|
|
|
|
|
@ -549,27 +522,27 @@ let kara = new Vue({ |
|
|
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
this.updateStorage(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
includesOneOf(phrases, wordsToSearch) { |
|
|
|
includesOneOf(keywords, wordsToSearch) { |
|
|
|
let includes = false; |
|
|
|
let includes = false; |
|
|
|
|
|
|
|
|
|
|
|
wordsToSearch.forEach((searchWord) => { |
|
|
|
wordsToSearch.forEach((searchWord) => { |
|
|
|
if (phrases.includes(searchWord)) { |
|
|
|
if (keywords.includes(searchWord)) { |
|
|
|
includes = true; |
|
|
|
includes = true; |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return includes; |
|
|
|
return includes; |
|
|
|
}, |
|
|
|
}, |
|
|
|
includesAllOf(phrases, wordsToSearch) { |
|
|
|
includesAllOf(keywords, wordsToSearch) { |
|
|
|
let includesAllPhrases = true; |
|
|
|
let includesAllkeywords = true; |
|
|
|
|
|
|
|
|
|
|
|
wordsToSearch.forEach((searchWord) => { |
|
|
|
wordsToSearch.forEach((searchWord) => { |
|
|
|
if (!phrases.includes(searchWord)) { |
|
|
|
if (!keywords.includes(searchWord)) { |
|
|
|
includesAllPhrases = false; |
|
|
|
includesAllkeywords = false; |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return includesAllPhrases; |
|
|
|
return includesAllkeywords; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// Ajax calls for saving/receiving reactions & themes
|
|
|
|
// Ajax calls for saving/receiving reactions & themes
|
|
|
@ -588,7 +561,9 @@ let kara = new Vue({ |
|
|
|
let vue = this; |
|
|
|
let vue = this; |
|
|
|
|
|
|
|
|
|
|
|
axios.get('/reactions/get').then((response) => { |
|
|
|
axios.get('/reactions/get').then((response) => { |
|
|
|
this.reactions = response.data; |
|
|
|
response.data.forEach((reaction) => { |
|
|
|
|
|
|
|
vue.reactions.push(JSON.parse(reaction.reaction)); |
|
|
|
|
|
|
|
}); |
|
|
|
}).catch((error) => { |
|
|
|
}).catch((error) => { |
|
|
|
console.log(error); |
|
|
|
console.log(error); |
|
|
|
}); |
|
|
|
}); |
|
|
|