diff options
Diffstat (limited to 'src/commands/admin')
-rw-r--r-- | src/commands/admin/channelPermissions.ts | 80 | ||||
-rw-r--r-- | src/commands/admin/roleAll.ts | 32 |
2 files changed, 84 insertions, 28 deletions
diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index bae1133..dc35c87 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -1,5 +1,5 @@ -import { BushCommand, BushMessage, ButtonPaginator } from '@lib'; -import { GuildMember, MessageEmbed, Role } from 'discord.js'; +import { BushCommand, BushMessage, BushSlashMessage, ButtonPaginator } from '@lib'; +import { GuildMember, MessageEmbed, PermissionString, Role } from 'discord.js'; export default class ChannelPermissionsCommand extends BushCommand { public constructor() { @@ -8,9 +8,9 @@ export default class ChannelPermissionsCommand extends BushCommand { category: 'admin', typing: true, description: { - content: 'Use to mass change the channel ', - usage: 'ChannelPerms <role_id> <perm> <state>', - examples: ['ChannelPerms 783794633129197589 read_messages deny'] + content: 'Use to mass change the channel permissions.', + usage: ['channel-perms <role_id> <perm> <state>'], + examples: ['channel-perms 783794633129197589 read_messages deny'] }, args: [ { @@ -18,7 +18,7 @@ export default class ChannelPermissionsCommand extends BushCommand { customType: util.arg.union('member', 'member'), prompt: { start: 'What user/role would you like to change?', - retry: 'Invalid response. What user/role would you like to change?' + retry: '{error} Choose a valid user/role to change.' } }, { @@ -44,39 +44,79 @@ export default class ChannelPermissionsCommand extends BushCommand { ], clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_CHANNELS']), userPermissions: ['ADMINISTRATOR'], - channel: 'guild' + channel: 'guild', + slash: true, + slashOptions: [ + { + name: 'target', + description: 'What user/role would you like to change?', + type: 'MENTIONABLE', + required: true + }, + { + name: 'permission', + description: 'What permission would you like to change?', + type: 'STRING', + required: true + }, + { + name: 'state', + description: 'What should that permission be set to?', + type: 'STRING', + choices: [ + { + name: 'Enabled', + value: 'true' + }, + { + name: 'Disabled', + value: 'false' + }, + { + name: 'Neutral', + value: 'neutral' + } + ], + required: true + } + ] }); } public override async exec( - message: BushMessage, - { - target, - permission, - state - }: { + message: BushMessage | BushSlashMessage, + args: { target: Role | GuildMember; - permission: string; + permission: PermissionString | string; state: 'true' | 'false' | 'neutral'; } - ): Promise<unknown> { + ) { + if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); + if (!message.member!.permissions.has('ADMINISTRATOR') && !message.member!.user.isOwner()) + return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); + if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); + + const permission: PermissionString = message.util.isSlashMessage(message) + ? await util.arg.cast('permission', message, args.permission) + : args.permission; + if (!permission) return await message.util.reply(`${util.emojis.error} Invalid permission.`); const failedChannels = []; - for (const channel of message.guild!.channels.cache.values()) { + for (const [, channel] of message.guild!.channels.cache) { try { if (channel.isThread()) return; if (channel.permissionsLocked) return; - const permissionState = state === 'true' ? true : state === 'false' ? false : null; + const permissionState = args.state === 'true' ? true : args.state === 'false' ? false : null; await channel.permissionOverwrites.create( - target.id, + args.target.id, { [permission]: permissionState }, { reason: 'Changing overwrites for mass channel perms command' } ); } catch (e) { - client.console.debug(e.stack); + void client.console.error('channelPermissions', e.stack); failedChannels.push(channel); } } - const failure = failedChannels.map((e) => `<#${e.id}>`).join(' '); + const failure = failedChannels.map((c) => `<#${c.id}>`).join(' '); if (failure.length > 2000) { const paginate: MessageEmbed[] = []; for (let i = 0; i < failure.length; i += 4000) { diff --git a/src/commands/admin/roleAll.ts b/src/commands/admin/roleAll.ts index 73369fc..1e67874 100644 --- a/src/commands/admin/roleAll.ts +++ b/src/commands/admin/roleAll.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, BushMessage } from '@lib'; +import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage } from '@lib'; import { GuildMember, Role } from 'discord.js'; export default class RoleAllCommand extends BushCommand { @@ -8,8 +8,8 @@ export default class RoleAllCommand extends BushCommand { category: 'admin', description: { content: 'Give a role to every member on the server.', - usage: 'roleAll <role> [another role]... [--bots]', - examples: ['roleAll 783794633129197589 --bots'] + usage: ['role-all <role> [--bots]'], + examples: ['role-all 783794633129197589 --bots'] }, args: [ { @@ -30,14 +30,30 @@ export default class RoleAllCommand extends BushCommand { channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_ROLES']), userPermissions: ['ADMINISTRATOR'], - typing: true + typing: true, + slash: true, + slashOptions: [ + { + name: 'role', + description: 'What role would you like to give to every member on the server?', + type: 'ROLE', + required: true + }, + { + name: 'bots', + description: 'Would you like to also give roles to bots?', + type: 'BOOLEAN', + required: false + } + ] }); } - public override async exec(message: BushMessage, args: { role: Role; bot?: boolean }): Promise<unknown> { + public override async exec(message: BushMessage | BushSlashMessage, args: { role: Role; bots: boolean }) { if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); if (!message.member!.permissions.has('ADMINISTRATOR') && !message.member!.user.isOwner()) return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); + if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); if (args.role.comparePositionTo(message.guild.me!.roles.highest) >= 0 && !args.role) { return await message.util.reply(`${util.emojis.error} I cannot assign a role higher or equal to my highest role.`); @@ -47,7 +63,7 @@ export default class RoleAllCommand extends BushCommand { members = members.filter((member: GuildMember) => { try { - if (member.user.bot && !args.bot) return false; + if (member.user.bot && !args.bots) return false; if (member.roles.cache.has(args.role.id)) return false; } catch { return false; @@ -66,7 +82,7 @@ export default class RoleAllCommand extends BushCommand { if (!failed.length) { await message.util.reply({ content: `${util.emojis.success} Finished adding <@&${args.role.id}> to **${members.size}** member${ - members.size ? 's' : '' + members.size > 1 ? 's' : '' }.`, allowedMentions: AllowedMentions.none() }); @@ -74,7 +90,7 @@ export default class RoleAllCommand extends BushCommand { const array = [...members.values()]; await message.util.reply({ content: `${util.emojis.warn} Finished adding <@&${args.role.id}> to **${members.size - failed.length}** member${ - members.size - failed.length ? 's' : '' + members.size - failed.length > 1 ? 's' : '' }! Failed members:\n${failed.map((_, index) => `<@${array[index].id}>`).join(' ')}`, allowedMentions: AllowedMentions.none() }); |