galactic-bot/structure/client/components/commands/administration/MassBan.js

152 lines
6.2 KiB
JavaScript
Raw Normal View History

const { Command } = require('../../../../interfaces/');
const { Ban } = require('../../../../moderation/infractions/');
class MassBanCommand extends Command {
constructor(client) {
super(client, {
name: 'massban',
module: 'administration',
2021-06-18 02:11:55 +02:00
usage: "<arguments..> [reason..]",
clientPermissions: ['BAN_MEMBERS'],
2021-06-18 02:11:55 +02:00
memberPermissions: ['MANAGE_GUILD', 'ADMINISTRATOR'],
aliases: [],
examples: [
2021-06-18 02:11:55 +02:00
"--accountage 1d raiding the server"
],
restricted: true,
2021-06-11 03:08:31 +02:00
archivable: false,
arguments: [
{
2021-06-18 02:11:55 +02:00
name: 'exact',
usage: '<text>',
type: 'STRING',
types: ['FLAG'],
required: true
},
{
name: 'contains',
aliases: ['includes'],
usage: '<text>',
type: 'STRING',
types: ['FLAG'],
required: true
},
{
2021-06-18 02:11:55 +02:00
name: 'startswith',
aliases: [
'starts',
'begins',
'beginswith'
],
usage: '<text>',
type: 'STRING',
types: ['FLAG'],
required: true
},
{
name: 'endswith',
aliases: ['ends'],
usage: '<text>',
type: 'STRING',
types: ['FLAG'],
required: true
},
{
name: 'accountage',
aliases: ['accage'],
type: 'TIME',
2021-06-18 02:11:55 +02:00
usage: '<time>',
types: ['FLAG'],
2021-06-18 02:11:55 +02:00
required: true
},
{
name: 'guildage',
aliases: ['serverage'],
type: 'TIME',
usage: '<time>',
2021-06-18 02:11:55 +02:00
types: ['FLAG'],
required: true
},
{
2021-06-18 02:11:55 +02:00
name: 'ignorecase',
type: 'BOOLEAN',
types: ['FLAG'],
default: true
},
{
2021-06-18 02:11:55 +02:00
name: 'or',
type: 'BOOLEAN',
types: ['FLAG'],
2021-06-18 02:11:55 +02:00
default: true
},
{
name: 'silent',
type: 'BOOLEAN',
types: ['FLAG'],
default: true
}
],
guildOnly: true,
showUsage: true,
throttling: {
usages: 2,
2021-06-18 02:11:55 +02:00
duration: 60
}
});
this.client = client;
}
2021-06-18 02:11:55 +02:00
async execute(message, { qParams, args }) {
// const requiredArguments = ['exact', 'contains', 'startswith', 'endswith', 'accountage', 'guildage'];
// if(!Object.keys(args).some((a) => requiredArguments.includes(a))) {
// return message.respond(message.format('C_MASSBAN_REQUIREDARGUMENTS'), {
// emoji: 'failure'
// });
// }
const members = await message.guild.members.fetch();
const filteredMembers = this._filterMembers(members, args);
if(filteredMembers.size === 0) {
return message.respond("Found nothing");
}
return message.respond(filteredMembers.map((m) => `${m.user.tag} (${m.user.id})`).join('\n'));
}
_filterMembers(members, a) {
const filters = {
AND: (m) => {
return (a.exact ? a.ignorecase ? a.exact.value.toLowerCase() === m.user.username.toLowerCase() : a.exact.value === m.user.username : true) //eslint-disable-line no-nested-ternary
&& (a.contains ? a.ignorecase ? m.user.username.toLowerCase().includes(a.contains.value.toLowerCase()) : m.user.username.includes(a.contains.value) : true) //eslint-disable-line no-nested-ternary
&& (a.startswith ? a.ignorecase ? m.user.username.toLowerCase().startsWith(a.startswith.value.toLowerCase()) : m.user.username.startsWith(a.startswith.value) : true) //eslint-disable-line no-nested-ternary
&& (a.endswith ? a.ignorecase ? m.user.username.toLowerCase().endsWith(a.endswith.value.toLowerCase()) : m.user.username.endsWith(a.endswith.value) : true) //eslint-disable-line no-nested-ternary
&& (a.accountage ? Math.floor((Date.now() - m.user.createdTimestamp)/1000) < a.accountage.value : true)
&& (a.guildage ? Math.floor((Date.now() - m.joinedTimestamp)/1000) < a.guildage.value : true);
},
OR: (m) => {
return (a.exact ? a.ignorecase ? a.exact.value.toLowerCase() === m.user.username.toLowerCase() : a.exact.value === m.user.username : false) //eslint-disable-line no-nested-ternary
|| (a.contains ? a.ignorecase ? m.user.username.toLowerCase().includes(a.contains.value.toLowerCase()) : m.user.username.includes(a.contains.value) : false) //eslint-disable-line no-nested-ternary
|| (a.startswith ? a.ignorecase ? m.user.username.toLowerCase().startsWith(a.startsWith.value.toLowerCase()) : m.user.username.startsWith(a.startswith.value) : false) //eslint-disable-line no-nested-ternary
|| (a.endswith ? a.ignorecase ? m.user.username.toLowerCase().endsWith(a.endswith.value.toLowerCase()) : m.user.username.endsWith(a.endswith.value) : false) //eslint-disable-line no-nested-ternary
|| (a.accountage ? Math.floor((Date.now() - m.user.createdTimestamp)/1000) < a.accountage.value : false)
|| (a.guildage ? Math.floor((Date.now() - m.joinedTimestamp)/1000) < a.guildage.value : false);
}
};
const method = a.or ? 'OR' : 'AND';
return members.filter((m) => {
return filters[method](m);
});
}
}
module.exports = MassBanCommand;