|
|
@ -88,24 +88,7 @@ let kara = new Vue({ |
|
|
|
this.scrollDown(); |
|
|
|
this.scrollDown(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
addMessage(body, bot, me = false) { |
|
|
|
// Initial
|
|
|
|
this.messages.push({ |
|
|
|
|
|
|
|
body: body, |
|
|
|
|
|
|
|
bot: bot, |
|
|
|
|
|
|
|
command: body.search('/') === 0, |
|
|
|
|
|
|
|
me: me, |
|
|
|
|
|
|
|
time: Date.now() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
botMessage(body) { |
|
|
|
|
|
|
|
this.addMessage(body, true); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
userMessage(body) { |
|
|
|
|
|
|
|
this.addMessage(body, false); |
|
|
|
|
|
|
|
this.lastMessage = body; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
initialGreeting() { |
|
|
|
initialGreeting() { |
|
|
|
this.botMessage( |
|
|
|
this.botMessage( |
|
|
|
this.oneOf( |
|
|
|
this.oneOf( |
|
|
@ -129,6 +112,54 @@ let kara = new Vue({ |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Name
|
|
|
|
|
|
|
|
askForName() { |
|
|
|
|
|
|
|
this.botMessage( |
|
|
|
|
|
|
|
this.oneOf([ |
|
|
|
|
|
|
|
'May i ask for your name?', |
|
|
|
|
|
|
|
'Whats your name? :)', |
|
|
|
|
|
|
|
'How can i call you?', |
|
|
|
|
|
|
|
'How did your developers call you? :)' |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.askedForName = true; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
setName(message) { |
|
|
|
|
|
|
|
this.username = message.trim(); |
|
|
|
|
|
|
|
this.settingsModal.username = this.username; |
|
|
|
|
|
|
|
this.askedForName = false; |
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.botMessage( |
|
|
|
|
|
|
|
this.oneOf([ |
|
|
|
|
|
|
|
"That's a beautiful name!", |
|
|
|
|
|
|
|
"Okay, i'll call you " + this.username + " from now on :)", |
|
|
|
|
|
|
|
"Nice to meet you, " + this.username + ". :D" |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Messages / Chat
|
|
|
|
|
|
|
|
addMessage(body, bot, me = false) { |
|
|
|
|
|
|
|
this.messages.push({ |
|
|
|
|
|
|
|
body: body, |
|
|
|
|
|
|
|
bot: bot, |
|
|
|
|
|
|
|
command: body.search('/') === 0, |
|
|
|
|
|
|
|
me: me, |
|
|
|
|
|
|
|
time: Date.now() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
botMessage(body) { |
|
|
|
|
|
|
|
this.addMessage(body, true); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
userMessage(body) { |
|
|
|
|
|
|
|
this.addMessage(body, false); |
|
|
|
|
|
|
|
this.lastMessage = body; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
|
|
|
|
}, |
|
|
|
sendMessage() { |
|
|
|
sendMessage() { |
|
|
|
if (this.chatbox.trim() === '') { |
|
|
|
if (this.chatbox.trim() === '') { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -141,6 +172,10 @@ let kara = new Vue({ |
|
|
|
this.react(this.chatbox); |
|
|
|
this.react(this.chatbox); |
|
|
|
this.chatbox = ''; |
|
|
|
this.chatbox = ''; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
meMessage(message) { |
|
|
|
|
|
|
|
this.addMessage(this.username + ' ' + message, false, true); |
|
|
|
|
|
|
|
this.react(message, true); |
|
|
|
|
|
|
|
}, |
|
|
|
react(message, recursive = false) { |
|
|
|
react(message, recursive = false) { |
|
|
|
this.isTyping = true; |
|
|
|
this.isTyping = true; |
|
|
|
|
|
|
|
|
|
|
@ -159,7 +194,7 @@ let kara = new Vue({ |
|
|
|
} else if (this.takeNote === true) { |
|
|
|
} else if (this.takeNote === true) { |
|
|
|
this.saveNote(message); |
|
|
|
this.saveNote(message); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
let answer = this.getAnswer(message); |
|
|
|
let answer = this.getReaction(message); |
|
|
|
if (answer) { |
|
|
|
if (answer) { |
|
|
|
this.botMessage(answer); |
|
|
|
this.botMessage(answer); |
|
|
|
} |
|
|
|
} |
|
|
@ -172,116 +207,7 @@ let kara = new Vue({ |
|
|
|
}, 1800); |
|
|
|
}, 1800); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
processCommands(message) { |
|
|
|
getReaction(message) { |
|
|
|
if (this.checkForCommands(message, 'note')) { |
|
|
|
|
|
|
|
let noteToSave = this.checkForCommands(message, 'note'); |
|
|
|
|
|
|
|
this.saveNote(noteToSave); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.checkForCommands(message, 'clear')) { |
|
|
|
|
|
|
|
this.clearChat(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.checkForCommands(message, 'weather')) { |
|
|
|
|
|
|
|
this.checkWeather() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.checkForCommands(message, 'joke')) { |
|
|
|
|
|
|
|
this.tellJoke(this.checkForCommands(message, 'joke')) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.checkForCommands(message, 'me')) { |
|
|
|
|
|
|
|
this.meMessage(this.checkForCommands(message, 'me')) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
scrollDown() { |
|
|
|
|
|
|
|
$('#chat-box').stop().animate({ |
|
|
|
|
|
|
|
scrollTop: ($('#chat-box')[0].scrollHeight * 10) |
|
|
|
|
|
|
|
}, 800); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
oneOf(answers) { |
|
|
|
|
|
|
|
let amountOfAnswers = answers.length; |
|
|
|
|
|
|
|
let randomIndex = Math.floor(Math.random() * (amountOfAnswers)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.convertWildcards(answers[randomIndex]); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
convertWildcards(message) { |
|
|
|
|
|
|
|
message = message.replace('$name$', this.username); |
|
|
|
|
|
|
|
message = message.replace('$botname$', this.name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
includesOneOf(phrases, wordsToSearch) { |
|
|
|
|
|
|
|
let includes = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wordsToSearch.forEach((searchWord) => { |
|
|
|
|
|
|
|
if (phrases.includes(searchWord)) { |
|
|
|
|
|
|
|
includes = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return includes; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
includesAllOf(phrases, wordsToSearch) { |
|
|
|
|
|
|
|
let includesAllPhrases = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wordsToSearch.forEach((searchWord) => { |
|
|
|
|
|
|
|
if (!phrases.includes(searchWord)) { |
|
|
|
|
|
|
|
includesAllPhrases = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return includesAllPhrases; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
cleanupMessage(message) { |
|
|
|
|
|
|
|
message = message.toLowerCase(); |
|
|
|
|
|
|
|
return message.replace('?', '') |
|
|
|
|
|
|
|
.replace('!', '') |
|
|
|
|
|
|
|
.replace('.', '') |
|
|
|
|
|
|
|
.replace(',', '') |
|
|
|
|
|
|
|
.replace('-', '') |
|
|
|
|
|
|
|
.replace('_', '') |
|
|
|
|
|
|
|
.replace('#', '') |
|
|
|
|
|
|
|
.replace('\'', '') |
|
|
|
|
|
|
|
.replace('"', '') |
|
|
|
|
|
|
|
.replace('+', '') |
|
|
|
|
|
|
|
.replace('*', '') |
|
|
|
|
|
|
|
.replace('§', '') |
|
|
|
|
|
|
|
.replace('$', '') |
|
|
|
|
|
|
|
.replace('%', '') |
|
|
|
|
|
|
|
.replace('&', '') |
|
|
|
|
|
|
|
.replace('/', '') |
|
|
|
|
|
|
|
.replace('(', '') |
|
|
|
|
|
|
|
.replace(')', '') |
|
|
|
|
|
|
|
.replace('=', '') |
|
|
|
|
|
|
|
.replace('\\', '') |
|
|
|
|
|
|
|
.replace('@', '') |
|
|
|
|
|
|
|
.replace('~', '') |
|
|
|
|
|
|
|
.replace('…', ''); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getAnswer(message) { |
|
|
|
|
|
|
|
message = this.cleanupMessage(message); |
|
|
|
message = this.cleanupMessage(message); |
|
|
|
|
|
|
|
|
|
|
|
let phrases = message.split(' '); |
|
|
|
let phrases = message.split(' '); |
|
|
@ -372,9 +298,6 @@ let kara = new Vue({ |
|
|
|
|
|
|
|
|
|
|
|
return 'I don\'t know what to say..'; |
|
|
|
return 'I don\'t know what to say..'; |
|
|
|
}, |
|
|
|
}, |
|
|
|
addResponseToInput() { |
|
|
|
|
|
|
|
this.addModal.responses.push(''); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
addNewResponseContainer() { |
|
|
|
addNewResponseContainer() { |
|
|
|
let includeAll = this.addModal.includeAll; |
|
|
|
let includeAll = this.addModal.includeAll; |
|
|
|
let keywords = this.cleanupMessage(this.addModal.keywords).split(','); |
|
|
|
let keywords = this.cleanupMessage(this.addModal.keywords).split(','); |
|
|
@ -392,120 +315,65 @@ let kara = new Vue({ |
|
|
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
this.updateStorage(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
updateStorage() { |
|
|
|
|
|
|
|
localStorage.setItem('name', this.name); |
|
|
|
|
|
|
|
localStorage.setItem('username', this.username); |
|
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
|
localStorage.setItem('lastMessage', JSON.stringify(this.lastMessage)); |
|
|
|
|
|
|
|
localStorage.setItem('location', JSON.stringify(this.location)); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getSavedData() { |
|
|
|
|
|
|
|
let savedName = localStorage.getItem('name'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.name = savedName ? savedName : this.name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedUsername = localStorage.getItem('username'); |
|
|
|
|
|
|
|
this.username = savedUsername ? savedUsername : null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedActiveTheme = localStorage.getItem('activeTheme'); |
|
|
|
// Forms
|
|
|
|
this.activeTheme = savedActiveTheme ? savedActiveTheme : 'slate'; |
|
|
|
saveSettings() { |
|
|
|
|
|
|
|
this.name = this.settingsModal.name; |
|
|
|
let savedMessages = JSON.parse(localStorage.getItem('messages')); |
|
|
|
this.username = this.settingsModal.username; |
|
|
|
this.messages = savedMessages ? savedMessages : []; |
|
|
|
this.location = this.settingsModal.location; |
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
let savedAnswers = JSON.parse(localStorage.getItem('answers')); |
|
|
|
|
|
|
|
this.answers = savedAnswers !== [] ? savedAnswers : this.answers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedNotes = JSON.parse(localStorage.getItem('notes')); |
|
|
|
|
|
|
|
this.notes = savedNotes ? savedNotes : []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedLastMessage = JSON.parse(localStorage.getItem('lastMessage')); |
|
|
|
|
|
|
|
this.lastMessage = savedLastMessage ? savedLastMessage : null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedLocation = JSON.parse(localStorage.getItem('location')); |
|
|
|
|
|
|
|
this.location = savedLocation ? savedLocation : null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this.botMessage('Settings saved! :)');
|
|
|
|
this.scrollDown(); |
|
|
|
this.scrollDown(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
askForName() { |
|
|
|
addResponseToInput() { |
|
|
|
this.botMessage( |
|
|
|
this.addModal.responses.push(''); |
|
|
|
this.oneOf([ |
|
|
|
|
|
|
|
'May i ask for your name?', |
|
|
|
|
|
|
|
'Whats your name? :)', |
|
|
|
|
|
|
|
'How can i call you?', |
|
|
|
|
|
|
|
'How did your developers call you? :)' |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.askedForName = true; |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
setName(message) { |
|
|
|
|
|
|
|
this.username = message.trim(); |
|
|
|
|
|
|
|
this.settingsModal.username = this.username; |
|
|
|
|
|
|
|
this.askedForName = false; |
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.botMessage( |
|
|
|
// Commands
|
|
|
|
this.oneOf([ |
|
|
|
processCommands(message) { |
|
|
|
"That's a beautiful name!", |
|
|
|
if (this.checkForCommands(message, 'note')) { |
|
|
|
"Okay, i'll call you " + this.username + " from now on :)", |
|
|
|
let noteToSave = this.checkForCommands(message, 'note'); |
|
|
|
"Nice to meet you, " + this.username + ". :D" |
|
|
|
this.saveNote(noteToSave); |
|
|
|
]) |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
saveNote(message) { |
|
|
|
|
|
|
|
this.takeNote = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.notes.push({ |
|
|
|
if (this.checkForCommands(message, 'clear')) { |
|
|
|
time: moment(), |
|
|
|
this.clearChat(); |
|
|
|
body: message, |
|
|
|
} |
|
|
|
checked: false |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
if (this.checkForCommands(message, 'weather')) { |
|
|
|
|
|
|
|
this.checkWeather() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.botMessage( |
|
|
|
if (this.checkForCommands(message, 'joke')) { |
|
|
|
this.oneOf([ |
|
|
|
this.tellJoke(this.checkForCommands(message, 'joke')) |
|
|
|
"Saved! :)", |
|
|
|
} |
|
|
|
"You can read and check your notes in the clipboard-section. :)" |
|
|
|
|
|
|
|
]) |
|
|
|
if (this.checkForCommands(message, 'me')) { |
|
|
|
) |
|
|
|
this.meMessage(this.checkForCommands(message, 'me')) |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
clearNotes() { |
|
|
|
checkForCommands(message, commands) { |
|
|
|
this.notes = []; |
|
|
|
if (!Array.isArray(commands)) { |
|
|
|
|
|
|
|
commands = [commands]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.botMessage( |
|
|
|
let commandFound = false; |
|
|
|
this.oneOf([ |
|
|
|
let parameter = false; |
|
|
|
"Notes cleared. 🚮" |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
commands.forEach((command) => { |
|
|
|
}, |
|
|
|
if (commandFound) { |
|
|
|
saveSettings() { |
|
|
|
return; |
|
|
|
this.name = this.settingsModal.name; |
|
|
|
} |
|
|
|
this.username = this.settingsModal.username; |
|
|
|
let commandString = '/' + command; |
|
|
|
this.location = this.settingsModal.location; |
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this.botMessage('Settings saved! :)');
|
|
|
|
if (message.search(commandString) === 0) { |
|
|
|
this.scrollDown(); |
|
|
|
parameter = message.replace(commandString, '').trim(); |
|
|
|
}, |
|
|
|
commandFound = true; |
|
|
|
clearChat() { |
|
|
|
} |
|
|
|
this.messages = []; |
|
|
|
}); |
|
|
|
this.botMessage(this.oneOf([ |
|
|
|
|
|
|
|
'Chat cleared.', |
|
|
|
|
|
|
|
'Evidence destroyed.', |
|
|
|
|
|
|
|
'Mind cleared.', |
|
|
|
|
|
|
|
'Uhm.. i think forgot everything we ever talked about.. oops.', |
|
|
|
|
|
|
|
'A fresh start!', |
|
|
|
|
|
|
|
"You've got something to hide? Nevermind, gotcha fam. Chat is cleared now. 🐱👤" |
|
|
|
|
|
|
|
])); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
return parameter ? parameter : commandFound; |
|
|
|
}, |
|
|
|
}, |
|
|
|
checkWeather() { |
|
|
|
checkWeather() { |
|
|
|
let vue = this; |
|
|
|
let vue = this; |
|
|
@ -571,14 +439,163 @@ let kara = new Vue({ |
|
|
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
this.updateStorage(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
meMessage(message) { |
|
|
|
|
|
|
|
this.addMessage(this.username + ' ' + message, false, true); |
|
|
|
// Notes
|
|
|
|
this.react(message, true); |
|
|
|
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. :)" |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
clearNotes() { |
|
|
|
|
|
|
|
this.notes = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.botMessage( |
|
|
|
|
|
|
|
this.oneOf([ |
|
|
|
|
|
|
|
"Notes cleared. 🚮" |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LocalStorage
|
|
|
|
|
|
|
|
getSavedData() { |
|
|
|
|
|
|
|
let savedName = localStorage.getItem('name'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.name = savedName ? savedName : this.name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedUsername = localStorage.getItem('username'); |
|
|
|
|
|
|
|
this.username = savedUsername ? savedUsername : null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedActiveTheme = localStorage.getItem('activeTheme'); |
|
|
|
|
|
|
|
this.activeTheme = savedActiveTheme ? savedActiveTheme : 'slate'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedMessages = JSON.parse(localStorage.getItem('messages')); |
|
|
|
|
|
|
|
this.messages = savedMessages ? savedMessages : []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedAnswers = JSON.parse(localStorage.getItem('answers')); |
|
|
|
|
|
|
|
this.answers = savedAnswers !== [] ? savedAnswers : this.answers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedNotes = JSON.parse(localStorage.getItem('notes')); |
|
|
|
|
|
|
|
this.notes = savedNotes ? savedNotes : []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedLastMessage = JSON.parse(localStorage.getItem('lastMessage')); |
|
|
|
|
|
|
|
this.lastMessage = savedLastMessage ? savedLastMessage : null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let savedLocation = JSON.parse(localStorage.getItem('location')); |
|
|
|
|
|
|
|
this.location = savedLocation ? savedLocation : null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.scrollDown(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
updateStorage() { |
|
|
|
|
|
|
|
localStorage.setItem('name', this.name); |
|
|
|
|
|
|
|
localStorage.setItem('username', this.username); |
|
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
|
localStorage.setItem('lastMessage', JSON.stringify(this.lastMessage)); |
|
|
|
|
|
|
|
localStorage.setItem('location', JSON.stringify(this.location)); |
|
|
|
}, |
|
|
|
}, |
|
|
|
clearStorage() { |
|
|
|
clearStorage() { |
|
|
|
localStorage.clear(); |
|
|
|
localStorage.clear(); |
|
|
|
location.reload(); |
|
|
|
location.reload(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Utility
|
|
|
|
|
|
|
|
scrollDown() { |
|
|
|
|
|
|
|
$('#chat-box').stop().animate({ |
|
|
|
|
|
|
|
scrollTop: ($('#chat-box')[0].scrollHeight * 10) |
|
|
|
|
|
|
|
}, 800); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
oneOf(answers) { |
|
|
|
|
|
|
|
let amountOfAnswers = answers.length; |
|
|
|
|
|
|
|
let randomIndex = Math.floor(Math.random() * (amountOfAnswers)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.convertWildcards(answers[randomIndex]); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
convertWildcards(message) { |
|
|
|
|
|
|
|
message = message.replace('$name$', this.username); |
|
|
|
|
|
|
|
message = message.replace('$botname$', this.name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
cleanupMessage(message) { |
|
|
|
|
|
|
|
message = message.toLowerCase(); |
|
|
|
|
|
|
|
return message.replace('?', '') |
|
|
|
|
|
|
|
.replace('!', '') |
|
|
|
|
|
|
|
.replace('.', '') |
|
|
|
|
|
|
|
.replace(',', '') |
|
|
|
|
|
|
|
.replace('-', '') |
|
|
|
|
|
|
|
.replace('_', '') |
|
|
|
|
|
|
|
.replace('#', '') |
|
|
|
|
|
|
|
.replace('\'', '') |
|
|
|
|
|
|
|
.replace('"', '') |
|
|
|
|
|
|
|
.replace('+', '') |
|
|
|
|
|
|
|
.replace('*', '') |
|
|
|
|
|
|
|
.replace('§', '') |
|
|
|
|
|
|
|
.replace('$', '') |
|
|
|
|
|
|
|
.replace('%', '') |
|
|
|
|
|
|
|
.replace('&', '') |
|
|
|
|
|
|
|
.replace('/', '') |
|
|
|
|
|
|
|
.replace('(', '') |
|
|
|
|
|
|
|
.replace(')', '') |
|
|
|
|
|
|
|
.replace('=', '') |
|
|
|
|
|
|
|
.replace('\\', '') |
|
|
|
|
|
|
|
.replace('@', '') |
|
|
|
|
|
|
|
.replace('~', '') |
|
|
|
|
|
|
|
.replace('…', ''); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
clearChat() { |
|
|
|
|
|
|
|
this.messages = []; |
|
|
|
|
|
|
|
this.botMessage(this.oneOf([ |
|
|
|
|
|
|
|
'Chat cleared.', |
|
|
|
|
|
|
|
'Evidence destroyed.', |
|
|
|
|
|
|
|
'Mind cleared.', |
|
|
|
|
|
|
|
'Uhm.. i think forgot everything we ever talked about.. oops.', |
|
|
|
|
|
|
|
'A fresh start!', |
|
|
|
|
|
|
|
"You've got something to hide? Nevermind, gotcha fam. Chat is cleared now. 🐱👤" |
|
|
|
|
|
|
|
])); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.updateStorage(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
includesOneOf(phrases, wordsToSearch) { |
|
|
|
|
|
|
|
let includes = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wordsToSearch.forEach((searchWord) => { |
|
|
|
|
|
|
|
if (phrases.includes(searchWord)) { |
|
|
|
|
|
|
|
includes = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return includes; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
includesAllOf(phrases, wordsToSearch) { |
|
|
|
|
|
|
|
let includesAllPhrases = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wordsToSearch.forEach((searchWord) => { |
|
|
|
|
|
|
|
if (!phrases.includes(searchWord)) { |
|
|
|
|
|
|
|
includesAllPhrases = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return includesAllPhrases; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ajax calls for saving/receiving responses & themes
|
|
|
|
getBootswatchThemes() { |
|
|
|
getBootswatchThemes() { |
|
|
|
let vue = this; |
|
|
|
let vue = this; |
|
|
|
|
|
|
|
|
|
|
|