From 58ea955cc507e7807723b8aab7450a68442bad6c Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 26 Jul 2022 20:42:36 +0300 Subject: [PATCH] define flag options --- .../commands/administration/Administration.js | 1 + .../commands/administration/Import.js | 3 +- .../commands/administration/Modstats.js | 2 +- .../commands/administration/Permissions.js | 4 +- .../commands/administration/Settings.js | 6 +-- .../components/commands/developer/Stats.js | 3 +- .../components/commands/moderation/Ban.js | 3 +- .../components/commands/moderation/Case.js | 3 +- .../components/commands/moderation/Edit.js | 5 ++- .../components/commands/moderation/History.js | 21 ++++++--- .../components/commands/moderation/Mute.js | 5 ++- .../commands/moderation/Nickname.js | 2 +- .../components/commands/moderation/Prune.js | 43 +++++++++++++------ .../components/commands/moderation/Resolve.js | 3 +- .../components/commands/moderation/Unmute.js | 5 ++- .../commands/moderation/Unresolve.js | 5 ++- .../components/commands/utility/Avatar.js | 9 ++-- .../components/commands/utility/Poll.js | 6 +-- .../components/commands/utility/Selfrole.js | 3 +- 19 files changed, 86 insertions(+), 46 deletions(-) diff --git a/src/structure/components/commands/administration/Administration.js b/src/structure/components/commands/administration/Administration.js index 36bf678..fe7d977 100644 --- a/src/structure/components/commands/administration/Administration.js +++ b/src/structure/components/commands/administration/Administration.js @@ -5,6 +5,7 @@ class AdministrationModule extends SettingsCommand { constructor(client) { super(client, { name: 'administration', + aliases: ['admin'], description: 'Configure the administrative settings', module: 'administration' }); diff --git a/src/structure/components/commands/administration/Import.js b/src/structure/components/commands/administration/Import.js index a657e9f..bb1917b 100644 --- a/src/structure/components/commands/administration/Import.js +++ b/src/structure/components/commands/administration/Import.js @@ -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'] diff --git a/src/structure/components/commands/administration/Modstats.js b/src/structure/components/commands/administration/Modstats.js index b73bad3..156487d 100644 --- a/src/structure/components/commands/administration/Modstats.js +++ b/src/structure/components/commands/administration/Modstats.js @@ -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 }; diff --git a/src/structure/components/commands/administration/Permissions.js b/src/structure/components/commands/administration/Permissions.js index eecb64b..24ac6df 100644 --- a/src/structure/components/commands/administration/Permissions.js +++ b/src/structure/components/commands/administration/Permissions.js @@ -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', diff --git a/src/structure/components/commands/administration/Settings.js b/src/structure/components/commands/administration/Settings.js index 9ef32de..0e4c4a1 100644 --- a/src/structure/components/commands/administration/Settings.js +++ b/src/structure/components/commands/administration/Settings.js @@ -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'] }); diff --git a/src/structure/components/commands/developer/Stats.js b/src/structure/components/commands/developer/Stats.js index 4cfaa43..9ebc1a5 100644 --- a/src/structure/components/commands/developer/Stats.js +++ b/src/structure/components/commands/developer/Stats.js @@ -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'], diff --git a/src/structure/components/commands/moderation/Ban.js b/src/structure/components/commands/moderation/Ban.js index 0748166..1df0e06 100644 --- a/src/structure/components/commands/moderation/Ban.js +++ b/src/structure/components/commands/moderation/Ban.js @@ -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', diff --git a/src/structure/components/commands/moderation/Case.js b/src/structure/components/commands/moderation/Case.js index ad1aa14..439eeee 100644 --- a/src/structure/components/commands/moderation/Case.js +++ b/src/structure/components/commands/moderation/Case.js @@ -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, diff --git a/src/structure/components/commands/moderation/Edit.js b/src/structure/components/commands/moderation/Edit.js index 3133dcb..eb47fd0 100644 --- a/src/structure/components/commands/moderation/Edit.js +++ b/src/structure/components/commands/moderation/Edit.js @@ -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 }] }); } diff --git a/src/structure/components/commands/moderation/History.js b/src/structure/components/commands/moderation/History.js index 96225a7..d433598 100644 --- a/src/structure/components/commands/moderation/History.js +++ b/src/structure/components/commands/moderation/History.js @@ -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) { diff --git a/src/structure/components/commands/moderation/Mute.js b/src/structure/components/commands/moderation/Mute.js index 7f78540..c0848e8 100644 --- a/src/structure/components/commands/moderation/Mute.js +++ b/src/structure/components/commands/moderation/Mute.js @@ -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, diff --git a/src/structure/components/commands/moderation/Nickname.js b/src/structure/components/commands/moderation/Nickname.js index 5d52dc5..f015335 100644 --- a/src/structure/components/commands/moderation/Nickname.js +++ b/src/structure/components/commands/moderation/Nickname.js @@ -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'], diff --git a/src/structure/components/commands/moderation/Prune.js b/src/structure/components/commands/moderation/Prune.js index 10530fb..d3f4ffb 100644 --- a/src/structure/components/commands/moderation/Prune.js +++ b/src/structure/components/commands/moderation/Prune.js @@ -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', diff --git a/src/structure/components/commands/moderation/Resolve.js b/src/structure/components/commands/moderation/Resolve.js index f38bec7..1d988f7 100644 --- a/src/structure/components/commands/moderation/Resolve.js +++ b/src/structure/components/commands/moderation/Resolve.js @@ -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 }); } diff --git a/src/structure/components/commands/moderation/Unmute.js b/src/structure/components/commands/moderation/Unmute.js index 0eae2b8..b55a09c 100644 --- a/src/structure/components/commands/moderation/Unmute.js +++ b/src/structure/components/commands/moderation/Unmute.js @@ -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, diff --git a/src/structure/components/commands/moderation/Unresolve.js b/src/structure/components/commands/moderation/Unresolve.js index e1a9373..49917a9 100644 --- a/src/structure/components/commands/moderation/Unresolve.js +++ b/src/structure/components/commands/moderation/Unresolve.js @@ -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; \ No newline at end of file +module.exports = UnresolveCommand; \ No newline at end of file diff --git a/src/structure/components/commands/utility/Avatar.js b/src/structure/components/commands/utility/Avatar.js index 9d3c49f..53404dc 100644 --- a/src/structure/components/commands/utility/Avatar.js +++ b/src/structure/components/commands/utility/Avatar.js @@ -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 }] }); } diff --git a/src/structure/components/commands/utility/Poll.js b/src/structure/components/commands/utility/Poll.js index 25236a9..6cf15a9 100644 --- a/src/structure/components/commands/utility/Poll.js +++ b/src/structure/components/commands/utility/Poll.js @@ -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' }); diff --git a/src/structure/components/commands/utility/Selfrole.js b/src/structure/components/commands/utility/Selfrole.js index 11d4c63..998d27f 100644 --- a/src/structure/components/commands/utility/Selfrole.js +++ b/src/structure/components/commands/utility/Selfrole.js @@ -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);