Refactor chat commands [untested]

This commit is contained in:
calzoneman 2013-03-05 12:51:58 -06:00
parent ab6fc96517
commit ab48c6aa50
2 changed files with 23 additions and 16 deletions

View File

@ -12,6 +12,7 @@ var Rank = require('./rank.js');
// I should use the <noun><verb>er naming scheme more often
var InfoGetter = require('./get-info.js');
var Media = require('./media.js').Media;
var ChatCommand = require('./chatcommand.js');
var Channel = function(name) {
console.log("Opening channel " + name);
@ -387,37 +388,34 @@ Channel.prototype.moveMedia = function(data) {
// Chat message from a user
Channel.prototype.chatMessage = function(user, msg) {
// Temporary code
// When I add more modifiers I should store them in a table
// of some kind
var msgclass = "";
if(msg.indexOf("/me ") == 0) {
msgclass = "action";
msg = msg.substring(3);
}
else if(msg.indexOf("/sp ") == 0) {
msgclass = "spoiler";
msg = msg.substring(3);
}
if(msg.indexOf("/") == 0)
ChatCommand.handle(msg);
else if(msg.indexOf(">") == 0)
msgclass = "greentext";
this.sendMessage(user.name, msg, "greentext");
else
this.sendMessage(user.name, msg, msgclass);
}
Channel.prototype.sendMessage = function(username, msg, msgclass) {
// I don't want HTML from strangers
msg = msg.replace(/</g, "&lt;").replace(/>/g, "&gt;");
// Match URLs
msg = msg.replace(/(((https?)|(ftp))(:\/\/[0-9a-zA-Z\.]+(:[0-9]+)?[^\s$]+))/, "<a href=\"$1\">$1</a>");
this.sendAll('chatMsg', {
username: user.name,
username: username,
msg: msg,
msgclass: msgclass
});
this.recentChat.push({
username: user.name,
username: username,
msg: msg,
msgclass: msgclass
});
if(this.recentChat.length > 15)
this.recentChat.shift();
}
};
// Promotion! Actor is the client who initiated the promotion, name is the
// name of the person being promoted

9
chatcommand.js Normal file
View File

@ -0,0 +1,9 @@
function handle(chan, user, msg) {
if(msg.indexOf("/me ") == 0)
chan.sendMessage(user.name, msg.substring(4), "action");
else if(msg.indexOf("/sp ") == 0)
chan.sendMessage(user.name, msg.substring(4), "spoiler");
}
exports.handle = handle;