diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 3099bba..d83aa47 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,7 +1,15 @@
+
+
+
-
+
+
+
+
+
+
@@ -10,8 +18,12 @@
+
+
+
+
@@ -21,7 +33,7 @@
-
+
@@ -33,29 +45,54 @@
1597264410641
-
+
+
+
+
+ 1597348071361
+
+
+
+ 1597348071361
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
-
+
+
-
+
\ No newline at end of file
diff --git a/app.css b/app.css
index 5927dab..53993b4 100644
--- a/app.css
+++ b/app.css
@@ -1,6 +1,8 @@
#kara {
margin: 2em auto auto auto;
width: 50em;
+ max-width: 99%;
+ max-height: 100%;
}
#kara .card {
@@ -26,5 +28,5 @@
#chat-box {
overflow-y: scroll;
- height: 100%
+ height: 25em;
}
\ No newline at end of file
diff --git a/app.js b/app.js
index 713e98d..8b99273 100644
--- a/app.js
+++ b/app.js
@@ -31,7 +31,12 @@ let kara = new Vue({
this.aiMessage(this.templates.initialGreeting);
},
sendMessage() {
+ if (this.chatbox.trim() === '') {
+ return false;
+ }
+
this.userMessage(this.chatbox);
+ this.scrollDown();
this.react(this.chatbox);
this.chatbox = '';
},
@@ -47,35 +52,44 @@ let kara = new Vue({
this.aiMessage(
this.getAnswer(message)
);
+ this.scrollDown();
}, 3000);
+ },
+ scrollDown() {
+ $('#chat-box').stop().animate({
+ scrollTop: $('#chat-box')[0].scrollHeight
+ }, 800);
+ },
+ oneOf(answers) {
+ let amountOfAnswers = answers.length;
+ console.log(answers);
+ let randomIndex = Math.floor(Math.random() * (amountOfAnswers));
+ console.log(randomIndex);
- this.scrollDown();
+ console.log(answers[randomIndex]);
+ return answers[randomIndex];
},
- getAnswer(message) {
- let isQuestion = (message.indexOf('?') > 0);
+ includesOneOf(phrases, wordsToSearch) {
+ let includes = false;
- message = message.toLowerCase();
- message = this.clearMessage(message);
- let phrases = message.split(' ');
+ wordsToSearch.forEach((searchWord) => {
+ if (phrases.includes(searchWord)) {
+ includes = true;
+ }
+ })
-
+ return includes;
+ },
+ includesAllOf(phrases, wordsToSearch) {
+ let includesAllPhrases = true;
- if (isQuestion) {
- return 'This is a question!';
- } else {
- if (message.indexOf('name') > 0) {
- return 'Nice to meet you!';
- } else {
- return "I don't know what to say.";
- }
- }
+ wordsToSearch.forEach((searchWord) => {
+ if (!phrases.includes(searchWord)) {
+ includesAllPhrases = false;
+ }
+ })
- return answer;
- },
- scrollDown() {
- $('#chat-box').stop().animate({
- scrollTop: $('#chat-box')[0].scrollHeight
- }, 800);
+ return includesAllPhrases;
},
clearMessage(message) {
return message.replace('?', '')
@@ -101,6 +115,35 @@ let kara = new Vue({
.replace('@', '')
.replace('~', '')
.replace('…', '');
+ },
+ getAnswer(message) {
+ let isQuestion = (message.indexOf('?') > 0);
+
+ message = message.toLowerCase();
+ message = this.clearMessage(message);
+ let phrases = message.split(' ');
+
+ if (
+ this.includesOneOf(phrases,['hi', 'hallo', 'servas', 'servas', 'servus', 'hello'])
+ ) {
+ return this.oneOf([
+ 'Hey! :)',
+ 'Hello!',
+ 'How are you?'
+ ]);
+ }
+
+ if (
+ this.includesAllOf(phrases,['how', 'are', 'you'])
+ ) {
+ return this.oneOf([
+ '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?'
+ ]);
+ }
+
+ return 'I don\'t know what to say..';
}
}
})
\ No newline at end of file
diff --git a/index.html b/index.html
index c650542..f3d171d 100644
--- a/index.html
+++ b/index.html
@@ -6,6 +6,7 @@
+
@@ -49,9 +50,7 @@