SupportChild/Commands/AddMessageCommand.cs

60 lines
2 KiB
C#
Raw Permalink Normal View History

using System.ComponentModel;
2024-12-27 07:17:14 +00:00
using System.Globalization;
using DSharpPlus.Entities;
2022-02-21 08:40:09 +00:00
using System.Threading.Tasks;
using DSharpPlus.Commands;
using DSharpPlus.Commands.ContextChecks;
using DSharpPlus.Commands.Processors.SlashCommands;
using DSharpPlus.Exceptions;
2022-02-21 08:40:09 +00:00
2022-08-21 07:34:11 +00:00
namespace SupportChild.Commands;
public class AddMessageCommand
2022-02-21 08:40:09 +00:00
{
[RequireGuild]
[Command("addmessage")]
[Description("Adds a new message for the 'say' command.")]
public async Task OnExecute(SlashCommandContext command,
[Parameter("identifier")][Description("The identifier word used in the /say command.")] string identifier,
[Parameter("message")][Description("The message the /say command will return.")] string message)
{
if (string.IsNullOrEmpty(message))
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "No message specified."
}, true);
return;
}
2022-02-21 08:40:09 +00:00
2024-12-27 07:17:14 +00:00
if (Database.TryGetMessage(identifier.ToLower(CultureInfo.InvariantCulture), out Database.Message _))
{
await command.RespondAsync(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.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Message added."
}, true);
}
else
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed adding the message to the database."
}, true);
}
2024-12-27 07:17:14 +00:00
await LogChannel.Success(command.User.Mention + " added or updated `" + identifier + "` in the /say command.\n\nContent:\n\n" + message);
}
2022-05-19 11:38:59 +00:00
}