Browse Source

Add message filters;

Add responsiveness;
Remove disabled input while Kara types;
Does not send empty messages;
master
Nero Ignis 5 years ago
parent
commit
c7971bbc01
  1. 55
      .idea/workspace.xml
  2. 4
      app.css
  3. 87
      app.js
  4. 5
      index.html

55
.idea/workspace.xml

@ -1,7 +1,15 @@ @@ -1,7 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<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="Adds gitignore.">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app.css" beforeDir="false" afterPath="$PROJECT_DIR$/app.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/app.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/index.html" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -10,8 +18,12 @@ @@ -10,8 +18,12 @@
<component name="ComposerSettings">
<execution />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="PhpDebugGeneral" listening_started="true" />
<component name="ProjectId" id="1g0vdLKoCZC7Ep9S79Z434EvL8a" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
@ -21,7 +33,7 @@ @@ -21,7 +33,7 @@
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last.edited.regexp" value="Why, ever, would you? Stupid! pf." />
<property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
<property name="settings.editor.selected.configurable" value="project.propVCSSupport.Mappings" />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
@ -33,29 +45,54 @@ @@ -33,29 +45,54 @@
<updated>1597264410641</updated>
<workItem from="1597264411672" duration="27000" />
<workItem from="1597264469454" duration="594000" />
<workItem from="1597346228730" duration="1396000" />
<workItem from="1597346228730" duration="1851000" />
<workItem from="1597348092890" duration="2029000" />
</task>
<task id="LOCAL-00001" summary="Adds gitignore.">
<created>1597348071361</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1597348071361</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Adds gitignore." />
<option name="LAST_COMMIT_MESSAGE" value="Adds gitignore." />
</component>
<component name="WindowStateProjectService">
<state x="172" y="0" key="SettingsEditor" timestamp="1597346967163">
<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="1597348122811">
<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="1597348122811" />
<state x="172" y="0" key="SettingsEditor" timestamp="1597347922296">
<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="1597347922296" />
<state x="278" y="92" width="800" height="542" key="Vcs.Push.Dialog.v2" timestamp="1597348073415">
<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="1597346967163" />
<state x="278" y="92" width="800" height="542" key="Vcs.Push.Dialog.v2/0.0.1366.720@0.0.1366.720" timestamp="1597348073415" />
<state x="0" y="0" width="616" height="720" key="find.popup" timestamp="1597346688624">
<screen x="0" y="0" width="1366" height="720" />
</state>
<state x="0" y="0" width="616" height="720" key="find.popup/0.0.1366.720@0.0.1366.720" timestamp="1597346688624" />
<state width="533" height="302" key="javadoc.popup.new" timestamp="1597347220132">
<state width="533" height="302" key="javadoc.popup.new" timestamp="1597349276436">
<screen x="0" y="0" width="1366" height="720" />
</state>
<state width="533" height="302" key="javadoc.popup.new/0.0.1366.720@0.0.1366.720" timestamp="1597347220132" />
<state x="346" y="41" width="672" height="678" key="search.everywhere.popup" timestamp="1597346938306">
<state width="533" height="302" key="javadoc.popup.new/0.0.1366.720@0.0.1366.720" timestamp="1597349276436" />
<state x="346" y="41" width="672" height="678" key="search.everywhere.popup" timestamp="1597350068560">
<screen x="0" y="0" width="1366" height="720" />
</state>
<state x="346" y="41" width="672" height="678" key="search.everywhere.popup/0.0.1366.720@0.0.1366.720" timestamp="1597346938306" />
<state x="346" y="41" width="672" height="678" key="search.everywhere.popup/0.0.1366.720@0.0.1366.720" timestamp="1597350068560" />
</component>
</project>

4
app.css

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
#kara {
margin: 2em auto auto auto;
width: 50em;
max-width: 99%;
max-height: 100%;
}
#kara .card {
@ -26,5 +28,5 @@ @@ -26,5 +28,5 @@
#chat-box {
overflow-y: scroll;
height: 100%
height: 25em;
}

87
app.js

@ -31,7 +31,12 @@ let kara = new Vue({ @@ -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({ @@ -47,35 +52,44 @@ let kara = new Vue({
this.aiMessage(
this.getAnswer(message)
);
this.scrollDown();
}, 3000);
this.scrollDown();
},
getAnswer(message) {
let isQuestion = (message.indexOf('?') > 0);
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);
message = message.toLowerCase();
message = this.clearMessage(message);
let phrases = message.split(' ');
console.log(answers[randomIndex]);
return answers[randomIndex];
},
includesOneOf(phrases, wordsToSearch) {
let includes = false;
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({ @@ -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..';
}
}
})

5
index.html

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
</title>
<link href="https://bootswatch.com/4/materia/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="app.css" rel="stylesheet" type="text/css"/>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no" name="viewport">
</head>
<body>
<div class="container" id="kara">
@ -49,9 +50,7 @@ @@ -49,9 +50,7 @@
</div>
</div>
<div class="card-footer">
<input autofocus="true" class="form-control" id="chatinput" type="text" v-model="chatbox" v-on:keyup.enter="sendMessage()" v-if="!isTyping" autofocus>
<input autofocus="true" class="form-control" id="chatinput" type="text" v-else disabled>
</input>
<input autofocus="true" class="form-control" id="chatinput" type="text" v-model="chatbox" v-on:keyup.enter="sendMessage()" required autofocus>
</div>
</div>
</div>

Loading…
Cancel
Save