2020-07-04 12:23:10 +02:00
|
|
|
const { Infraction } = require('../interfaces/');
|
|
|
|
const escapeRegex = require('escape-string-regexp');
|
|
|
|
|
2021-06-18 07:54:07 +02:00
|
|
|
const { Util, KillItWithFire } = require('../../../util/');
|
2021-06-11 07:39:40 +02:00
|
|
|
|
2020-07-04 12:23:10 +02:00
|
|
|
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"]
|
|
|
|
};
|
|
|
|
|
2020-07-30 14:41:17 +02:00
|
|
|
class NicknameInfraction extends Infraction {
|
2020-07-04 12:23:10 +02:00
|
|
|
|
2021-06-16 06:49:17 +02:00
|
|
|
static type = 'NICKNAME';
|
|
|
|
|
2020-07-04 12:23:10 +02:00
|
|
|
constructor(client, opts = {}) {
|
|
|
|
|
|
|
|
super(client, {
|
2021-05-10 22:09:03 +02:00
|
|
|
targetType: 'USER',
|
2021-06-16 08:50:01 +02:00
|
|
|
type: opts.type,
|
2020-07-04 12:23:10 +02:00
|
|
|
executor: opts.executor.user,
|
|
|
|
target: opts.target.user,
|
2021-05-10 22:09:03 +02:00
|
|
|
reason: opts.reason,
|
2020-07-04 12:23:10 +02:00
|
|
|
guild: opts.guild,
|
2021-06-18 02:11:55 +02:00
|
|
|
arguments: opts.arguments,
|
2020-07-04 12:23:10 +02:00
|
|
|
channel: opts.channel,
|
|
|
|
silent: opts.silent,
|
2020-07-16 09:54:39 +02:00
|
|
|
points: opts.points,
|
|
|
|
expiration: opts.expiration,
|
2021-06-26 08:42:57 +02:00
|
|
|
data: opts.data,
|
|
|
|
hyperlink: opts.hyperlink
|
2020-07-04 12:23:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.client = client;
|
|
|
|
this.member = opts.target;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async execute() {
|
2021-06-11 07:39:40 +02:00
|
|
|
let { dehoist } = this.data; //eslint-disable-line prefer-const
|
2020-07-04 12:23:10 +02:00
|
|
|
|
2021-06-11 07:39:40 +02:00
|
|
|
this.data.oldName = this.member.nickname || this.member.user.username;
|
2020-07-04 12:23:10 +02:00
|
|
|
if(dehoist) {
|
2021-06-18 07:54:07 +02:00
|
|
|
let name = this._killName(this.data.oldName);
|
|
|
|
if(name === this.data.oldName) return this._fail('C_NICKNAME_NOCHARACTERS');
|
|
|
|
|
|
|
|
if(name.length === 0) name = this._generateName();
|
|
|
|
this.data.name = name;
|
2020-07-04 12:23:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2021-06-11 07:39:40 +02:00
|
|
|
this.member.setNickname(this.data.name, this._reason);
|
2020-07-04 12:23:10 +02:00
|
|
|
} 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];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-18 07:54:07 +02:00
|
|
|
_killName(name) {
|
|
|
|
for(const [key, value] of Object.entries(KillItWithFire)) {
|
|
|
|
name = name.replace(new RegExp(value, 'gui'), key);
|
|
|
|
}
|
|
|
|
const Regex = new RegExp(`(^(?:${Constants.Characters.map((c) => escapeRegex(c)).join('|')}*)*)`, 'gui');
|
|
|
|
name = name.replace(Regex, '');
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2020-07-29 21:01:39 +02:00
|
|
|
async verify() {
|
2020-07-20 00:42:21 +02:00
|
|
|
|
2020-07-16 09:54:39 +02:00
|
|
|
const { highest } = this.member.roles;
|
|
|
|
if(highest.comparePositionTo(this.guild.me.roles.highest) > 0) {
|
|
|
|
return this._fail('C_NICKNAME_MISSINGPERMISSIONS');
|
|
|
|
}
|
|
|
|
|
|
|
|
return super._verify();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-11 07:39:40 +02:00
|
|
|
description() {
|
|
|
|
return `\n${this.guild.format('INFRACTION_DESCRIPTIONNICKNAME', { old: Util.escapeMarkdown(this.data.oldName), new: Util.escapeMarkdown(this.data.name) })}`;
|
|
|
|
}
|
|
|
|
|
2020-07-04 12:23:10 +02:00
|
|
|
}
|
|
|
|
|
2020-07-30 14:41:17 +02:00
|
|
|
module.exports = NicknameInfraction;
|