var UserCommands = {
'/emotes': function() {
var text = '';
Display.add_message('Available Emotes — Prefix with a : to use', 'help');
Display.add_message(EmoteHelper.legalEmotes.join(', '), 'help');
},
'/help': function() {
var help = [];
Display.add_message('JsChat Help — Type the following commands into the message field:', 'help')
help.push(['/clear', 'Clears messages']);
help.push(['/lastlog', 'Shows recent activity']);
help.push(['/names', 'Refreshes the names list']);
help.push(['/name new_name', 'Changes your name']);
help.push(['/emotes', 'Shows available emotes']);
$A(help).each(function(options) {
var help_text = '#{command}#{text}'.interpolate({ command: options[0], text: options[1]});
Display.add_message(help_text, 'help');
});
},
'/clear': function() {
$('messages').innerHTML = '';
},
'/lastlog': function() {
$('messages').innerHTML = '';
JsChat.Request.get('/lastlog', function(transport) {
this.displayMessages(transport.responseText);
$('names').innerHTML = '';
this.updateNames();
}.bind(this));
},
'/(name|nick)\\s+(.*)': function(name) {
name = name[2];
new Ajax.Request('/change-name', {
method: 'post',
parameters: { name: name },
onSuccess: function(response) {
this.displayMessages(response.responseText, function() {
$('name').innerHTML = name;
Cookie.create('jschat-name', name, 28, '/');
});
}.bind(this),
onFailure: function() {
Display.add_message("Server error: couldn't access: #{url}".interpolate({ url: url }), 'server');
}
});
},
'/names': function() {
JsChat.Request.get('/names', function(t) { this.displayMessages(t.responseText); }.bind(this));
}
};