SupportChild/Commands/AddMessageCommand.cs

53 lines
1.7 KiB
C#
Raw Permalink Normal View History

2022-08-21 07:34:11 +00:00
using DSharpPlus.Entities;
2022-02-21 08:40:09 +00:00
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 AddMessageCommand : ApplicationCommandModule
2022-02-21 08:40:09 +00:00
{
[SlashRequireGuild]
[SlashCommand("addmessage", "Adds a new message for the 'say' command.")]
public async Task OnExecute(InteractionContext command,
[Option("Identifier", "The identifier word used in the /say command.")] string identifier,
[Option("Message", "The message the /say command will return.")] string message)
{
if (string.IsNullOrEmpty(message))
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "No message specified."
}, true);
return;
}
2022-02-21 08:40:09 +00:00
if (Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "There is already a message with that identifier."
}, true);
return;
}
2022-02-21 08:40:09 +00:00
if (Database.AddMessage(identifier, command.Member.Id, message))
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Message added."
}, true);
}
else
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed adding the message to the database."
}, true);
}
}
2022-05-19 11:38:59 +00:00
}