From 075b9f03cb641dfd02e775ecc5a045a869e8c846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A4r=20Halberkamp?= Date: Sun, 11 Dec 2016 05:40:39 +0100 Subject: [PATCH] Implement an autolock for multiple roombans --- config/config-example.js | 8 ++++++++ punishments.js | 21 ++++++++++++++++++++- rooms.js | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/config/config-example.js b/config/config-example.js index cfa3388559..b7cecbfdaf 100644 --- a/config/config-example.js +++ b/config/config-example.js @@ -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 diff --git a/punishments.js b/punishments.js index 649aa89f62..f7d3e7e010 100644 --- a/punishments.js +++ b/punishments.js @@ -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}`); + } } }; diff --git a/rooms.js b/rooms.js index 193229ea42..e31b7562c5 100644 --- a/rooms.js +++ b/rooms.js @@ -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)));