mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-29 18:49:53 +03:00
Reduce method complexity in /ban, /unban and some other commands (#50)
This PR does numerous things to reduce method complexity: - Created an extension method `FeedbackService#SendContextualEmbedResultAsync`, which directly takes a `Result<Embed>` and checks it once in the extension method instead of multiple times in all commands; - Split the command methods for `/ban` and `/unban` into 2 parts: `Execute(Un)Ban` and `(Un)BanUserAsync`. The former will check all the needed results and will pass the outputs into the latter; - Extracted the method for logging an action into Private- and PublicFeedbackChannels. It now resides in UtilityService. Right now, only `/ban` and `/unban` make use of that method; - Created an extension method `Snowflake#EmptyOrEqualTo`, that combines the task of checking if a Snowflake is empty and checking if that Snowflake is equal to another Snowflake. Similar changes will be made to other command groups in future PRs. This is not done here to make the reviewing process easier. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
c825848d7e
commit
e2bf083189
10 changed files with 186 additions and 186 deletions
|
@ -83,10 +83,7 @@ public class KickCommandGroup : CommandGroup {
|
|||
var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotFoundShort, currentUser)
|
||||
.WithColour(ColorsList.Red).Build();
|
||||
|
||||
if (!embed.IsDefined(out var alreadyBuilt))
|
||||
return Result.FromError(embed);
|
||||
|
||||
return (Result)await _feedbackService.SendContextualEmbedAsync(alreadyBuilt, ct: CancellationToken);
|
||||
return await _feedbackService.SendContextualEmbedResultAsync(embed, CancellationToken);
|
||||
}
|
||||
|
||||
var interactionResult
|
||||
|
@ -162,9 +159,6 @@ public class KickCommandGroup : CommandGroup {
|
|||
}
|
||||
}
|
||||
|
||||
if (!responseEmbed.IsDefined(out var built))
|
||||
return Result.FromError(responseEmbed);
|
||||
|
||||
return (Result)await _feedbackService.SendContextualEmbedAsync(built, ct: CancellationToken);
|
||||
return await _feedbackService.SendContextualEmbedResultAsync(responseEmbed, CancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue