From 2accf99e7fb2caa3f0199b2e7fc0c722eea54e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A4r=20Halberkamp?= Date: Tue, 25 Sep 2018 23:19:16 +0200 Subject: [PATCH] Introduce /unlockname and redesign /unlockip (#4869) - Allow unlocking specific names with /unlockname - Expand /unlockip to work for mods - Clarify which names are locked on /ip --- chat-commands.js | 60 ++++++++++++++++++++++++++++++++++---------- chat-plugins/info.js | 14 ++++++++--- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/chat-commands.js b/chat-commands.js index 12c7224c56..0521e544b6 100644 --- a/chat-commands.js +++ b/chat-commands.js @@ -1902,6 +1902,53 @@ const commands = { this.errorReply(`User '${target}' is not locked.`); } }, + unlockname: function (target, room, user) { + if (!target) return this.parse('/help unlock'); + if (!this.can('lock')) return false; + + const userid = toId(target); + const punishment = Punishments.userids.get(userid); + if (!punishment) return this.errorReply("This name isn't locked."); + if (punishment[1] === userid) return this.errorReply(`"${userid}" was specifically locked by a staff member (check the global modlog). Use /unlock if you really want to unlock this name.`); + + Punishments.userids.delete(userid); + Punishments.savePunishments(); + + for (const curUser of Users.findUsers([userid], [])) { + if (curUser.locked && !curUser.locked.startsWith('#') && !Punishments.getPunishType(curUser.userid)) { + curUser.locked = false; + curUser.namelocked = false; + curUser.updateIdentity(); + } + } + this.globalModlog("UNLOCKNAME", userid, ` by ${user.name}`); + this.addModAction(`The name '${target}' was unlocked by ${user.name}.`); + }, + unlockip: function (target, room, user) { + target = target.trim(); + if (!target) return this.parse('/help unlock'); + if (!this.can('ban')) return false; + const range = target.charAt(target.length - 1) === '*'; + if (range && !this.can('rangeban')) return false; + + if (!/^[0-9.*]+$/.test(target)) return this.errorReply("Please enter a valid IP address."); + + const punishment = Punishments.ips.get(target); + if (!punishment) return this.errorReply(`${target} is not a locked/banned IP or IP range.`); + + Punishments.ips.delete(target); + Punishments.savePunishments(); + + for (const curUser of Users.findUsers([], [target])) { + if (curUser.locked && !curUser.locked.startsWith('#') && !Punishments.getPunishType(curUser.userid)) { + curUser.locked = false; + curUser.namelocked = false; + curUser.updateIdentity(); + } + } + this.globalModlog(`UNLOCK${range ? 'RANGE' : 'IP'}`, target, ` by ${user.name}`); + this.addModAction(`${user.name} unlocked the ${range ? "IP range" : "IP"}: ${target}`); + }, unlockhelp: [`/unlock [username] - Unlocks the user. Requires: % @ * & ~`], forceglobalban: 'globalban', @@ -2123,19 +2170,6 @@ const commands = { unrangelock: 'unlockip', rangeunlock: 'unlockip', - unlockip: function (target, room, user) { - target = target.trim(); - if (!target) { - return this.parse('/help unbanip'); - } - if (!this.can('rangeban')) return false; - if (!Punishments.ips.has(target)) { - return this.errorReply(`${target} is not a locked/banned IP or IP range.`); - } - Punishments.ips.delete(target); - this.addModAction(`${user.name} unlocked the ${(target.charAt(target.length - 1) === '*' ? "IP range" : "IP")}: ${target}`); - this.modlog('UNRANGELOCK', null, target); - }, /********************************************************* * Moderating: Other diff --git a/chat-plugins/info.js b/chat-plugins/info.js index 2af689b8bd..1a15cc5b1e 100644 --- a/chat-plugins/info.js +++ b/chat-plugins/info.js @@ -84,16 +84,24 @@ const commands = { } buf += '
'; if (user.can('alts', targetUser) || user.can('alts') && user === targetUser) { - let prevNames = Object.keys(targetUser.prevNames).join(", "); + let prevNames = Object.keys(targetUser.prevNames).map(userid => { + const punishment = Punishments.userids.get(userid); + return userid + (punishment ? ` (${Punishments.punishmentTypes.get(punishment[0]) || 'punished'}${punishment[1] !== targetUser.userid ? ` as ${punishment[1]}` : ''})` : ''); + }).join(", "); if (prevNames) buf += Chat.html`
Previous names: ${prevNames}`; for (const targetAlt of targetUser.getAltUsers(true)) { if (!targetAlt.named && !targetAlt.connected) continue; if (targetAlt.group === '~' && user.group !== '~') continue; - buf += Chat.html`
Alt: ${targetAlt.name}`; + const punishment = Punishments.userids.get(targetAlt.userid); + const punishMsg = punishment ? ` (${Punishments.punishmentTypes.get(punishment[0]) || 'punished'}${punishment[1] !== targetAlt.userid ? ` as ${punishment[1]}` : ''})` : ''; + buf += Chat.html`
Alt: ${targetAlt.name}${punishMsg}`; if (!targetAlt.connected) buf += ` (offline)`; - prevNames = Object.keys(targetAlt.prevNames).join(", "); + prevNames = Object.keys(targetAlt.prevNames).map(userid => { + const punishment = Punishments.userids.get(userid); + return userid + (punishment ? ` (${Punishments.punishmentTypes.get(punishment[0]) || 'punished'}${punishment[1] !== targetAlt.userid ? ` as ${punishment[1]}` : ''})` : ''); + }).join(", "); if (prevNames) buf += `
Previous names: ${prevNames}`; } if (targetUser.namelocked) {