From e3e72ce48396450fd63f0e40ea552838fcee59ba Mon Sep 17 00:00:00 2001 From: smyalygames Date: Tue, 28 Feb 2023 02:44:32 +0000 Subject: [PATCH] feat(arabot): add deferred replies --- src/commands/coordinators/moveall.ts | 30 ++++-------- src/commands/coordinators/private.ts | 48 ++++++------------- src/commands/mod/ban/ban.ts | 4 +- src/commands/mod/ban/tempBan.ts | 2 + src/commands/mod/ban/unban.ts | 2 + src/commands/mod/restriction/restrict.ts | 2 + .../mod/restriction/restrictTolerance.ts | 3 +- src/commands/mod/restriction/restrictTools.ts | 33 ++++--------- src/commands/mod/restriction/unrestrict.ts | 2 + 9 files changed, 47 insertions(+), 79 deletions(-) diff --git a/src/commands/coordinators/moveall.ts b/src/commands/coordinators/moveall.ts index 62786f1..98d8dc9 100644 --- a/src/commands/coordinators/moveall.ts +++ b/src/commands/coordinators/moveall.ts @@ -57,31 +57,27 @@ export class MoveAllCommand extends Command { const { member } = interaction; const { guild } = interaction; + await interaction.deferReply({ ephemeral: true }); + if (channel.type !== ChannelType.GuildVoice && channel.type !== ChannelType.GuildStageVoice) { - await interaction.reply({ + await interaction.editReply({ content: 'The channel you provided is not a voice channel!', - ephemeral: true, - fetchReply: true, }); return; } // Checks if all the variables are of the right type if (guild === null) { - await interaction.reply({ + await interaction.editReply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, }); return; } if (member === null) { - await interaction.reply({ + await interaction.editReply({ content: 'Error fetching your user', - ephemeral: true, - fetchReply: true, }); return; } @@ -89,19 +85,15 @@ export class MoveAllCommand extends Command { const mod = guild.members.cache.get(member.user.id); if (mod === undefined) { - await interaction.reply({ + await interaction.editReply({ content: 'Error fetching user from guild', - ephemeral: true, - fetchReply: true, }); return; } if (mod.voice.channelId === null) { - await interaction.reply({ + await interaction.editReply({ content: 'You need to be in a voice channel to run this command!', - ephemeral: true, - fetchReply: true, }); return; } @@ -110,10 +102,8 @@ export class MoveAllCommand extends Command { if (voice === undefined || !voice.isVoiceBased()) { - await interaction.reply({ + await interaction.editReply({ content: 'Error fetching your current voice channel!', - ephemeral: true, - fetchReply: true, }); return; } @@ -122,10 +112,8 @@ export class MoveAllCommand extends Command { memberVC.voice.setChannel(channel.id); }); - await interaction.reply({ + await interaction.editReply({ content: `Successfully moved ${voice.members.size} members to <#${channel.id}>!`, - ephemeral: true, - fetchReply: true, }); } diff --git a/src/commands/coordinators/private.ts b/src/commands/coordinators/private.ts index 2395cb1..7eed885 100644 --- a/src/commands/coordinators/private.ts +++ b/src/commands/coordinators/private.ts @@ -77,12 +77,12 @@ export class PrivateCommand extends Subcommand { const mod = interaction.member; const { guild } = interaction; + await interaction.deferReply({ ephemeral: true }); + // Checks if all the variables are of the right type if (user === null || guild === null || mod === null) { - await interaction.reply({ + await interaction.editReply({ content: 'Error fetching user!', - ephemeral: true, - fetchReply: true, }); return; } @@ -92,10 +92,8 @@ export class PrivateCommand extends Subcommand { // Checks if guildMember is null if (guildMember === undefined || modGuildMember === undefined) { - await interaction.reply({ + await interaction.editReply({ content: 'Error fetching users!', - ephemeral: true, - fetchReply: true, }); return; } @@ -103,10 +101,8 @@ export class PrivateCommand extends Subcommand { const [name, coordinator] = this.getCoordinator(modGuildMember); if (this.checkPrivate(guildMember.id, coordinator, guild)) { - await interaction.reply({ + await interaction.editReply({ content: 'A private channel already exists!', - ephemeral: true, - fetchReply: true, }); return; } @@ -206,10 +202,8 @@ export class PrivateCommand extends Subcommand { await privateChannel.send({ embeds: [embed] }); - await interaction.reply({ + await interaction.editReply({ content: `Created the private channel: ${privateChannel}`, - fetchReply: true, - ephemeral: true, }); } @@ -219,12 +213,12 @@ export class PrivateCommand extends Subcommand { const mod = interaction.member; const { guild, channel } = interaction; + await interaction.deferReply({ ephemeral: true }); + // Checks if all the variables are of the right type if (mod === null || guild === null || channel === null) { - await interaction.reply({ + await interaction.editReply({ content: 'Error fetching user!', - ephemeral: true, - fetchReply: true, }); return; } @@ -233,10 +227,8 @@ export class PrivateCommand extends Subcommand { // Checks if guildMember is null if (modGuildMember === undefined) { - await interaction.reply({ + await interaction.editReply({ content: 'Error fetching users!', - ephemeral: true, - fetchReply: true, }); return; } @@ -247,28 +239,22 @@ export class PrivateCommand extends Subcommand { if (user === null) { if (channel.type !== ChannelType.GuildText) { - await interaction.reply({ + await interaction.editReply({ content: 'Please make sure you ran this command in the original private text channel!', - ephemeral: true, - fetchReply: true, }); return; } if (channel.parentId !== IDs.categories.private) { - await interaction.reply({ + await interaction.editReply({ content: 'Please make sure you ran this command in the original private text channel!', - ephemeral: true, - fetchReply: true, }); return; } if (channel.topic === null) { - await interaction.reply({ + await interaction.editReply({ content: 'There was an error with this channel\'s topic!', - ephemeral: true, - fetchReply: true, }); return; } @@ -290,10 +276,8 @@ export class PrivateCommand extends Subcommand { .get(IDs.categories.private) as CategoryChannel | undefined; if (category === undefined) { - await interaction.reply({ + await interaction.editReply({ content: 'Could not find category!', - ephemeral: true, - fetchReply: true, }); return; } @@ -315,10 +299,8 @@ export class PrivateCommand extends Subcommand { } }); - await interaction.reply({ + await interaction.editReply({ content: `Successfully deleted the channel for ${user}`, - fetchReply: true, - ephemeral: true, }); } diff --git a/src/commands/mod/ban/ban.ts b/src/commands/mod/ban/ban.ts index c8a63fb..e87ac8d 100644 --- a/src/commands/mod/ban/ban.ts +++ b/src/commands/mod/ban/ban.ts @@ -77,9 +77,11 @@ export class BanCommand extends Command { return; } + await interaction.deferReply(); + const ban = await this.ban(user.id, mod.user.id, reason, guild); - await interaction.reply({ content: ban.message }); + await interaction.editReply({ content: ban.message }); } // Non Application Command method of banning a user diff --git a/src/commands/mod/ban/tempBan.ts b/src/commands/mod/ban/tempBan.ts index 1c44983..20c882e 100644 --- a/src/commands/mod/ban/tempBan.ts +++ b/src/commands/mod/ban/tempBan.ts @@ -89,6 +89,8 @@ export class TempBanCommand extends Command { return; } + await interaction.deferReply(); + const ban = await this.ban(user.id, mod.user.id, time, reason, guild); await interaction.reply({ content: ban.message }); diff --git a/src/commands/mod/ban/unban.ts b/src/commands/mod/ban/unban.ts index cd0c998..c3d41a3 100644 --- a/src/commands/mod/ban/unban.ts +++ b/src/commands/mod/ban/unban.ts @@ -74,6 +74,8 @@ export class UnbanCommand extends Command { return; } + await interaction.deferReply(); + const unban = await this.unban(user.id, mod.user.id, guild); await interaction.reply({ content: unban.message }); diff --git a/src/commands/mod/restriction/restrict.ts b/src/commands/mod/restriction/restrict.ts index 3925598..c3539b9 100644 --- a/src/commands/mod/restriction/restrict.ts +++ b/src/commands/mod/restriction/restrict.ts @@ -312,6 +312,8 @@ export class RestrictCommand extends Command { return; } + await interaction.deferReply(); + const info = await restrictRun(user?.id, mod.user.id, reason, guild); await interaction.reply({ diff --git a/src/commands/mod/restriction/restrictTolerance.ts b/src/commands/mod/restriction/restrictTolerance.ts index 113e2d5..a41fecf 100644 --- a/src/commands/mod/restriction/restrictTolerance.ts +++ b/src/commands/mod/restriction/restrictTolerance.ts @@ -68,11 +68,12 @@ export class RestrictToleranceCommand extends Command { return; } + await interaction.deferReply(); + const info = await restrictRun(user?.id, mod.user.id, reason, guild, true); await interaction.reply({ content: info.message, - fetchReply: true, }); } diff --git a/src/commands/mod/restriction/restrictTools.ts b/src/commands/mod/restriction/restrictTools.ts index 3dc2a34..4bccb05 100644 --- a/src/commands/mod/restriction/restrictTools.ts +++ b/src/commands/mod/restriction/restrictTools.ts @@ -69,12 +69,12 @@ export class RestrictToolsCommand extends Subcommand { const modInteraction = interaction.member; const { guild, channel } = interaction; + await interaction.deferReply({ ephemeral: true }); + // Checks if all the variables are of the right type if (modInteraction === null || guild === null || channel === null) { - await interaction.reply({ + await interaction.editReply({ content: 'Error fetching user!', - ephemeral: true, - fetchReply: true, }); return; } @@ -83,10 +83,8 @@ export class RestrictToolsCommand extends Subcommand { // Checks if guildMember is null if (mod === undefined) { - await interaction.reply({ + await interaction.editReply({ content: 'Error fetching moderator!', - ephemeral: true, - fetchReply: true, }); return; } @@ -95,19 +93,15 @@ export class RestrictToolsCommand extends Subcommand { if (user === null) { if (channel.type !== ChannelType.GuildText) { - await interaction.reply({ + await interaction.editReply({ content: 'Please make sure you ran this command in the original restricted text channel!', - ephemeral: true, - fetchReply: true, }); return; } if (channel.parentId !== IDs.categories.restricted) { - await interaction.reply({ + await interaction.editReply({ content: 'Please make sure you ran this command in the original restricted text channel!', - ephemeral: true, - fetchReply: true, }); return; } @@ -118,19 +112,15 @@ export class RestrictToolsCommand extends Subcommand { || channel.id === IDs.channels.restricted.restricted || channel.id === IDs.channels.restricted.tolerance ) { - await interaction.reply({ + await interaction.editReply({ content: 'You can\'t run this command these channels!', - ephemeral: true, - fetchReply: true, }); return; } if (channel.topic === null) { - await interaction.reply({ + await interaction.editReply({ content: 'There was an error with this channel\'s topic!', - ephemeral: true, - fetchReply: true, }); return; } @@ -153,10 +143,8 @@ export class RestrictToolsCommand extends Subcommand { .get(IDs.categories.restricted) as CategoryChannel | undefined; if (category === undefined) { - await interaction.reply({ + await interaction.editReply({ content: 'Could not find category!', - ephemeral: true, - fetchReply: true, }); return; } @@ -178,9 +166,8 @@ export class RestrictToolsCommand extends Subcommand { } }); - await interaction.reply({ + await interaction.editReply({ content: `Successfully deleted the channel for ${user}`, - fetchReply: true, }); } } diff --git a/src/commands/mod/restriction/unrestrict.ts b/src/commands/mod/restriction/unrestrict.ts index 98c2847..6464fdf 100644 --- a/src/commands/mod/restriction/unrestrict.ts +++ b/src/commands/mod/restriction/unrestrict.ts @@ -73,6 +73,8 @@ export class UnRestrictCommand extends Command { return; } + await interaction.deferReply(); + const info = await this.unRestrictRun(user?.id, mod.user.id, guild); await interaction.reply({