SupportChild/Commands/SayCommand.cs

67 lines
1.9 KiB
C#
Raw Normal View History

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.Linq;
using System.Threading.Tasks;
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
{
2022-08-21 07:34:11 +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)
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
// Print list of all messages if no identifier is provided
if (identifier == null)
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
List<Database.Message> messages = Database.GetAllMessages();
if (!messages.Any())
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
await command.CreateResponseAsync(new DiscordEmbedBuilder
2022-05-19 11:38:59 +00:00
{
Color = DiscordColor.Red,
2022-08-21 07:34:11 +00:00
Description = "There are no messages registered."
}, true);
2022-05-19 11:38:59 +00:00
return;
}
2022-02-21 08:40:09 +00:00
2022-08-21 07:34:11 +00:00
List<string> listItems = new List<string>();
foreach (Database.Message message in messages)
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
listItems.Add("**" + message.identifier + "** Added by <@" + message.userID + ">\n");
2022-05-19 11:38:59 +00:00
}
2022-02-21 08:40:09 +00:00
2022-08-21 07:34:11 +00:00
LinkedList<string> listMessages = Utilities.ParseListIntoMessages(listItems);
foreach (string listMessage in listMessages)
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Title = "Available messages: ",
Color = DiscordColor.Green,
Description = listMessage
}, true);
}
2022-05-19 11:38:59 +00:00
}
2022-08-21 07:34:11 +00:00
// Print specific message
else
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message message))
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
await command.CreateResponseAsync(new DiscordEmbedBuilder
2022-05-19 11:38:59 +00:00
{
Color = DiscordColor.Red,
2022-08-21 07:34:11 +00:00
Description = "There is no message with that identifier."
}, true);
2022-05-19 11:38:59 +00:00
return;
}
2022-02-21 08:40:09 +00:00
2022-08-21 07:34:11 +00:00
await command.CreateResponseAsync(new DiscordEmbedBuilder
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
Color = DiscordColor.Cyan,
Description = message.message.Replace("\\n", "\n")
});
2022-05-19 11:38:59 +00:00
}
}
}