SupportChild/Commands/ListOpen.cs

60 lines
1.9 KiB
C#
Raw Permalink Normal View History

2022-08-21 07:34:11 +00:00
using System.Collections.Generic;
using System.Threading.Tasks;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes;
namespace SupportChild.Commands;
public class ListOpen : ApplicationCommandModule
{
[SlashRequireGuild]
[SlashCommand("listopen", "Lists all open tickets, oldest first.")]
public async Task OnExecute(InteractionContext command)
{
if (!Database.TryGetOpenTickets(out List<Database.Ticket> openTickets))
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Could not fetch any open tickets."
});
return;
}
2022-08-21 07:34:11 +00:00
List<string> listItems = new List<string>();
foreach (Database.Ticket ticket in openTickets)
{
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
}
2022-08-21 07:34:11 +00:00
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
foreach (string message in Utilities.ParseListIntoMessages(listItems))
{
embeds.Add(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = message
});
}
2022-08-21 07:34:11 +00:00
// Add the footers
for (int i = 0; i < embeds.Count; i++)
{
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
{
Text = $"Page {i + 1} / {embeds.Count}"
};
}
2022-08-21 07:34:11 +00:00
List<Page> listPages = new List<Page>();
foreach (DiscordEmbedBuilder embed in embeds)
{
listPages.Add(new Page("", embed));
}
2022-08-21 07:34:11 +00:00
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
}
2022-08-21 07:34:11 +00:00
}