diff --git a/channel.js b/channel.js index 2662c070..27b272a3 100644 --- a/channel.js +++ b/channel.js @@ -12,6 +12,7 @@ var Rank = require('./rank.js'); // I should use the 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, ">"); // Match URLs msg = msg.replace(/(((https?)|(ftp))(:\/\/[0-9a-zA-Z\.]+(:[0-9]+)?[^\s$]+))/, "$1"); 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 diff --git a/chatcommand.js b/chatcommand.js new file mode 100644 index 00000000..93bdea60 --- /dev/null +++ b/chatcommand.js @@ -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; +