forked from TeamInklings/Octobot
Don't use Option attribute in ExecuteBanAsync method (#252)
https://github.com/TeamOctolings/Octobot/issues/246#issuecomment-1912579699 > The `Option` attribute also somehow affects the command update behavior. I'll get rid of it then. Closes #246 Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
b4ae9cca2d
commit
7e9c08cab7
1 changed files with 6 additions and 7 deletions
|
@ -54,7 +54,7 @@ public class BanCommandGroup : CommandGroup
|
||||||
/// A slash command that bans a Discord user with the specified reason.
|
/// A slash command that bans a Discord user with the specified reason.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="target">The user to ban.</param>
|
/// <param name="target">The user to ban.</param>
|
||||||
/// <param name="stringDuration">The duration for this ban. The user will be automatically unbanned after this duration.</param>
|
/// <param name="duration">The duration for this ban. The user will be automatically unbanned after this duration.</param>
|
||||||
/// <param name="reason">
|
/// <param name="reason">
|
||||||
/// The reason for this ban. Must be encoded with <see cref="StringExtensions.EncodeHeader" /> when passed to
|
/// The reason for this ban. Must be encoded with <see cref="StringExtensions.EncodeHeader" /> when passed to
|
||||||
/// <see cref="IDiscordRestGuildAPI.CreateGuildBanAsync" />.
|
/// <see cref="IDiscordRestGuildAPI.CreateGuildBanAsync" />.
|
||||||
|
@ -76,8 +76,7 @@ public class BanCommandGroup : CommandGroup
|
||||||
[Description("User to ban")] IUser target,
|
[Description("User to ban")] IUser target,
|
||||||
[Description("Ban reason")] [MaxLength(256)]
|
[Description("Ban reason")] [MaxLength(256)]
|
||||||
string reason,
|
string reason,
|
||||||
[Description("Ban duration")] [Option("duration")]
|
[Description("Ban duration")] string? duration = null)
|
||||||
string? stringDuration = null)
|
|
||||||
{
|
{
|
||||||
if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId))
|
if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId))
|
||||||
{
|
{
|
||||||
|
@ -106,14 +105,14 @@ public class BanCommandGroup : CommandGroup
|
||||||
var data = await _guildData.GetData(guild.ID, CancellationToken);
|
var data = await _guildData.GetData(guild.ID, CancellationToken);
|
||||||
Messages.Culture = GuildSettings.Language.Get(data.Settings);
|
Messages.Culture = GuildSettings.Language.Get(data.Settings);
|
||||||
|
|
||||||
if (stringDuration is null)
|
if (duration is null)
|
||||||
{
|
{
|
||||||
return await BanUserAsync(executor, target, reason, null, guild, data, channelId, bot,
|
return await BanUserAsync(executor, target, reason, null, guild, data, channelId, bot,
|
||||||
CancellationToken);
|
CancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
var parseResult = TimeSpanParser.TryParse(stringDuration);
|
var parseResult = TimeSpanParser.TryParse(duration);
|
||||||
if (!parseResult.IsDefined(out var duration))
|
if (!parseResult.IsDefined(out var timeSpan))
|
||||||
{
|
{
|
||||||
var failedEmbed = new EmbedBuilder()
|
var failedEmbed = new EmbedBuilder()
|
||||||
.WithSmallTitle(Messages.InvalidTimeSpan, bot)
|
.WithSmallTitle(Messages.InvalidTimeSpan, bot)
|
||||||
|
@ -123,7 +122,7 @@ public class BanCommandGroup : CommandGroup
|
||||||
return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken);
|
return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await BanUserAsync(executor, target, reason, duration, guild, data, channelId, bot, CancellationToken);
|
return await BanUserAsync(executor, target, reason, timeSpan, guild, data, channelId, bot, CancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Result> BanUserAsync(
|
private async Task<Result> BanUserAsync(
|
||||||
|
|
Reference in a new issue