diff --git a/src/Commands/AboutCommandGroup.cs b/src/Commands/AboutCommandGroup.cs
index 70f4bcf..760d96b 100644
--- a/src/Commands/AboutCommandGroup.cs
+++ b/src/Commands/AboutCommandGroup.cs
@@ -72,8 +72,7 @@ public class AboutCommandGroup : CommandGroup {
.WithColour(ColorsList.Cyan)
.WithImageUrl("https://cdn.upload.systems/uploads/JFAaX5vr.png")
.Build();
- if (!embed.IsDefined(out var built)) return Result.FromError(embed);
- return (Result)await _feedbackService.SendContextualEmbedAsync(built, ct: CancellationToken);
+ return await _feedbackService.SendContextualEmbedResultAsync(embed, CancellationToken);
}
}
diff --git a/src/Commands/BanCommandGroup.cs b/src/Commands/BanCommandGroup.cs
index d2c1c76..902c753 100644
--- a/src/Commands/BanCommandGroup.cs
+++ b/src/Commands/BanCommandGroup.cs
@@ -7,13 +7,13 @@ using Remora.Commands.Attributes;
using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.API.Abstractions.Rest;
-using Remora.Discord.API.Objects;
using Remora.Discord.Commands.Attributes;
using Remora.Discord.Commands.Conditions;
using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Feedback.Services;
using Remora.Discord.Extensions.Embeds;
using Remora.Discord.Extensions.Formatting;
+using Remora.Rest.Core;
using Remora.Results;
namespace Boyfriend.Commands;
@@ -57,7 +57,7 @@ public class BanCommandGroup : CommandGroup {
/// A feedback sending result which may or may not have succeeded. A successful result does not mean that the user
/// was banned and vice-versa.
///
- ///
+ ///
[Command("ban", "бан")]
[DiscordDefaultMemberPermissions(DiscordPermission.BanMembers)]
[DiscordDefaultDMPermission(false)]
@@ -66,122 +66,95 @@ public class BanCommandGroup : CommandGroup {
[RequireBotDiscordPermissions(DiscordPermission.BanMembers)]
[Description("Ban user")]
[UsedImplicitly]
- public async Task BanUserAsync(
+ public async Task ExecuteBan(
[Description("User to ban")] IUser target,
[Description("Ban reason")] string reason,
[Description("Ban duration")] TimeSpan? duration = null) {
if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var userId))
return Result.FromError(
new ArgumentNullError(nameof(_context), "Unable to retrieve necessary IDs from command context"));
-
// The current user's avatar is used when sending error messages
var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken);
if (!currentUserResult.IsDefined(out var currentUser))
return Result.FromError(currentUserResult);
+ var userResult = await _userApi.GetUserAsync(userId.Value, CancellationToken);
+ if (!userResult.IsDefined(out var user))
+ return Result.FromError(userResult);
+ var guildResult = await _guildApi.GetGuildAsync(guildId.Value, ct: CancellationToken);
+ if (!guildResult.IsDefined(out var guild))
+ return Result.FromError(guildResult);
- var data = await _dataService.GetData(guildId.Value, CancellationToken);
+ return await BanUserAsync(target, reason, duration, guild, channelId.Value, user, currentUser);
+ }
+
+ private async Task BanUserAsync(
+ IUser target, string reason, TimeSpan? duration, IGuild guild, Snowflake channelId,
+ IUser user, IUser currentUser) {
+ var data = await _dataService.GetData(guild.ID, CancellationToken);
var cfg = data.Settings;
Messages.Culture = GuildSettings.Language.Get(cfg);
- var existingBanResult = await _guildApi.GetGuildBanAsync(guildId.Value, target.ID, CancellationToken);
+ var existingBanResult = await _guildApi.GetGuildBanAsync(guild.ID, target.ID, CancellationToken);
if (existingBanResult.IsDefined()) {
- var embed = new EmbedBuilder().WithSmallTitle(Messages.UserAlreadyBanned, currentUser)
+ var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.UserAlreadyBanned, 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(failedEmbed, CancellationToken);
}
var interactionResult
- = await _utility.CheckInteractionsAsync(guildId.Value, userId.Value, target.ID, "Ban", CancellationToken);
+ = await _utility.CheckInteractionsAsync(guild.ID, user.ID, target.ID, "Ban", CancellationToken);
if (!interactionResult.IsSuccess)
return Result.FromError(interactionResult);
- Result