fix: make slash command args optional without breaking them

This commit is contained in:
sam 2024-10-14 03:14:28 +02:00
parent 72c09b3e08
commit c86f94e497
Signed by: sam
GPG key ID: 5F3C3C1B3166639D

View file

@ -53,6 +53,8 @@ public class InviteCommands(
.Select(i => new PartialNamedInvite(
i.Code,
dbInvites.FirstOrDefault(dbI => dbI.Code == i.Code)?.Name,
i.Uses,
i.Channel,
i.Inviter,
i.CreatedAt
))
@ -64,20 +66,29 @@ public class InviteCommands(
Value: $"""
**Name:** {i.Name ?? "*(unnamed)*"}
**Created at:** <t:{i.CreatedAt.ToUnixTimeSeconds()}>
**Uses:** {i.Uses}
**Channel:** {(i.Channel != null ? $"<#{i.Channel.ID.Value}>" : "*(unknown)*")}
**Created by:** {i.CreatedBy.OrDefault()?.Tag() ?? "*(unknown)*"}
""",
IsInline: true
));
IsInline: false
))
.ToList();
return await feedbackService.SendContextualPaginatedMessageAsync(
userId,
DiscordUtils.PaginateFields(fields, title: $"Invites for {guild.Name}")
DiscordUtils.PaginateFields(
fields,
title: $"Invites for {guild.Name} ({fields.Count})",
fieldsPerPage: 5
)
);
}
private record struct PartialNamedInvite(
string Code,
string? Name,
int Uses,
IPartialChannel? Channel,
Optional<IUser> CreatedBy,
DateTimeOffset CreatedAt
);
@ -88,7 +99,7 @@ public class InviteCommands(
[Description("The channel to create the invite in")]
[ChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement)]
IChannel channel,
[Description("What to name the new invite")] [Optional] string? name
[Description("What to name the new invite")] string? name = null
)
{
var (userId, guildId) = contextInjection.GetUserAndGuild();
@ -141,7 +152,7 @@ public class InviteCommands(
[Description("The invite to rename")]
[AutocompleteProvider("autocomplete:invite-provider")]
string invite,
[Description("The invite's new name")] [Optional] string? name
[Description("The invite's new name")] string? name = null
)
{
var (_, guildId) = contextInjection.GetUserAndGuild();