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