Start refactoring commands
This commit is contained in:
parent
b200d6cc2c
commit
6e99990ef0
4 changed files with 172 additions and 7 deletions
|
|
@ -2186,6 +2186,10 @@ Channel.prototype.tryUpdateMotd = function(user, data) {
|
|||
/* REGION Chat */
|
||||
|
||||
Channel.prototype.tryChat = function(user, data) {
|
||||
if (data.meta === undefined) {
|
||||
data.meta = {};
|
||||
}
|
||||
|
||||
if(user.name == "") {
|
||||
return;
|
||||
}
|
||||
|
|
@ -2219,14 +2223,21 @@ Channel.prototype.tryChat = function(user, data) {
|
|||
var msgobj = {
|
||||
username: user.name,
|
||||
msg: msg,
|
||||
msgclass: "",
|
||||
meta: data.meta,
|
||||
time: Date.now()
|
||||
};
|
||||
user.socket.emit("chatMsg", msgobj);
|
||||
return;
|
||||
}
|
||||
|
||||
this.chainMessage(user, msg);
|
||||
if (msg.indexOf("/") === 0) {
|
||||
ChatCommand.handle(this, user, msg, data.meta);
|
||||
} else {
|
||||
if (msg.indexOf(">") === 0) {
|
||||
data.meta.addClass = "greentext";
|
||||
}
|
||||
this.sendMessage(user, msg, data.meta);
|
||||
}
|
||||
}
|
||||
|
||||
Channel.prototype.chainMessage = function(user, msg, data) {
|
||||
|
|
@ -2271,7 +2282,29 @@ Channel.prototype.filterMessage = function(msg) {
|
|||
return subs.join("");
|
||||
}
|
||||
|
||||
Channel.prototype.sendMessage = function(username, msg, msgclass, data) {
|
||||
Channel.prototype.sendMessage = function (user, msg, meta, filter) {
|
||||
msg = sanitize(msg).escape();
|
||||
msg = this.filterMessage(msg);
|
||||
var msgobj = {
|
||||
username: user.name,
|
||||
msg: msg,
|
||||
meta: meta,
|
||||
time: Date.now()
|
||||
}
|
||||
|
||||
if (filter && filter.byRank !== undefined) {
|
||||
this.sendAllWithRank("chatMsg", msgobj, filter.byRank);
|
||||
} else {
|
||||
this.sendAll("chatMsg", msgobj);
|
||||
this.chatbuffer.push(msgobj);
|
||||
if(this.chatbuffer.length > 15)
|
||||
this.chatbuffer.shift();
|
||||
var unescaped = sanitize(msg).entityDecode();
|
||||
this.logger.log("<" + user.name + "> " + unescaped);
|
||||
}
|
||||
};
|
||||
|
||||
Channel.prototype.sendMessageOld = function(username, msg, msgclass, data) {
|
||||
// I don't want HTML from strangers
|
||||
msg = sanitize(msg).escape();
|
||||
msg = this.filterMessage(msg);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,77 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||
var Logger = require("./logger.js");
|
||||
var Poll = require("./poll").Poll;
|
||||
|
||||
function handle(chan, user, msg, data) {
|
||||
var handlers = {
|
||||
"me": function (chan, user, msg, meta) {
|
||||
meta.addClass = "action";
|
||||
meta.action = true;
|
||||
chan.sendMessage(user, msg, meta);
|
||||
},
|
||||
"sp": function (chan, user, msg, meta) {
|
||||
meta.addClass = "spoiler";
|
||||
chan.sendMessage(user, msg, meta);
|
||||
},
|
||||
"say": function (chan, user, msg, meta) {
|
||||
if (user.rank >= 1.5) {
|
||||
meta.addClass = "shout";
|
||||
meta.forceShowName = true;
|
||||
chan.sendMessage(user, msg, meta);
|
||||
}
|
||||
},
|
||||
"afk": function (chan, user, msg, meta) {
|
||||
user.setAFK(!user.meta.afk);
|
||||
},
|
||||
"a": function (chan, user, msg, meta) {
|
||||
var superadminflair = {
|
||||
labelclass: "label-important",
|
||||
icon: "icon-globe"
|
||||
};
|
||||
|
||||
var args = msg.split(" ");
|
||||
var cargs = [];
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
var a = args[i];
|
||||
if (a.indexOf("!icon-") === 0) {
|
||||
superadminflair.icon = a.substring(1);
|
||||
} else if (a.indexOf("!label-") === 0) {
|
||||
superadminflair.labelclass = a.substring(1);
|
||||
} else {
|
||||
cargs.push(a);
|
||||
}
|
||||
}
|
||||
|
||||
meta.superadminflair = superadminflair;
|
||||
meta.forceShowName = true;
|
||||
chan.sendMessage(user, cargs.join(" "), meta);
|
||||
},
|
||||
"mute": function (chan, user, msg, meta) {
|
||||
handleMute(chan, user, msg.split(" "));
|
||||
},
|
||||
"smute": function (chan, user, msg, meta) {
|
||||
handleShadowMute(chan, user, msg.split(" "));
|
||||
}
|
||||
};
|
||||
|
||||
var handlerList = [];
|
||||
for (var key in handlers) {
|
||||
handlerList.push({
|
||||
sub: key.length + 2,
|
||||
re: new RegExp("^\\/" + key + "(?:\\s|$)"),
|
||||
fn: handlers[key]
|
||||
});
|
||||
}
|
||||
|
||||
function handle(chan, user, msg, meta) {
|
||||
for (var i = 0; i < handlerList.length; i++) {
|
||||
var h = handlerList[i];
|
||||
if (msg.match(h.re)) {
|
||||
h.fn(chan, user, msg.substring(h.sub), meta);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleOld(chan, user, msg, data) {
|
||||
if(msg.indexOf("/me ") == 0)
|
||||
chan.sendMessage(user.name, msg.substring(4), "action", data);
|
||||
else if(msg.indexOf("/sp ") == 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue