Bat/src/main/java/cc/fascinated/bat/afk/command/AfkCommand.java

58 lines
2.5 KiB
Java
Raw Normal View History

2024-12-27 13:04:57 +00:00
package cc.fascinated.bat.afk.command;
2024-06-27 14:29:48 +01:00
2024-12-27 13:04:57 +00:00
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
2024-06-27 14:29:48 +01:00
import cc.fascinated.bat.common.MemberUtils;
2024-12-27 13:04:57 +00:00
import cc.fascinated.bat.afk.profile.AfkProfile;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
2024-06-27 14:29:48 +01:00
import lombok.NonNull;
import net.dv8tion.jda.api.entities.Member;
2024-07-16 14:35:02 +01:00
import net.dv8tion.jda.api.entities.Message;
2024-06-27 14:29:48 +01:00
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;
2024-06-27 14:29:48 +01:00
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component
@CommandInfo(name = "afk", description = "Sets your AFK status", category = Category.GENERAL)
2024-06-27 14:29:48 +01:00
public class AfkCommand extends BatCommand {
public AfkCommand() {
2024-07-04 08:47:32 -04:00
super.addOptions(new OptionData(OptionType.STRING, "reason", "The reason for being AFK", false));
2024-06-27 14:29:48 +01:00
}
2024-07-04 08:47:32 -04:00
/**
* Fired when this command is executed.
*
2024-07-16 14:35:02 +01:00
* @param guild the guild the command was executed in, if any
* @param user the user who executed the command
* @param channel the channel the command was executed in
* @param member the member who executed the command, null if not a guild
* @param commandMessage
* @param arguments
* @param event the event that invoked this command
2024-07-04 08:47:32 -04:00
*/
2024-06-27 14:29:48 +01:00
@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) {
2024-06-27 14:29:48 +01:00
AfkProfile profile = guild.getProfile(AfkProfile.class);
String reason = null;
2024-07-01 15:27:39 +01:00
OptionMapping reasonOption = event.getOption("reason");
2024-06-27 14:29:48 +01:00
if (reasonOption != null) {
reason = reasonOption.getAsString();
}
profile.addAfkUser(guild, member.getId(), reason);
2024-07-01 15:27:39 +01:00
event.reply("You are now AFK: %s%s".formatted(
2024-06-27 14:29:48 +01:00
profile.getAfkReason(member.getId()),
MemberUtils.hasPermissionToEdit(guild, user) ? "" :
"\n\n*I do not have enough permissions to edit your user, and therefore cannot update your nickname*"
)).queue();
}
}