Change the way /mute works

This commit is contained in:
calzoneman 2013-10-16 17:36:05 -05:00
parent 5eda748fc4
commit 120d56d6c8
5 changed files with 51 additions and 5 deletions

View File

@ -1,3 +1,10 @@
Wed Oct 16 17:34 2013 CDT
* lib/utilities.js: Add a "Set" wrapper around objects to represent
sets.
* lib/channel.js, lib/user.js: Change the way muting works- muted
users are stored in a set and are automatically muted when they
join (this set is not persisted across restarts, however).
Wed Oct 16 17:19 2013 CDT Wed Oct 16 17:19 2013 CDT
* lib/channel.js, lib/user.js: Only kick users on permissions * lib/channel.js, lib/user.js: Only kick users on permissions
violations. Fail silently on bad packets. violations. Fail silently on bad packets.

View File

@ -38,6 +38,7 @@ var Channel = function(name) {
// Initialize defaults // Initialize defaults
self.registered = false; self.registered = false;
self.users = []; self.users = [];
self.mutedUsers = new $util.Set();
self.playlist = new Playlist(self); self.playlist = new Playlist(self);
self.plqueue = new AsyncQueue(); self.plqueue = new AsyncQueue();
self.position = -1; self.position = -1;
@ -1097,6 +1098,9 @@ Channel.prototype.broadcastNewUser = function(user) {
self.kick(user, "You're banned!"); self.kick(user, "You're banned!");
return; return;
} }
if (self.mutedUsers.contains(user.name.toLowerCase())) {
user.meta.icon = "icon-volume-off";
}
self.sendAll("addUser", { self.sendAll("addUser", {
name: user.name, name: user.name,
rank: user.rank, rank: user.rank,
@ -2181,7 +2185,7 @@ Channel.prototype.tryChat = function(user, data) {
if(!this.hasPermission(user, "chat")) if(!this.hasPermission(user, "chat"))
return; return;
if(user.muted) { if (this.mutedUsers.contains(user.name.toLowerCase())) {
user.socket.emit("noflood", { user.socket.emit("noflood", {
action: "chat", action: "chat",
msg: "You have been muted on this channel." msg: "You have been muted on this channel."

View File

@ -117,7 +117,7 @@ function handleMute(chan, user, args) {
return; return;
} }
person.meta.icon = "icon-volume-off"; person.meta.icon = "icon-volume-off";
person.muted = true; chan.mutedUsers.add(person.name.toLowerCase());
chan.broadcastUserUpdate(person); chan.broadcastUserUpdate(person);
chan.logger.log("*** " + user.name + " muted " + args[0]); chan.logger.log("*** " + user.name + " muted " + args[0]);
} }
@ -143,7 +143,7 @@ function handleUnmute(chan, user, args) {
return; return;
} }
person.meta.icon = false; person.meta.icon = false;
person.muted = false; chan.mutedUsers.remove(person.name.toLowerCase());
chan.broadcastUserUpdate(person); chan.broadcastUserUpdate(person);
chan.logger.log("*** " + user.name + " unmuted " + args[0]); chan.logger.log("*** " + user.name + " unmuted " + args[0]);
} }

View File

@ -33,7 +33,6 @@ var User = function (socket) {
afk: false, afk: false,
icon: false icon: false
}; };
this.muted = false;
this.throttle = {}; this.throttle = {};
this.flooded = {}; this.flooded = {};
this.queueLimiter = $util.newRateLimiter(); this.queueLimiter = $util.newRateLimiter();

View File

@ -1,3 +1,37 @@
/*
Set prototype- simple wrapper around JS objects to
manipulate them like a set
*/
var Set = function (items) {
this._items = {};
var self = this;
if (items instanceof Array)
items.forEach(function (it) { self.add(it); });
};
Set.prototype.contains = function (what) {
return (what in this._items);
};
Set.prototype.add = function (what) {
this._items[what] = true;
};
Set.prototype.remove = function (what) {
if (what in this._items)
delete this._items[what];
};
Set.prototype.clear = function () {
this._items = {};
};
Set.prototype.forEach = function (fn) {
for (var k in this._items) {
fn(k);
}
};
module.exports = { module.exports = {
isValidChannelName: function (name) { isValidChannelName: function (name) {
return name.match(/^[\w-_]{1,30}$/); return name.match(/^[\w-_]{1,30}$/);
@ -127,5 +161,7 @@ module.exports = {
default: default:
return ""; return "";
} }
} },
Set: Set
}; };