Files
Bat/src/main/java/cc/fascinated/bat/birthday/command/MessageSubCommand.java

59 lines
2.6 KiB
Java
Raw Normal View History

2024-12-27 13:04:57 +00:00
package cc.fascinated.bat.birthday.command;
2024-12-27 13:04:57 +00:00
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
2024-12-27 13:04:57 +00:00
import cc.fascinated.bat.birthday.profile.BirthdayProfile;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
import lombok.NonNull;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Member;
2024-07-16 14:35:02 +01:00
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
2024-07-04 08:47:32 -04:00
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component("birthday:message.sub")
2024-06-27 19:36:52 +01:00
@CommandInfo(name = "message", description = "Changes the message that is sent when it is a user's birthday", requiredPermissions = Permission.MANAGE_SERVER)
2024-07-04 08:47:32 -04:00
public class MessageSubCommand extends BatCommand {
@Autowired
public MessageSubCommand() {
2024-07-04 08:47:32 -04:00
super.addOptions(new OptionData(OptionType.STRING, "message", "The message that is sent. (Placeholders: {user}, {age})", true));
}
@Override
2024-07-16 14:35:02 +01:00
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, Message commandMessage, String[] arguments, SlashCommandInteraction event) {
BirthdayProfile profile = guild.getBirthdayProfile();
2024-07-01 15:27:39 +01:00
OptionMapping messageOption = event.getOption("message");
2024-07-07 02:18:10 +01:00
assert messageOption != null;
String message = messageOption.getAsString();
2024-07-07 02:18:10 +01:00
if (message.length() > 2000) {
2024-07-01 15:27:39 +01:00
event.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("The message must be less than 2000 characters")
.build()).queue();
return;
}
if (!message.contains("{user}") || !message.contains("{age}")) {
2024-07-01 15:27:39 +01:00
event.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("The message must contain the placeholders {user} and {age}")
.build()).queue();
return;
}
profile.setMessage(message);
2024-07-01 15:27:39 +01:00
event.replyEmbeds(EmbedUtils.successEmbed()
.setDescription("You have updated the birthday message!\n\n**Message:** %s".formatted(profile.getBirthdayMessage(user.getDiscordUser())))
.build()).queue();
}
}