const { Infraction } = require('../interfaces/'); const escapeRegex = require('escape-string-regexp'); const { Util } = require('../../../util/'); const Constants = { Characters: ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '=', '+', '"', "'", '`', '\\', '/', '[', ']', '>', '<', '.'], RandomNames: ["Ashly Armistead", "Jenifer James", "Eleonora Espinosa", "Eleanore Ellerbee", "Marguerite Means", "Lore Lazar", "Cherilyn Calero", "Olevia Olvera", "Herman Horvat", "Elvin Elfrink", "Jennine Julian", "Pei Plude", "Kenisha Kirts", "Sherly Starbird", "Lashanda Louder", "Elizabeth Eakle", "Lyda Leard", "Penelope Petri", "Kimi Kissel", "Crista Crowe", "Mallory Mehta", "Bettina Bregman", "Marcie Moran", "James Jiles", "Clifton Capshaw", "Cher Curlee", "Brigid Bonier", "Lana Lehman", "Carletta Chalker", "Valene Viator", "Eugena Eder", "Samatha Shivers", "Hoyt Hard", "Karena King", "Tiffani Trott", "Joye Jeremiah", "Emely Espino", "Rowena Rowan", "Gillian Godbey", "Hailey Huggard", "Lillian Lander", "Shani Szabo", "Liberty Lamorte", "Tomika Thrift", "Garrett Grogan", "Vallie Valazquez", "Shin Secor", "Deangelo Divito", "Kacy Kimball", "Norris Northway", "Evelia Ernest", "Horacio Huey", "Christen Cyr", "Jada Janus", "Vanita Valero", "Abdul Addario", "Daniell Dingle", "Tangela Trull", "Jeanmarie Jimenez", "Georgia Gourlay", "Valery Vergara", "Chasidy Conrad", "Marlena Malin", "Kristeen Kesselman", "Jo Jeffries", "Terina Tworek", "Geri Gilbert", "Phuong Pratte", "Juanita Jess", "Audrea Ammon", "Shakita Stalter", "Rosamond Reese", "Shani Solorio", "Archie Augustyn", "Bridgett Behrman", "Susann Schmaltz", "Edgardo Engman", "Valerie Vice", "Cheyenne Claeys", "Kristina Kastner", "Lanita Labrum", "Kai Knick", "Lucien Lee", "Tameika Turley", "Octavia Obermiller", "Kia Kravitz", "Justina Jury", "Cortney Coppa", "Johnathan Joshi", "Arden Alphin", "Francis Feinberg", "Sal Suits", "Myles Marden", "Emmitt Engelmann", "Tara Tibbits", "Su Sprowl", "Isadora Ingrassia", "Janell Jarrard", "Kenyatta Kenley", "Mabelle Mccrady"] }; const Regex = new RegExp(`(^(?:${Constants.Characters.map((c) => escapeRegex(c)).join('|')}*)*)(.*)`, 'gui'); class NicknameInfraction extends Infraction { constructor(client, opts = {}) { super(client, { type: 'NICKNAME', targetType: 'USER', executor: opts.executor.user, target: opts.target.user, reason: opts.reason, guild: opts.guild, channel: opts.channel, silent: opts.silent, points: opts.points, expiration: opts.expiration, data: opts.data }); this.client = client; this.member = opts.target; } async execute() { let { dehoist } = this.data; //eslint-disable-line prefer-const this.data.oldName = this.member.nickname || this.member.user.username; if(dehoist) { console.log(Regex); console.log(this.data.oldName); const [, removed, fixed] = Regex.exec(this.data.oldName); console.log("Succeeded"); if(!removed) return this._fail('C_NICKNAME_NOCHARACTERS'); if(fixed) { this.data.name = fixed; } else { this.data.name = this._generateName(); } } try { this.member.setNickname(this.data.name, this._reason); } catch(e) { return this._fail('INFRACTION_ERROR'); } await this.handle(); return this._succeed(); } _generateName() { const random = Math.floor(Math.random()*Constants.RandomNames.length); return Constants.RandomNames[random]; } async verify() { const { highest } = this.member.roles; if(highest.comparePositionTo(this.guild.me.roles.highest) > 0) { return this._fail('C_NICKNAME_MISSINGPERMISSIONS'); } return super._verify(); } description() { return `\n${this.guild.format('INFRACTION_DESCRIPTIONNICKNAME', { old: Util.escapeMarkdown(this.data.oldName), new: Util.escapeMarkdown(this.data.name) })}`; } } module.exports = NicknameInfraction;