2022-08-21 07:34:11 +00:00
|
|
|
|
using DSharpPlus.Entities;
|
2022-02-21 08:40:09 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-10-29 10:17:44 +00:00
|
|
|
|
using DSharpPlus.Interactivity;
|
|
|
|
|
using DSharpPlus.Interactivity.Extensions;
|
2022-08-21 07:34:11 +00:00
|
|
|
|
using DSharpPlus.SlashCommands;
|
|
|
|
|
using DSharpPlus.SlashCommands.Attributes;
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2022-08-21 07:34:11 +00:00
|
|
|
|
namespace SupportChild.Commands;
|
|
|
|
|
|
|
|
|
|
public class SayCommand : ApplicationCommandModule
|
2022-02-21 08:40:09 +00:00
|
|
|
|
{
|
2024-10-29 09:10:37 +00:00
|
|
|
|
[SlashRequireGuild]
|
|
|
|
|
[SlashCommand("say", "Prints a message with information from staff. Use without identifier to list all identifiers.")]
|
|
|
|
|
public async Task OnExecute(InteractionContext command, [Option("Identifier", "(Optional) The identifier word to summon a message.")] string identifier = null)
|
|
|
|
|
{
|
|
|
|
|
// Print list of all messages if no identifier is provided
|
|
|
|
|
if (identifier == null)
|
|
|
|
|
{
|
2024-10-29 10:17:44 +00:00
|
|
|
|
SendMessageList(command);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2024-10-29 10:17:44 +00:00
|
|
|
|
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message message))
|
|
|
|
|
{
|
|
|
|
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
|
{
|
2024-10-29 10:17:44 +00:00
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
|
Description = "There is no message with that identifier."
|
|
|
|
|
}, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Cyan,
|
|
|
|
|
Description = message.message.Replace("\\n", "\n")
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2024-10-29 10:17:44 +00:00
|
|
|
|
private static async void SendMessageList(InteractionContext command)
|
|
|
|
|
{
|
|
|
|
|
List<Database.Message> messages = Database.GetAllMessages();
|
|
|
|
|
if (messages.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
|
{
|
2024-10-29 10:17:44 +00:00
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
|
Description = "There are no messages registered."
|
|
|
|
|
}, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<string> listItems = [];
|
|
|
|
|
foreach (Database.Message message in messages)
|
|
|
|
|
{
|
|
|
|
|
listItems.Add("**" + message.identifier + "** Added by <@" + message.userID + ">\n");
|
2024-10-29 09:10:37 +00:00
|
|
|
|
}
|
2024-10-29 10:17:44 +00:00
|
|
|
|
|
|
|
|
|
List<DiscordEmbedBuilder> embeds = [];
|
|
|
|
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
2024-10-29 09:10:37 +00:00
|
|
|
|
{
|
2024-10-29 10:17:44 +00:00
|
|
|
|
embeds.Add(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
|
{
|
2024-10-29 10:17:44 +00:00
|
|
|
|
Title = "Available messages:",
|
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
|
Description = message
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2024-10-29 10:17:44 +00:00
|
|
|
|
// Add the footers
|
|
|
|
|
for (int i = 0; i < embeds.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
2024-10-29 09:10:37 +00:00
|
|
|
|
{
|
2024-10-29 10:17:44 +00:00
|
|
|
|
Text = $"Page {i + 1} / {embeds.Count}"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Page> listPages = [];
|
|
|
|
|
foreach (DiscordEmbedBuilder embed in embeds)
|
|
|
|
|
{
|
|
|
|
|
listPages.Add(new Page("", embed));
|
2024-10-29 09:10:37 +00:00
|
|
|
|
}
|
2024-10-29 10:17:44 +00:00
|
|
|
|
|
|
|
|
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
2024-10-29 09:10:37 +00:00
|
|
|
|
}
|
2022-05-19 11:38:59 +00:00
|
|
|
|
}
|