define flag options

This commit is contained in:
Erik 2022-07-26 20:42:36 +03:00
parent 9b6c792514
commit 58ea955cc5
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
19 changed files with 86 additions and 46 deletions

View File

@ -5,6 +5,7 @@ class AdministrationModule extends SettingsCommand {
constructor(client) {
super(client, {
name: 'administration',
aliases: ['admin'],
description: 'Configure the administrative settings',
module: 'administration'
});

View File

@ -39,7 +39,8 @@ class ImportCommand extends SlashCommand {
}, {
name: 'overwrite',
description: 'Whether any existing logs should be overwritten by the imports. By default new ones are bumped',
type: 'BOOLEAN'
type: 'BOOLEAN',
flag: true, valueOptional: true, defaultValue: true
}]
}],
clientPermissions: ['ManageWebhooks']

View File

@ -46,7 +46,7 @@ class ModstatsCommand extends SlashCommand {
const data = await this.client.mongodb.infractions.find(query, { projection: { executor: 1, type: 1 } });
for (const log of data) {
if (log.executor === guild.members.me.id) continue;
if (log.executor === this.client.user.id) continue;
if (!result[log.executor]) {
const user = await this.client.resolveUser(log.executor);
result[log.executor] = { name: user.tag };

View File

@ -27,7 +27,8 @@ class PermissionsCommand extends SlashCommand {
name: 'channel',
description: 'The channel(s) in which this permission is granted to user or role',
type: 'TEXT_CHANNELS',
dependsOn: ['permission']
dependsOn: ['permission'],
flag: true
},
{
name: 'role',
@ -64,6 +65,7 @@ class PermissionsCommand extends SlashCommand {
name: 'channel',
description: 'The channel(s) to reset',
type: 'TEXT_CHANNELS',
flag: true
},
{
name: 'role',

View File

@ -1,4 +1,4 @@
const { SlashCommand, CommandOption } = require("../../../interfaces");
const { SlashCommand } = require("../../../interfaces");
const { Util } = require('../../../../utilities');
class SettingsCommand extends SlashCommand {
@ -10,11 +10,11 @@ class SettingsCommand extends SlashCommand {
description: 'View settings',
options: [
// Probably add reset options here too
new CommandOption({
{
name: 'list',
description: 'List available settings',
type: 'SUB_COMMAND'
})
}
],
memberPermissions: ['ManageGuild']
});

View File

@ -17,7 +17,8 @@ class StatsCommand extends SlashCommand {
name: 'log',
type: 'BOOLEAN',
types: ['FLAG'],
description: 'Logs the output in the console.'
description: 'Logs the output in the console.',
flag: true, valueOptional: true, defaultValue: true
}
],
clientPermissions: ['SendMessages', 'EmbedLinks'],

View File

@ -18,7 +18,8 @@ class BanCommand extends ModerationCommand {
type: 'INTEGER',
description: 'How many days worth of messages to prune',
minimum: 1,
maximum: 7
maximum: 7,
flag: true
}, {
name: 'users',
type: 'USERS',

View File

@ -23,7 +23,8 @@ class CaseCommand extends SlashCommand {
'Print out more detailed information about the case',
'List changes to the case'
],
depeondsOn: ['id']
depeondsOn: ['id'],
flag: true, valueOptional: true, defaultValue: true
}],
guildOnly: true,
showUsage: true,

View File

@ -24,14 +24,15 @@ class EditCommand extends SlashCommand {
name: 'points',
type: 'INTEGER',
description: 'New point value for case',
minimum: 0, maximum: 100
minimum: 0, maximum: 100, flag: true
}, {
name: ['expiration', 'duration'],
type: 'TIME',
description: [
'New expiration for points, starts from the time the infraction was issued',
'Duration if the infraction is timed'
]
],
flag: true
}]
});
}

View File

