Add /mute command

This commit is contained in:
calzoneman 2013-06-25 10:18:33 -04:00
parent 259d7470e1
commit ccae0ea76e
4 changed files with 63 additions and 1 deletions

View File

@ -65,6 +65,7 @@ var Channel = function(name) {
playlistclear: 2,
pollctl: 1.5,
pollvote: -1,
mute: 1.5,
kick: 1.5,
ban: 2,
motdedit: 3,
@ -1719,6 +1720,14 @@ Channel.prototype.tryChat = function(user, data) {
if(!this.hasPermission(user, "chat"))
return;
if(user.muted) {
user.socket.emit("noflood", {
action: "chat",
msg: "You have been muted on this channel."
});
return;
}
if(typeof data.msg !== "string") {
return;
}
@ -1770,6 +1779,7 @@ Channel.prototype.filterMessage = function(msg) {
Channel.prototype.sendMessage = function(username, msg, msgclass, data) {
// I don't want HTML from strangers
msg = msg.replace(/&/g, "&");
msg = msg.replace(/</g, "&lt;").replace(/>/g, "&gt;");
msg = this.filterMessage(msg);
var msgobj = {

View File

@ -55,6 +55,12 @@ function handle(chan, user, msg, data) {
chan.chainMessage(user, cargs.join(" "), flair);
}
}
else if(msg.indexOf("/mute ") == 0) {
handleMute(chan, user, msg.substring(6).split(" "));
}
else if(msg.indexOf("/unmute ") == 0) {
handleUnmute(chan, user, msg.substring(8).split(" "));
}
else if(msg.indexOf("/kick ") == 0) {
handleKick(chan, user, msg.substring(6).split(" "));
}
@ -85,6 +91,46 @@ function handle(chan, user, msg, data) {
}
}
function handleMute(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) {
person.meta.icon = "icon-volume-off";
person.muted = true;
chan.broadcastUserUpdate(person);
chan.logger.log("*** " + user.name + " muted " + args[0]);
}
}
}
function handleUnmute(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) {
person.meta.icon = false;
person.muted = false;
chan.broadcastUserUpdate(person);
chan.logger.log("*** " + user.name + " unmuted " + args[0]);
}
}
}
function handleKick(chan, user, args) {
if(chan.hasPermission(user, "kick") && args.length > 0) {
args[0] = args[0].toLowerCase();

View File

@ -30,8 +30,10 @@ var User = function(socket, ip) {
this.channel = null;
this.name = "";
this.meta = {
afk: false
afk: false,
icon: false
};
this.muted = false;
this.throttle = {};
this.flooded = {};
this.profile = {

View File

@ -98,6 +98,9 @@ function formatUserlistItem(div, data) {
name.css("font-style", "italic");
$("<i/>").addClass("icon-time").appendTo(flair);
}
if(data.meta && data.meta.icon) {
$("<i/>").addClass(data.meta.icon).prependTo(flair);
}
}
function getNameColor(rank) {
@ -1294,6 +1297,7 @@ function genPermissionsEditor() {
makeOption("Vote", "pollvote", standard, CHANNEL.perms.pollvote+"");
addDivider("Moderation");
makeOption("Mute users", "mute", modleader, CHANNEL.perms.mute+"");
makeOption("Kick users", "kick", modleader, CHANNEL.perms.kick+"");
makeOption("Ban users", "ban", modplus, CHANNEL.perms.ban+"");
makeOption("Edit MOTD", "motdedit", modplus, CHANNEL.perms.motdedit+"");