SupportChild/Commands/CreateButtonPanelCommand.cs

56 lines
2.2 KiB
C#
Raw Permalink Normal View History

using System.Collections.Generic;
using System.ComponentModel;
2022-08-21 07:34:11 +00:00
using System.Linq;
using System.Threading.Tasks;
using DSharpPlus.Commands;
using DSharpPlus.Commands.ContextChecks;
using DSharpPlus.Commands.Processors.SlashCommands;
2022-08-21 07:34:11 +00:00
using DSharpPlus.Entities;
using DSharpPlus.Exceptions;
2022-08-21 07:34:11 +00:00
namespace SupportChild.Commands;
public class CreateButtonPanelCommand
2022-08-21 07:34:11 +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)
{
DiscordMessageBuilder builder = new DiscordMessageBuilder().WithContent(" ");
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedCategories();
2022-08-21 07:34:11 +00:00
if (verifiedCategories.Count == 0)
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: No registered categories found. You have to use /addcategory first."
}, true);
return;
}
2022-08-21 07:34:11 +00:00
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
2022-08-21 07:34:11 +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
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++)
{
buttonRow.Add(new DiscordButtonComponent(DiscordButtonStyle.Primary, "supportchild_newticketbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name));
}
builder.AddComponents(buttonRow);
}
2022-08-21 07:34:11 +00:00
await command.Channel.SendMessageAsync(builder);
await command.RespondAsync(new DiscordEmbedBuilder
{
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-27 07:17:14 +00:00
await LogChannel.Success(command.User.Mention + " created a new button panel in " + command.Channel.Mention + ".");
}
2022-08-21 07:34:11 +00:00
}