From 6588e90bfe2fba3239ff352d990d42b205daad26 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Fri, 8 Nov 2013 20:45:59 -0600 Subject: [PATCH] Add basic shadow mute command --- changelog | 4 ++++ lib/channel.js | 13 +++++++++++++ lib/chatcommand.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/changelog b/changelog index 77c1a2c5..15613d92 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +Fri Nov 08 20:44 2013 CDT + * lib/channel.js, lib/chatcommand.js: Implement basic shadow mute + command + Fri Nov 08 17:55 2013 CDT * lib/get-info.js: Strip "ip" and "expire" fields from Google Drive flashvars diff --git a/lib/channel.js b/lib/channel.js index 83da616f..0c8ab362 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -2201,6 +2201,19 @@ Channel.prototype.tryChat = function(user, data) { return; } + if (this.mutedUsers.contains("[shadow]" + user.name.toLowerCase())) { + msg = sanitize(msg).escape(); + msg = this.filterMessage(msg); + var msgobj = { + username: user.name, + msg: msg, + msgclass: "", + time: Date.now() + }; + user.socket.emit("chatMsg", msgobj); + return; + } + this.chainMessage(user, msg); } diff --git a/lib/chatcommand.js b/lib/chatcommand.js index 5ae799bf..b4c7c1f2 100644 --- a/lib/chatcommand.js +++ b/lib/chatcommand.js @@ -56,6 +56,9 @@ function handle(chan, user, msg, data) { else if(msg.indexOf("/mute ") == 0) { handleMute(chan, user, msg.substring(6).split(" ")); } + else if(msg.indexOf("/smute ") == 0) { + handleShadowMute(chan, user, msg.substring(7).split(" ")); + } else if(msg.indexOf("/unmute ") == 0) { handleUnmute(chan, user, msg.substring(8).split(" ")); } @@ -98,6 +101,41 @@ function handle(chan, user, msg, data) { } } +function handleShadowMute(chan, user, args) { + if(chan.hasPermission(user, "mute") && args.length > 0) { + args[0] = args[0].toLowerCase(); + var person = false; + for(var i = 0; i < chan.users.length; i++) { + if(chan.users[i].name.toLowerCase() == args[0]) { + person = chan.users[i]; + break; + } + } + + if(person) { + if(person.rank >= user.rank) { + user.socket.emit("errorMsg", { + msg: "You don't have permission to mute that person." + }); + return; + } + chan.mutedUsers.add("[shadow]" + person.name.toLowerCase()); + chan.logger.log("*** " + user.name + " shadow muted " + args[0]); + var pkt = { + username: "[server]", + msg: user.name + " shadow muted " + args[0], + msgclass: "server-whisper", + time: Date.now() + }; + chan.users.forEach(function (u) { + if (u.rank >= 2) { + u.socket.emit("chatMsg", pkt); + } + }); + } + } +} + function handleMute(chan, user, args) { if(chan.hasPermission(user, "mute") && args.length > 0) { args[0] = args[0].toLowerCase(); @@ -144,6 +182,7 @@ function handleUnmute(chan, user, args) { } person.meta.icon = false; chan.mutedUsers.remove(person.name.toLowerCase()); + chan.mutedUsers.remove("[shadow]" + person.name.toLowerCase()); chan.broadcastUserUpdate(person); chan.logger.log("*** " + user.name + " unmuted " + args[0]); }