2022-04-18 10:52:03 +00:00
|
|
|
|
using System.Collections.Generic;
|
2024-12-26 05:36:20 +00:00
|
|
|
|
using System.ComponentModel;
|
2022-02-21 08:40:09 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2024-12-26 05:36:20 +00:00
|
|
|
|
using DSharpPlus.Commands;
|
|
|
|
|
using DSharpPlus.Commands.ContextChecks;
|
|
|
|
|
using DSharpPlus.Commands.Processors.SlashCommands;
|
2022-02-21 08:40:09 +00:00
|
|
|
|
using DSharpPlus.Entities;
|
2022-08-21 07:34:11 +00:00
|
|
|
|
using DSharpPlus.Interactivity;
|
|
|
|
|
using DSharpPlus.Interactivity.Extensions;
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2022-08-21 07:34:11 +00:00
|
|
|
|
namespace SupportChild.Commands;
|
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
|
public class ListAssignedCommand
|
2022-02-21 08:40:09 +00:00
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
[RequireGuild]
|
|
|
|
|
[Command("listassigned")]
|
|
|
|
|
[Description("Lists tickets assigned to a user.")]
|
|
|
|
|
public async Task OnExecute(SlashCommandContext command,
|
|
|
|
|
[Parameter("user")][Description("(Optional) User to list tickets for.")] DiscordUser user = null)
|
2024-10-29 09:10:37 +00:00
|
|
|
|
{
|
|
|
|
|
DiscordUser listUser = user == null ? command.User : user;
|
|
|
|
|
|
|
|
|
|
if (!Database.TryGetAssignedTickets(listUser.Id, out List<Database.Ticket> assignedTickets))
|
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
|
Description = "User does not have any assigned tickets."
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<string> listItems = new List<string>();
|
|
|
|
|
foreach (Database.Ticket ticket in assignedTickets)
|
|
|
|
|
{
|
|
|
|
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
|
|
|
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
|
|
|
|
{
|
|
|
|
|
embeds.Add(new DiscordEmbedBuilder
|
|
|
|
|
{
|
|
|
|
|
Title = "Assigned tickets: ",
|
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
|
Description = message
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add the footers
|
|
|
|
|
for (int i = 0; i < embeds.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
|
|
|
|
{
|
|
|
|
|
Text = $"Page {i + 1} / {embeds.Count}"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Page> listPages = new List<Page>();
|
|
|
|
|
foreach (DiscordEmbedBuilder embed in embeds)
|
|
|
|
|
{
|
|
|
|
|
listPages.Add(new Page("", embed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
|
|
|
|
}
|
2022-05-19 11:38:59 +00:00
|
|
|
|
}
|