|
|
|
@ -6,6 +6,7 @@ let kara = new Vue({
@@ -6,6 +6,7 @@ let kara = new Vue({
|
|
|
|
|
chatbox: null, |
|
|
|
|
isTyping: false, |
|
|
|
|
askedForName: false, |
|
|
|
|
takeNote: false, |
|
|
|
|
username: '', |
|
|
|
|
themes: null, |
|
|
|
|
activeTheme: 'slate', |
|
|
|
@ -20,6 +21,7 @@ let kara = new Vue({
@@ -20,6 +21,7 @@ let kara = new Vue({
|
|
|
|
|
name: null, |
|
|
|
|
username: null |
|
|
|
|
}, |
|
|
|
|
notes: [], |
|
|
|
|
answers: [ |
|
|
|
|
{ |
|
|
|
|
includeAll: false, |
|
|
|
@ -121,8 +123,16 @@ let kara = new Vue({
@@ -121,8 +123,16 @@ let kara = new Vue({
|
|
|
|
|
this.isTyping = true; |
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
if (this.askedForName === true) { |
|
|
|
|
// Check commands
|
|
|
|
|
if (this.checkForCommands(message, 'note')) { |
|
|
|
|
let noteToSave = this.checkForCommands(message, 'note'); |
|
|
|
|
this.saveNote(noteToSave); |
|
|
|
|
} else if (this.checkForCommands(message, 'clear')) { |
|
|
|
|
this.clearChat(); |
|
|
|
|
} else if (this.askedForName === true) { |
|
|
|
|
this.setName(message) |
|
|
|
|
} else if (this.takeNote === true) { |
|
|
|
|
this.saveNote(message) |
|
|
|
|
} else { |
|
|
|
|
let answer = this.getAnswer(message); |
|
|
|
|
if (answer) { |
|
|
|
@ -134,7 +144,7 @@ let kara = new Vue({
@@ -134,7 +144,7 @@ let kara = new Vue({
|
|
|
|
|
|
|
|
|
|
this.isTyping = false; |
|
|
|
|
this.scrollDown(); |
|
|
|
|
}, 3000); |
|
|
|
|
}, 2000); |
|
|
|
|
}, |
|
|
|
|
scrollDown() { |
|
|
|
|
$('#chat-box').stop().animate({ |
|
|
|
@ -144,9 +154,7 @@ let kara = new Vue({
@@ -144,9 +154,7 @@ let kara = new Vue({
|
|
|
|
|
oneOf(answers) { |
|
|
|
|
let amountOfAnswers = answers.length; |
|
|
|
|
let randomIndex = Math.floor(Math.random() * (amountOfAnswers)); |
|
|
|
|
console.log(randomIndex); |
|
|
|
|
|
|
|
|
|
console.log(answers[randomIndex]); |
|
|
|
|
return this.convertWildcards(answers[randomIndex]); |
|
|
|
|
}, |
|
|
|
|
convertWildcards(message) { |
|
|
|
@ -177,6 +185,28 @@ let kara = new Vue({
@@ -177,6 +185,28 @@ let kara = new Vue({
|
|
|
|
|
|
|
|
|
|
return includesAllPhrases; |
|
|
|
|
}, |
|
|
|
|
checkForCommands(message, commands) { |
|
|
|
|
if (!Array.isArray(commands)) { |
|
|
|
|
commands = [commands]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let commandFound = false; |
|
|
|
|
let parameter = false; |
|
|
|
|
|
|
|
|
|
commands.forEach((command) => { |
|
|
|
|
if (commandFound) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
let commandString = '/' + command; |
|
|
|
|
|
|
|
|
|
if (message.search(commandString) === 0) { |
|
|
|
|
parameter = message.replace(commandString, '').trim(); |
|
|
|
|
commandFound = true; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return parameter ? parameter : commandFound; |
|
|
|
|
}, |
|
|
|
|
cleanupMessage(message) { |
|
|
|
|
message = message.toLowerCase(); |
|
|
|
|
return message.replace('?', '') |
|
|
|
@ -205,6 +235,7 @@ let kara = new Vue({
@@ -205,6 +235,7 @@ let kara = new Vue({
|
|
|
|
|
}, |
|
|
|
|
getAnswer(message) { |
|
|
|
|
message = this.cleanupMessage(message); |
|
|
|
|
|
|
|
|
|
let phrases = message.split(' '); |
|
|
|
|
let answer = undefined; |
|
|
|
|
|
|
|
|
@ -213,6 +244,19 @@ let kara = new Vue({
@@ -213,6 +244,19 @@ let kara = new Vue({
|
|
|
|
|
return "Please tell me how i should call you."; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
this.includesAllOf(phrases, ['new', 'note']) || |
|
|
|
|
this.includesAllOf(phrases, ['new', 'task']) || |
|
|
|
|
this.includesAllOf(phrases, ['save', 'to', 'clipboard']) |
|
|
|
|
) { |
|
|
|
|
this.takeNote = true; |
|
|
|
|
return this.oneOf([ |
|
|
|
|
"What do you wan't me to save for you?", |
|
|
|
|
"Tell me what you wan't to save.", |
|
|
|
|
"What is it you wan't to save?", |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.includesAllOf(phrases, ['clear', 'chat'])) { |
|
|
|
|
this.clearChat() |
|
|
|
|
return false; |
|
|
|
@ -267,7 +311,6 @@ let kara = new Vue({
@@ -267,7 +311,6 @@ let kara = new Vue({
|
|
|
|
|
let includeAll = this.addModal.includeAll; |
|
|
|
|
let keywords = this.cleanupMessage(this.addModal.keywords).split(','); |
|
|
|
|
let responses = this.addModal.responses; |
|
|
|
|
console.log(this.addModal.responses); |
|
|
|
|
|
|
|
|
|
this.answers.push({ |
|
|
|
|
includeAll: includeAll, |
|
|
|
@ -287,6 +330,7 @@ let kara = new Vue({
@@ -287,6 +330,7 @@ let kara = new Vue({
|
|
|
|
|
localStorage.setItem('activeTheme', this.activeTheme); |
|
|
|
|
localStorage.setItem('messages', JSON.stringify(this.messages)); |
|
|
|
|
localStorage.setItem('answers', JSON.stringify(this.answers)); |
|
|
|
|
localStorage.setItem('notes', JSON.stringify(this.notes)); |
|
|
|
|
}, |
|
|
|
|
getSavedData() { |
|
|
|
|
let savedName = localStorage.getItem('name'); |
|
|
|
@ -305,6 +349,9 @@ let kara = new Vue({
@@ -305,6 +349,9 @@ let kara = new Vue({
|
|
|
|
|
let savedAnswers = JSON.parse(localStorage.getItem('answers')); |
|
|
|
|
this.answers = savedAnswers ? savedAnswers : this.answers; |
|
|
|
|
|
|
|
|
|
let savedNotes = JSON.parse(localStorage.getItem('notes')); |
|
|
|
|
this.notes = savedNotes ? savedNotes : this.notes; |
|
|
|
|
|
|
|
|
|
this.scrollDown(); |
|
|
|
|
}, |
|
|
|
|
askForName() { |
|
|
|
@ -333,6 +380,24 @@ let kara = new Vue({
@@ -333,6 +380,24 @@ let kara = new Vue({
|
|
|
|
|
]) |
|
|
|
|
) |
|
|
|
|
}, |
|
|
|
|
saveNote(message) { |
|
|
|
|
this.takeNote = false; |
|
|
|
|
|
|
|
|
|
this.notes.push({ |
|
|
|
|
time: moment(), |
|
|
|
|
body: message, |
|
|
|
|
checked: false |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
|
|
|
|
|
|
this.botMessage( |
|
|
|
|
this.oneOf([ |
|
|
|
|
"Saved! :)", |
|
|
|
|
"You can read and check your notes in the clipboard-section. :)" |
|
|
|
|
]) |
|
|
|
|
) |
|
|
|
|
}, |
|
|
|
|
saveSettings() { |
|
|
|
|
this.name = this.settingsModal.name; |
|
|
|
|
this.username = this.settingsModal.username; |
|
|
|
@ -344,6 +409,7 @@ let kara = new Vue({
@@ -344,6 +409,7 @@ let kara = new Vue({
|
|
|
|
|
clearChat() { |
|
|
|
|
this.messages = []; |
|
|
|
|
this.botMessage('Chat cleared.'); |
|
|
|
|
this.updateStorage(); |
|
|
|
|
}, |
|
|
|
|
clearStorage() { |
|
|
|
|
localStorage.clear(); |
|
|
|
@ -354,7 +420,6 @@ let kara = new Vue({
@@ -354,7 +420,6 @@ let kara = new Vue({
|
|
|
|
|
|
|
|
|
|
axios.get('https://bootswatch.com/api/4.json') |
|
|
|
|
.then(function (response) { |
|
|
|
|
console.log(response.data.themes); |
|
|
|
|
vue.themes = response.data.themes; |
|
|
|
|
}) |
|
|
|
|
.catch(function (error) { |
|
|
|
|