define flag options

This commit is contained in:
Erik 2022-07-26 20:42:36 +03:00
parent 9b6c792514
commit 58ea955cc5
Signed by untrusted user: 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) { constructor(client) {
super(client, { super(client, {
name: 'administration', name: 'administration',
aliases: ['admin'],
description: 'Configure the administrative settings', description: 'Configure the administrative settings',
module: 'administration' module: 'administration'
}); });

View File

@ -39,7 +39,8 @@ class ImportCommand extends SlashCommand {
}, { }, {
name: 'overwrite', name: 'overwrite',
description: 'Whether any existing logs should be overwritten by the imports. By default new ones are bumped', 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'] 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 } }); const data = await this.client.mongodb.infractions.find(query, { projection: { executor: 1, type: 1 } });
for (const log of data) { 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]) { if (!result[log.executor]) {
const user = await this.client.resolveUser(log.executor); const user = await this.client.resolveUser(log.executor);
result[log.executor] = { name: user.tag }; result[log.executor] = { name: user.tag };

View File

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

View File

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

View File

@ -17,7 +17,8 @@ class StatsCommand extends SlashCommand {
name: 'log', name: 'log',
type: 'BOOLEAN', type: 'BOOLEAN',
types: ['FLAG'], 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'], clientPermissions: ['SendMessages', 'EmbedLinks'],

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,8 @@ class ResolveCommand extends SlashCommand {
}, { }, {
name: 'notify', name: 'notify',
description: 'Attempt to notify the user about the resolve, may not always be possible', 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 }] // Potentially add another option to enable a range of cases
}); });
} }

View File

@ -23,8 +23,9 @@ class UnmuteCommand extends ModerationCommand {
const { guild } = interaction; const { guild } = interaction;
const settings = await guild.settings(); const settings = await guild.settings();
const { type } = settings.mute; 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' } }); const me = await guild.resolveMember(this.client.user);
else if (!guild.members.me.permissions.has('ManageRoles')) throw new CommandError(interaction, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', params: { command: this.name, missing: 'ManageRoles' } }); 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, { return this.client.moderationManager.handleInfraction(Unmute, interaction, {
targets: users.value, 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) { constructor(client) {
super(client, { super(client, {
name: 'unresolve', 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', // type: 'INTEGER',
choices: [16, 32, 64, 128, 256, 512, 1024, 2048].map((i) => { choices: [16, 32, 64, 128, 256, 512, 1024, 2048].map((i) => {
return { name: `${i}`, value: `${i}` }; return { name: `${i}`, value: `${i}` };
}) }),
flag: true
}, { }, {
name: 'format', name: 'format',
description: 'Image format', description: 'Image format',
// type: 'STRING' // type: 'STRING'
choices: ['webp', 'png', 'jpeg', 'jpg', 'gif'].map((i) => { choices: ['webp', 'png', 'jpeg', 'jpg', 'gif'].map((i) => {
return { name: i, value: i }; return { name: i, value: i };
}) }),
flag: true
}, { }, {
name: 'user', name: 'user',
description: 'Use this for the user\'s global avatar', description: 'Use this for the user\'s global avatar',
@ -28,7 +30,8 @@ class AvatarCommand extends SlashCommand {
}, { }, {
name: 'member', name: 'member',
description: 'Use this for the user\'s server avatar', 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 questions = [];
const _channel = channel?.value || invoker.channel; 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']); 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 (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 } }); 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++) { for (let i = 0; i < choices.value; i++) {
const response = await invoker.promptMessage({ const response = await invoker.promptMessage({
content: guild.format(`COMMAND_POLL_QUESTION${choices.value === 1 ? '' : 'S'}`, { number: i + 1 }) + '\n' + guild.format('COMMAND_POLL_ADDENDUM'), 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 (!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; const { content } = response;
if (content.toLowerCase() === 'stop') break; if (content.toLowerCase() === 'stop') break;
if (content.toLowerCase() === 'cancel') return invoker.editReply({ index: 'GENERAL_CANCELLED' }); 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 { guild, member } = invoker;
const { selfrole } = await guild.settings(); const { selfrole } = await guild.settings();
if (!selfrole.roles.length) return { index: 'COMMAND_SELFROLE_NONE', emoji: 'failure' }; 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 memberRoles = member.roles.cache.map((r) => r.id);
const tooHigh = roles?.value.filter((r) => r.position > ownHighest.position); const tooHigh = roles?.value.filter((r) => r.position > ownHighest.position);