Browse Source

Add /me;

master
neroignis 5 years ago
parent
commit
d7ed7d85d4
  1. 4
      app.css
  2. 17
      app.js
  3. 2
      index.html

4
app.css

@ -76,3 +76,7 @@ body {
max-height: 2em; max-height: 2em;
margin-right: 5px; margin-right: 5px;
} }
.me-message {
background-color: orange;
}

17
app.js

@ -87,11 +87,12 @@ let kara = new Vue({
this.scrollDown(); this.scrollDown();
}, },
methods: { methods: {
addMessage(body, bot) { addMessage(body, bot, me = false) {
this.messages.push({ this.messages.push({
body: body, body: body,
bot: bot, bot: bot,
command: body.search('/') === 0, command: body.search('/') === 0,
me: me,
time: Date.now() time: Date.now()
}) })
}, },
@ -132,15 +133,17 @@ let kara = new Vue({
return false; return false;
} }
if (this.chatbox.search('/me') !== 0) {
this.userMessage(this.chatbox); this.userMessage(this.chatbox);
}
this.scrollDown(); this.scrollDown();
this.react(this.chatbox); this.react(this.chatbox);
this.chatbox = ''; this.chatbox = '';
}, },
react(message) { react(message, recursive = false) {
this.isTyping = true; this.isTyping = true;
if (message.search('/') === 0) { if (message.search('/') === 0 && !recursive) {
setTimeout(() => { setTimeout(() => {
this.processCommands(message); this.processCommands(message);
@ -185,6 +188,10 @@ let kara = new Vue({
if (this.checkForCommands(message, 'joke')) { if (this.checkForCommands(message, 'joke')) {
this.tellJoke(this.checkForCommands(message, 'joke')) this.tellJoke(this.checkForCommands(message, 'joke'))
} }
if (this.checkForCommands(message, 'me')) {
this.meMessage(this.checkForCommands(message, 'me'))
}
}, },
checkForCommands(message, commands) { checkForCommands(message, commands) {
if (!Array.isArray(commands)) { if (!Array.isArray(commands)) {
@ -561,6 +568,10 @@ let kara = new Vue({
this.updateStorage(); this.updateStorage();
}, },
meMessage(message) {
this.addMessage(this.username + ' ' + message, false, true);
this.react(message, true);
},
clearStorage() { clearStorage() {
localStorage.clear(); localStorage.clear();
location.reload(); location.reload();

2
index.html

@ -37,7 +37,7 @@
{{ message.body }} {{ message.body }}
<br/> <br/>
</div> </div>
<div :class="'message user-message float-right' + (message.command ? ' command-message' : '')" v-else> <div :class="'message user-message float-right' + (message.command ? ' command-message' : '') + (message.me ? ' me-message' : '')" v-else>
{{ message.body }} {{ message.body }}
<br/> <br/>
</div> </div>

Loading…
Cancel
Save