All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m42s
58 lines
2.5 KiB
Java
58 lines
2.5 KiB
Java
package cc.fascinated.bat.afk.command;
|
|
|
|
import cc.fascinated.bat.common.command.BatCommand;
|
|
import cc.fascinated.bat.common.command.Category;
|
|
import cc.fascinated.bat.common.command.CommandInfo;
|
|
import cc.fascinated.bat.common.MemberUtils;
|
|
import cc.fascinated.bat.afk.profile.AfkProfile;
|
|
import cc.fascinated.bat.common.model.BatGuild;
|
|
import cc.fascinated.bat.common.model.BatUser;
|
|
import lombok.NonNull;
|
|
import net.dv8tion.jda.api.entities.Member;
|
|
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;
|
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
/**
|
|
* @author Fascinated (fascinated7)
|
|
*/
|
|
@Component
|
|
@CommandInfo(name = "afk", description = "Sets your AFK status", category = Category.GENERAL)
|
|
public class AfkCommand extends BatCommand {
|
|
public AfkCommand() {
|
|
super.addOptions(new OptionData(OptionType.STRING, "reason", "The reason for being AFK", false));
|
|
}
|
|
|
|
/**
|
|
* Fired when this command is executed.
|
|
*
|
|
* @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
|
|
*/
|
|
@Override
|
|
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, Message commandMessage, String[] arguments, SlashCommandInteraction event) {
|
|
AfkProfile profile = guild.getProfile(AfkProfile.class);
|
|
String reason = null;
|
|
OptionMapping reasonOption = event.getOption("reason");
|
|
if (reasonOption != null) {
|
|
reason = reasonOption.getAsString();
|
|
}
|
|
|
|
profile.addAfkUser(guild, member.getId(), reason);
|
|
event.reply("You are now AFK: %s%s".formatted(
|
|
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();
|
|
}
|
|
}
|