@ -24,7 +24,8 @@ class HistoryCommand extends SlashCommand {
options: [{
name: ['before', 'after'],
type: 'DATE',
description: 'Filter by a date, must be in YYYY/MM/DD or YYYY-MM-DD format'
description: 'Filter by a date, must be in YYYY/MM/DD or YYYY-MM-DD format',
flag: true
}, {
name: ['verbose', 'oldest', 'export', 'private'],
description: [
@ -33,26 +34,31 @@ class HistoryCommand extends SlashCommand {
'Export the list of infractions',
'DM the command response'
],
type: 'BOOLEAN'
type: 'BOOLEAN',
flag: true, valueOptional: true, defaultValue: true
}, {
name: 'type',
description: 'Filter infractions by type',
choices: Infractions.map((inf) => {
return { name: inf.toLowerCase(), value: inf };
})
}),
flag: true
}, {
name: ['pagesize', 'page'],
description: ['Amount of infractions to list per page', 'Page to select'],
type: 'INTEGER',
minimum: 1
minimum: 1,
flag: true
}, {
name: ['user', 'moderator'], //
description: ['User whose infractions to query, overrides channel if both are given', 'Query by moderator'],
type: 'USER'
type: 'USER',
flag: true
}, {
name: 'channel',
description: 'Infractions done on channels, e.g. slowmode, lockdown',
type: 'TEXT_CHANNEL'
type: 'TEXT_CHANNEL',
flag: true
}]
});
}
@ -95,6 +101,7 @@ class HistoryCommand extends SlashCommand {
limit: pageSize
});
const me = await guild.resolveMember(this.client.user);
const embed = {
author: {
name: 'Infraction History',
@ -104,7 +111,7 @@ class HistoryCommand extends SlashCommand {
footer: {
text: `• Page ${_page}/${maxPage} | ${resultsAmt} Results`
},
color: invoker.guild.members.me.roles.highest.color
color: me.roles.highest.color
};
if (invoker.guild._settings.modpoints.enabled) {

View File

@ -27,8 +27,9 @@ class MuteCommand extends ModerationCommand {
const { guild } = interaction;
const settings = await guild.settings();
const { type } = settings.mute;
if (type === 3 && !guild.members.me.permissions.has('ModerateMembers')) throw new CommandError(interaction, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', params: { command: this.name, missing: 'ModerateMembers' } });
else if (!guild.members.me.permissions.has('ManageRoles')) throw new CommandError(interaction, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', params: { command: this.name, missing: 'ManageRoles' } });
const me = await guild.resolveMember(this.client.user);
if (type === 3 && !me.permissions.has('ModerateMembers')) throw new CommandError(interaction, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', params: { command: this.name, missing: 'ModerateMembers' } });
else if (!me.permissions.has('ManageRoles')) throw new CommandError(interaction, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', params: { command: this.name, missing: 'ManageRoles' } });
return this.client.moderationManager.handleInfraction(Mute, interaction, {
targets: users.value,

View File

@ -12,7 +12,7 @@ class NicknameCommand extends ModerationCommand {
name: 'name',
description: 'The new nickname to give',
type: 'STRING',
required: true
required: true, flag: true
}],
memberPermissions: ['ManageNicknames'],
clientPermissions: ['ManageNicknames'],

View File

@ -1,6 +1,10 @@
const { ModerationCommand, CommandError } = require('../../../interfaces');
const { Prune } = require('../../../infractions');
const flag = true,
valueOptional = true,
defaultValue = true;
class PruneCommand extends ModerationCommand {
constructor(client) {
@ -26,56 +30,69 @@ class PruneCommand extends ModerationCommand {
}, {
name: 'silent',
type: 'BOOLEAN',
description: 'Prune quietly'
description: 'Prune quietly',
flag, valueOptional, defaultValue
}, {
name: 'bots',
type: 'BOOLEAN',
description: 'Prune messages from bots'
description: 'Prune messages from bots',
flag, valueOptional, defaultValue
}, {
name: 'humans',
type: 'BOOLEAN',
description: 'Prune messages from humans'
description: 'Prune messages from humans',
flag, valueOptional, defaultValue
}, {
name: 'contains',
type: 'STRING',
description: 'Text to look for messages by'
description: 'Text to look for messages by',
flag
}, {
name: 'startswith',
type: 'STRING',
description: 'Text the messages to delete start with'
description: 'Text the messages to delete start with',
flag
}, {
name: 'endswith',
type: 'STRING',
description: 'Text the messages to delete end with'
description: 'Text the messages to delete end with',
flag
}, {
name: 'text',
type: 'BOOLEAN',
description: 'Only delete messages containing text'
description: 'Only delete messages containing text',
flag, valueOptional, defaultValue
}, {
name: 'invites',
type: 'BOOLEAN',
description: 'Delete messages containing invites'
description: 'Delete messages containing invites',
flag, valueOptional, defaultValue
}, {
name: 'links',
type: 'BOOLEAN',
description: 'Delete messages containing links'
description: 'Delete messages containing links',
flag, valueOptional, defaultValue
}, {
name: 'emojis',
type: 'BOOLEAN',
description: 'Prune messages cotaining emojis'
description: 'Prune messages cotaining emojis',
flag, valueOptional, defaultValue
}, {
name: 'after',
type: 'STRING',
description: 'ID of message after which to start deleting'
description: 'ID of message after which to start deleting',
flag
}, {
name: 'before',
type: 'STRING',
description: 'ID of message before which to start deleting'
description: 'ID of message before which to start deleting',
flag
}, {
name: 'logic',
// type: '',
choices: [{ name: 'AND', value: 'AND' }, { name: 'OR', value: 'OR' }],
description: 'Logic type to use for combining options'
description: 'Logic type to use for combining options',
flag
}, {
name: 'reason',
type: 'STRING',

View File

@ -22,7 +22,8 @@ class ResolveCommand extends SlashCommand {
}, {
name: 'notify',
description: 'Attempt to notify the user about the resolve, may not always be possible',
type: 'BOOLEAN'
type: 'BOOLEAN',
flag: true, valueOptional: true, defaultValue: true
}] // Potentially add another option to enable a range of cases
});
}

View File

@ -23,8 +23,9 @@ class UnmuteCommand extends ModerationCommand {
const { guild } = interaction;
const settings = await guild.settings();
const { type } = settings.mute;
if (type === 3 && !guild.members.me.permissions.has('ModerateMembers')) throw new CommandError(interaction, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', params: { command: this.name, missing: 'ModerateMembers' } });
else if (!guild.members.me.permissions.has('ManageRoles')) throw new CommandError(interaction, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', params: { command: this.name, missing: 'ManageRoles' } });
const me = await guild.resolveMember(this.client.user);
if (type === 3 && !me.permissions.has('ModerateMembers')) throw new CommandError(interaction, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', params: { command: this.name, missing: 'ModerateMembers' } });
else if (!me.permissions.has('ManageRoles')) throw new CommandError(interaction, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', params: { command: this.name, missing: 'ManageRoles' } });
return this.client.moderationManager.handleInfraction(Unmute, interaction, {
targets: users.value,

View File

@ -12,8 +12,9 @@ const { SlashCommand, Infraction } = require("../../../interfaces");
}
*/
class ResolveCommand extends SlashCommand {
class UnresolveCommand extends SlashCommand {
// TODO: make unresolving enact the infraction again
constructor(client) {
super(client, {
name: 'unresolve',
@ -50,4 +51,4 @@ class ResolveCommand extends SlashCommand {
}
module.exports = ResolveCommand;
module.exports = UnresolveCommand;

View File

@ -13,14 +13,16 @@ class AvatarCommand extends SlashCommand {
// type: 'INTEGER',
choices: [16, 32, 64, 128, 256, 512, 1024, 2048].map((i) => {
return { name: `${i}`, value: `${i}` };
})
}),
flag: true
}, {
name: 'format',
description: 'Image format',
// type: 'STRING'
choices: ['webp', 'png', 'jpeg', 'jpg', 'gif'].map((i) => {
return { name: i, value: i };
})
}),
flag: true
}, {
name: 'user',
description: 'Use this for the user\'s global avatar',
@ -28,7 +30,8 @@ class AvatarCommand extends SlashCommand {
}, {
name: 'member',
description: 'Use this for the user\'s server avatar',
type: 'MEMBER'
type: 'MEMBER',
flag: true
}]
});
}

View File

@ -57,7 +57,7 @@ class PollCommand extends SlashCommand {
const questions = [];
const _channel = channel?.value || invoker.channel;
const botMissing = _channel.permissionsFor(guild.members.me).missing(['SendMessages', 'EmbedLinks']);
const botMissing = _channel.permissionsFor(this.client.user).missing(['SendMessages', 'EmbedLinks']);
const userMissing = _channel.permissionsFor(member).missing(['SendMessages']);
if (botMissing.length) return invoker.editReply({ index: 'COMMAND_POLL_BOT_PERMS', params: { missing: botMissing.join(', '), channel: _channel.id } });
if (userMissing.length) return invoker.editReply({ index: 'COMMAND_POLL_USER_PERMS', params: { missing: userMissing.join(', '), channel: _channel.id } });
@ -65,10 +65,10 @@ class PollCommand extends SlashCommand {
for (let i = 0; i < choices.value; i++) {
const response = await invoker.promptMessage({
content: guild.format(`COMMAND_POLL_QUESTION${choices.value === 1 ? '' : 'S'}`, { number: i + 1 }) + '\n' + guild.format('COMMAND_POLL_ADDENDUM'),
time: 90, editReply: true
time: 90, editReply: invoker.replied
});
if (!response || !response.content) return invoker.editReply({ index: 'COMMAND_POLL_TIMEOUT' });
if(invoker.channel.permissionsFor(guild.members.me).has('ManageMessages')) await response.delete().catch(() => null);
if(invoker.channel.permissionsFor(this.client.user).has('ManageMessages')) await response.delete().catch(() => null);
const { content } = response;
if (content.toLowerCase() === 'stop') break;
if (content.toLowerCase() === 'cancel') return invoker.editReply({ index: 'GENERAL_CANCELLED' });

View File

@ -34,7 +34,8 @@ class SelfroleCommand extends SlashCommand {
const { guild, member } = invoker;
const { selfrole } = await guild.settings();
if (!selfrole.roles.length) return { index: 'COMMAND_SELFROLE_NONE', emoji: 'failure' };
const ownHighest = guild.members.me.roles.highest;
const me = await guild.resolveMemberr(this.client.user);
const ownHighest = me.roles.highest;
const memberRoles = member.roles.cache.map((r) => r.id);
const tooHigh = roles?.value.filter((r) => r.position > ownHighest.position);