Skip to content

Commit

Permalink
Implement /unblacklistall command
Browse files Browse the repository at this point in the history
This also introduces Punishments#roomUnblacklistAll to do the heavy lifting of this command.
  • Loading branch information
panpawn committed Sep 30, 2016
1 parent f5271bb commit 8736044
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions commands.js
Expand Up @@ -2149,6 +2149,27 @@ let commands = exports.commands = {
},
unblacklisthelp: ["/unblacklist [username] - Unblacklists the user from the room you are in. Requires: # & ~"],

unblacklistall: function (target, room, user) {
if (!this.can('editroom', null, room)) return false;

if (!target) {
user.lastCommand = '/unblacklistall';
this.errorReply("THIS WILL UNBLACKLIST ALL BLACKLISTED USERS IN THIS ROOM.");
this.errorReply("To confirm, use: /unblacklistall confirm");
return;
}
if (user.lastCommand !== '/unblacklistall' || target !== 'confirm') {
return this.parse('/help unblacklistall');
}

let unblacklisted = Punishments.roomUnblacklistAll(room);
if (!unblacklisted) return this.errorReply("No users are currently blacklisted in this room to unblacklist.");
let reply = `All blacklists in this room have been lifted by ${user.name}.`;
room.add(`|c|${user.getIdentity()}|/log ${reply}`).update();
this.logEntry(`${reply} This has unblacklisted: ${unblacklisted.join(', ')}`);
},
unblacklistallhelp: ["/unblacklistall - Unblacklists all blacklisted users in the current room. Requires #, &, ~"],

blacklists: 'showblacklist',
showbl: 'showblacklist',
showblacklist: function (target, room, user) {
Expand Down
17 changes: 17 additions & 0 deletions punishments.js
Expand Up @@ -726,6 +726,23 @@ Punishments.roomUnblacklist = function (room, userid) {
return Punishments.roomUnpunish(room, userid, 'BLACKLIST');
};

Punishments.roomUnblacklistAll = function (room) {
const roombans = Punishments.roomUserids.get(room.id);
if (!roombans) return false;

let unblacklisted = [];

roombans.forEach((punishment, userid) => {
if (punishment[0] === 'BLACKLIST') {
Punishments.roomUnblacklist(room, userid);
unblacklisted.push(userid);
}
});
if (unblacklisted.length === 0) return false;
Punishments.savePunishments();
return unblacklisted;
};

/*********************************************************
* Checking
*********************************************************/
Expand Down

0 comments on commit 8736044

Please sign in to comment.