Browse Source

Move answers to data.

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

23
.idea/workspace.xml

@ -5,6 +5,7 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e3f098f0-e98c-435a-af04-d153c9525633" name="Default Changelist" comment=""> <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" /> <change beforePath="$PROJECT_DIR$/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/app.js" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -45,7 +46,7 @@
<workItem from="1597346228730" duration="1851000" /> <workItem from="1597346228730" duration="1851000" />
<workItem from="1597348092890" duration="8205000" /> <workItem from="1597348092890" duration="8205000" />
<workItem from="1597530844649" duration="131000" /> <workItem from="1597530844649" duration="131000" />
<workItem from="1597577497243" duration="188000" /> <workItem from="1597577497243" duration="1451000" />
</task> </task>
<task id="LOCAL-00001" summary="Adds gitignore."> <task id="LOCAL-00001" summary="Adds gitignore.">
<created>1597348071361</created> <created>1597348071361</created>
@ -222,7 +223,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1597577559042</updated> <updated>1597577559042</updated>
</task> </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 /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -240,17 +248,18 @@
<MESSAGE value="Testing database access." /> <MESSAGE value="Testing database access." />
<MESSAGE value="Test commit." /> <MESSAGE value="Test commit." />
<MESSAGE value="Remove DB method call." /> <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>
<component name="WindowStateProjectService"> <component name="WindowStateProjectService">
<state x="278" y="2" width="800" height="718" key="#Plugins" timestamp="1597350105557"> <state x="278" y="2" width="800" height="718" key="#Plugins" timestamp="1597350105557">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
<state x="278" y="2" width="800" height="718" key="#Plugins/0.0.1366.720@0.0.1366.720" timestamp="1597350105557" /> <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" /> <screen x="0" y="0" width="1366" height="720" />
</state> </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"> <state x="466" y="118" width="424" height="490" key="FileChooserDialogImpl" timestamp="1597353496276">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
@ -267,10 +276,10 @@
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
<state x="172" y="0" key="SettingsEditor/0.0.1366.720@0.0.1366.720" timestamp="1597530949459" /> <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" /> <screen x="0" y="0" width="1366" height="720" />
</state> </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"> <state x="0" y="0" width="616" height="720" key="find.popup" timestamp="1597346688624">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>

86
app.js

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