Browse Source

Move answers to data.

master
Nero Ignis 5 years ago
parent
commit
1dac91bdf2
  1. 23
      .idea/workspace.xml
  2. 76
      app.js

23
.idea/workspace.xml

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
</component>
<component name="ChangeListManager">
<list default="true" id="e3f098f0-e98c-435a-af04-d153c9525633" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/app.js" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -45,7 +46,7 @@ @@ -45,7 +46,7 @@
<workItem from="1597346228730" duration="1851000" />
<workItem from="1597348092890" duration="8205000" />
<workItem from="1597530844649" duration="131000" />
<workItem from="1597577497243" duration="188000" />
<workItem from="1597577497243" duration="1451000" />
</task>
<task id="LOCAL-00001" summary="Adds gitignore.">
<created>1597348071361</created>
@ -222,7 +223,14 @@ @@ -222,7 +223,14 @@
<option name="project" value="LOCAL" />
<updated>1597577559042</updated>
</task>
<option name="localTasksCounter" value="26" />
<task id="LOCAL-00026" summary="Refactor and added todo.">
<created>1597577694274</created>
<option name="number" value="00026" />
<option name="presentableId" value="LOCAL-00026" />
<option name="project" value="LOCAL" />
<updated>1597577694274</updated>
</task>
<option name="localTasksCounter" value="27" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -240,17 +248,18 @@ @@ -240,17 +248,18 @@
<MESSAGE value="Testing database access." />
<MESSAGE value="Test commit." />
<MESSAGE value="Remove DB method call." />
<option name="LAST_COMMIT_MESSAGE" value="Remove DB method call." />
<MESSAGE value="Refactor and added todo." />
<option name="LAST_COMMIT_MESSAGE" value="Refactor and added todo." />
</component>
<component name="WindowStateProjectService">
<state x="278" y="2" width="800" height="718" key="#Plugins" timestamp="1597350105557">
<screen x="0" y="0" width="1366" height="720" />
</state>
<state x="278" y="2" width="800" height="718" key="#Plugins/0.0.1366.720@0.0.1366.720" timestamp="1597350105557" />
<state x="222" y="0" width="912" height="720" key="CommitChangelistDialog2" timestamp="1597577558978">
<state x="222" y="0" width="912" height="720" key="CommitChangelistDialog2" timestamp="1597577694214">
<screen x="0" y="0" width="1366" height="720" />
</state>
<state x="222" y="0" width="912" height="720" key="CommitChangelistDialog2/0.0.1366.720@0.0.1366.720" timestamp="1597577558978" />
<state x="222" y="0" width="912" height="720" key="CommitChangelistDialog2/0.0.1366.720@0.0.1366.720" timestamp="1597577694214" />
<state x="466" y="118" width="424" height="490" key="FileChooserDialogImpl" timestamp="1597353496276">
<screen x="0" y="0" width="1366" height="720" />
</state>
@ -267,10 +276,10 @@ @@ -267,10 +276,10 @@
<screen x="0" y="0" width="1366" height="720" />
</state>
<state x="172" y="0" key="SettingsEditor/0.0.1366.720@0.0.1366.720" timestamp="1597530949459" />
<state x="278" y="92" width="800" height="542" key="Vcs.Push.Dialog.v2" timestamp="1597577614375">
<state x="278" y="92" width="800" height="542" key="Vcs.Push.Dialog.v2" timestamp="1597577695094">
<screen x="0" y="0" width="1366" height="720" />
</state>
<state x="278" y="92" width="800" height="542" key="Vcs.Push.Dialog.v2/0.0.1366.720@0.0.1366.720" timestamp="1597577614375" />
<state x="278" y="92" width="800" height="542" key="Vcs.Push.Dialog.v2/0.0.1366.720@0.0.1366.720" timestamp="1597577695094" />
<state x="0" y="0" width="616" height="720" key="find.popup" timestamp="1597346688624">
<screen x="0" y="0" width="1366" height="720" />
</state>

76
app.js

@ -7,7 +7,31 @@ let kara = new Vue({ @@ -7,7 +7,31 @@ let kara = new Vue({
isTyping: false,
templates: {
initialGreeting: "Hi! I'm Kara. :)"
},
answers: [
{
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() {
this.initialGreeting();
@ -49,10 +73,10 @@ let kara = new Vue({ @@ -49,10 +73,10 @@ let kara = new Vue({
}, 2500);
setTimeout(() => {
this.aiMessage(
// this.getAnswerFromDB(message)
this.getAnswer(message)
);
let answer = this.getAnswer(message);
console.log(answer);
this.aiMessage(answer);
this.scrollDown();
}, 3000);
},
@ -63,7 +87,6 @@ let kara = new Vue({ @@ -63,7 +87,6 @@ let kara = new Vue({
},
oneOf(answers) {
let amountOfAnswers = answers.length;
console.log(answers);
let randomIndex = Math.floor(Math.random() * (amountOfAnswers));
console.log(randomIndex);
@ -121,42 +144,29 @@ let kara = new Vue({ @@ -121,42 +144,29 @@ let kara = new Vue({
message = message.toLowerCase();
message = this.cleanupMessage(message);
let phrases = message.split(' ');
let answer = undefined;
// TODO: get options from json
this.answers.forEach((answerOption) => {
if (answerOption.includeAll === true) {
if (
this.includesOneOf(phrases,['hi', 'hallo', 'servas', 'servas', 'servus', 'hello'])
this.includesAllOf(phrases, answerOption.keywords)
) {
return this.oneOf([
'Hey! :)',
'Hello!',
'How are you?'
]);
answer = this.oneOf(answerOption.responses);
}
} else {
if (
this.includesAllOf(phrases,['how', 'are', 'you'])
this.includesOneOf(phrases, answerOption.keywords)
) {
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?'
]);
answer = this.oneOf(answerOption.responses);
}
}
});
if (answer) {
return answer;
}
return 'I don\'t know what to say..';
},
// getAnswerFromDB(message) {
// let answer = null;
//
// axios.post('/karaAI/', {
// message: message
// })
// .then(function (response) {
// console.log(response);
// })
// .catch(function (error) {
// console.log(error)
// })
// }
}
}
})
Loading…
Cancel
Save