2024-10-29 09:10:37 +00:00
|
|
|
using System.Collections.Generic;
|
2024-12-26 05:36:20 +00:00
|
|
|
using System.ComponentModel;
|
2022-08-21 07:34:11 +00:00
|
|
|
using System.Linq;
|
|
|
|
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-08-21 07:34:11 +00:00
|
|
|
using DSharpPlus.Entities;
|
2024-12-26 12:21:37 +00:00
|
|
|
using DSharpPlus.Exceptions;
|
2022-08-21 07:34:11 +00:00
|
|
|
|
|
|
|
namespace SupportChild.Commands;
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
public class CreateButtonPanelCommand
|
2022-08-21 07:34:11 +00:00
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
[RequireGuild]
|
|
|
|
[Command("createbuttonpanel")]
|
|
|
|
[Description("Creates a series of buttons which users can use to open new tickets in specific categories.")]
|
|
|
|
public async Task OnExecute(SlashCommandContext command)
|
2024-10-29 09:10:37 +00:00
|
|
|
{
|
|
|
|
DiscordMessageBuilder builder = new DiscordMessageBuilder().WithContent(" ");
|
2024-12-27 03:28:27 +00:00
|
|
|
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedCategories();
|
2022-08-21 07:34:11 +00:00
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
if (verifiedCategories.Count == 0)
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
{
|
|
|
|
Color = DiscordColor.Red,
|
2024-12-26 05:36:20 +00:00
|
|
|
Description = "Error: No registered categories found. You have to use /addcategory first."
|
2024-10-29 09:10:37 +00:00
|
|
|
}, true);
|
|
|
|
return;
|
|
|
|
}
|
2022-08-21 07:34:11 +00:00
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
2022-08-21 07:34:11 +00:00
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
int nrOfButtons = 0;
|
|
|
|
for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++)
|
|
|
|
{
|
|
|
|
List<DiscordButtonComponent> buttonRow = new List<DiscordButtonComponent>();
|
2022-08-21 07:34:11 +00:00
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++)
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
buttonRow.Add(new DiscordButtonComponent(DiscordButtonStyle.Primary, "supportchild_newticketbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name));
|
2024-10-29 09:10:37 +00:00
|
|
|
}
|
|
|
|
builder.AddComponents(buttonRow);
|
|
|
|
}
|
2022-08-21 07:34:11 +00:00
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
await command.Channel.SendMessageAsync(builder);
|
2024-12-26 05:36:20 +00:00
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
{
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
Description = "Successfully created message, make sure to run this command again if you add new categories to the bot."
|
|
|
|
}, true);
|
2024-12-26 12:21:37 +00:00
|
|
|
|
2024-12-27 07:17:14 +00:00
|
|
|
await LogChannel.Success(command.User.Mention + " created a new button panel in " + command.Channel.Mention + ".");
|
2024-10-29 09:10:37 +00:00
|
|
|
}
|
2022-08-21 07:34:11 +00:00
|
|
|
}
|