Implement an autolock for multiple roombans

This commit is contained in:
Bär Halberkamp
2016-12-11 05:40:39 +01:00
committed by Guangcong Luo
parent 7b4a482373
commit 075b9f03cb
3 changed files with 29 additions and 1 deletions

View File

@@ -101,6 +101,14 @@ exports.reportbattlejoins = true;
// Set this to 0 to turn the monitor off.
exports.monitorminpunishments = 3;
// allow punishmentmonitor to lock users with multiple roombans.
// When set to `true`, this feature will automatically lock any users with three or more
// active roombans, and notify the staff room.
// Note that this requires punishmentmonitor to be enabled, and therefore requires the `monitorminpunishments`
// option to be set to a number greater than zero. If `monitorminpunishments` is set to a value greater than 3,
// the autolock will only apply to people who pass this threshold.
exports.punishmentautolock = false;
// whitelist - prevent users below a certain group from doing things
// For the modchat settings, false will allow any user to participate, while a string
// with a group symbol will restrict it to that group and above. The string

View File

@@ -1065,14 +1065,21 @@ Punishments.getRoomPunishments = function (user, publicOnly) {
* @param {User} user
*/
Punishments.monitorRoomPunishments = function (user) {
if (user.locked) return;
const minPunishments = (typeof Config.monitorminpunishments === 'number' ? Config.monitorminpunishments : 3); // Default to 3 if the Config option is not defined or valid
if (!minPunishments) return;
let punishments = Punishments.getRoomPunishments(user, true);
if (punishments.length >= minPunishments) {
let roombans = [];
let blacklists = [];
let punishmentText = punishments.map(([room, punishment]) => {
const [punishType, punishUserid, , reason] = punishment;
if (punishType === 'ROOMBAN') roombans.push(room.id);
if (punishType === 'BLACKLIST') blacklists.push(room.id);
let punishDesc = Punishments.roomPunishmentTypes.get(punishType);
if (!punishDesc) punishDesc = `punished`;
if (punishUserid !== user.userid) punishDesc += ` as ${punishUserid}`;
@@ -1081,6 +1088,18 @@ Punishments.monitorRoomPunishments = function (user) {
return `<<${room}>> (${punishDesc})`;
}).join(', ');
Monitor.log(`[PunishmentMonitor] ${user.name} currently has punishments in ${punishments.length} rooms: ${punishmentText}`);
if (Config.punishmentautolock && roombans.length && (roombans.length + blacklists.length) >= 3) {
let roombanString = roombans.join(', ');
let blacklistString = blacklists.map(str => `${str} (blacklisted)`).join(', ');
let sep = roombanString && blacklistString ? ', ' : '';
let reason = `Autolocked for being banned from ${roombans.length + blacklists.length} rooms: ${roombanString}${sep}${blacklistString}`;
Punishments.lock(user, Date.now() + LOCK_DURATION, user.userid, reason);
Monitor.log(`[PunishmentMonitor] ${user.name} was locked for being banned from ${roombans.length + blacklists.length} rooms: ${punishmentText}`);
user.popup("|modal|You've been locked for breaking the rules in multiple chatrooms.\n\nIf you feel that your lock was unjustified, you can still PM staff members (%, @, &, and ~) to discuss it" + (Config.appealurl ? " or you can appeal:\n" + Config.appealurl : ".") + "\n\nYour lock will expire in a few days.");
Rooms.global.modlog(`(staff) AUTOLOCK: [${user.userid}]: ${reason}`);
} else {
Monitor.log(`[PunishmentMonitor] ${user.name} currently has punishments in ${punishments.length} rooms: ${punishmentText}`);
}
}
};

View File

@@ -90,6 +90,7 @@ class Room {
addRaw(message) {
return this.add('|raw|' + message);
}
getLogSlice(amount) {
let log = this.log.slice(amount);
log.unshift('|:|' + (~~(Date.now() / 1000)));