mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-19 02:59:57 +00:00
Closes #12 - /me command
This commit is contained in:
parent
c7902a6e29
commit
edfab8a0c3
@ -156,6 +156,7 @@ export default class Chat {
|
|||||||
command: 'nick',
|
command: 'nick',
|
||||||
description: 'Changes nickname.',
|
description: 'Changes nickname.',
|
||||||
paramaters: ['{username}'],
|
paramaters: ['{username}'],
|
||||||
|
multiple: false,
|
||||||
usage: '/nick {username}',
|
usage: '/nick {username}',
|
||||||
action: () => {
|
action: () => {
|
||||||
let newUsername = trigger.params[0] || false;
|
let newUsername = trigger.params[0] || false;
|
||||||
@ -186,13 +187,37 @@ export default class Chat {
|
|||||||
command: 'help',
|
command: 'help',
|
||||||
description: 'Shows a list of commands.',
|
description: 'Shows a list of commands.',
|
||||||
paramaters: [],
|
paramaters: [],
|
||||||
|
multiple: false,
|
||||||
usage: '/help',
|
usage: '/help',
|
||||||
action: () => {
|
action: () => {
|
||||||
validCommands = validCommands.map((command) => {
|
validCommands = validCommands.map((command) => {
|
||||||
return '/' + command;
|
return '/' + command;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.log('Valid commands: ' + validCommands.join(', '), {info: true});
|
this.log('Valid commands: ' + validCommands.sort().join(', '), {info: true});
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
command: 'me',
|
||||||
|
description: 'Invoke virtual action',
|
||||||
|
paramaters: ['{action}'],
|
||||||
|
multiple: true,
|
||||||
|
usage: '/me {action}',
|
||||||
|
action: () => {
|
||||||
|
|
||||||
|
expectedParams = 100;
|
||||||
|
|
||||||
|
let actionMessage = trigger.params.join(' ');
|
||||||
|
|
||||||
|
this.darkwire.encodeMessage(actionMessage, 'action').then((socketData) => {
|
||||||
|
this.addChatMessage({
|
||||||
|
username: username,
|
||||||
|
message: actionMessage,
|
||||||
|
messageType: 'action'
|
||||||
|
});
|
||||||
|
this.socket.emit('new message', socketData);
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@ -208,9 +233,12 @@ export default class Chat {
|
|||||||
|
|
||||||
if (commandToTrigger) {
|
if (commandToTrigger) {
|
||||||
expectedParams = commandToTrigger.paramaters.length;
|
expectedParams = commandToTrigger.paramaters.length;
|
||||||
if (trigger.params.length > expectedParams || trigger.params.length < expectedParams) {
|
if (expectedParams && trigger.params.length > expectedParams || expectedParams && trigger.params.length < expectedParams) {
|
||||||
return this.log('Missing or too many paramater. Usage: ' + commandToTrigger.usage, {error: true});
|
if (!commandToTrigger.multple && trigger.params.length < 1) {
|
||||||
|
return this.log('Missing or too many paramater. Usage: ' + commandToTrigger.usage, {error: true});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return commandToTrigger.action.call();
|
return commandToTrigger.action.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,18 +295,25 @@ export default class Chat {
|
|||||||
let $usernameDiv = $('<span class="username"/>')
|
let $usernameDiv = $('<span class="username"/>')
|
||||||
.text(data.username)
|
.text(data.username)
|
||||||
.css('color', this.getUsernameColor(data.username));
|
.css('color', this.getUsernameColor(data.username));
|
||||||
|
|
||||||
let $messageBodyDiv = $('<span class="messageBody">');
|
let $messageBodyDiv = $('<span class="messageBody">');
|
||||||
if (messageType !== 'text') {
|
|
||||||
$messageBodyDiv.html(this.darkwire.addFileToQueue(data));
|
if (messageType === 'text' || messageType === 'action') {
|
||||||
} else {
|
if (messageType === 'action') {
|
||||||
|
$usernameDiv.css('color','').prepend('*');
|
||||||
|
}
|
||||||
$messageBodyDiv.html(unescape(data.message));
|
$messageBodyDiv.html(unescape(data.message));
|
||||||
|
} else {
|
||||||
|
$messageBodyDiv.html(this.darkwire.addFileToQueue(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
let typingClass = data.typing ? 'typing' : '';
|
let typingClass = data.typing ? 'typing' : '';
|
||||||
|
let actionClass = data.messageType === 'action' ? 'action' : '';
|
||||||
|
|
||||||
let $messageDiv = $('<li class="message"/>')
|
let $messageDiv = $('<li class="message"/>')
|
||||||
.data('username', data.username)
|
.data('username', data.username)
|
||||||
.addClass(typingClass)
|
.addClass(typingClass)
|
||||||
|
.addClass(actionClass)
|
||||||
.append($usernameDiv, $messageBodyDiv);
|
.append($usernameDiv, $messageBodyDiv);
|
||||||
|
|
||||||
this.addMessageElement($messageDiv, options);
|
this.addMessageElement($messageDiv, options);
|
||||||
|
@ -3,6 +3,7 @@ import Darkwire from './darkwire';
|
|||||||
import WindowHandler from './window';
|
import WindowHandler from './window';
|
||||||
import CryptoUtil from './crypto';
|
import CryptoUtil from './crypto';
|
||||||
import Chat from './chat';
|
import Chat from './chat';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
let fs = window.RequestFileSystem || window.webkitRequestFileSystem;
|
let fs = window.RequestFileSystem || window.webkitRequestFileSystem;
|
||||||
|
|
||||||
@ -49,6 +50,7 @@ $(function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chat.log(moment().format('MMMM Do YYYY, h:mm:ss a'), {info: true});
|
||||||
darkwire.updateUsername(username).then((socketData) => {
|
darkwire.updateUsername(username).then((socketData) => {
|
||||||
chat.chatPage.show();
|
chat.chatPage.show();
|
||||||
chat.inputMessage.focus();
|
chat.inputMessage.focus();
|
||||||
|
@ -312,3 +312,8 @@ html.no-touchevents .chat #input-icons {
|
|||||||
color: yellow;
|
color: yellow;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.action {
|
||||||
|
font-style: italic;
|
||||||
|
color: #00FF7F;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user