(wip) migrate commands to components
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-09-06 22:14:44 +02:00
parent eafa80f1d2
commit 1f2bafa7f8
35 changed files with 359 additions and 174 deletions

View File

@@ -7,12 +7,21 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.ProfileImage;
import wtf.beatrice.hidekobot.objects.MessageResponse;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashAvatarCommand extends SlashCommandImpl
{
private final ProfileImage profileImage;
public SlashAvatarCommand(@NotNull ProfileImage profileImage)
{
this.profileImage = profileImage;
}
@Override
public CommandData getSlashCommandData()
{
@@ -44,13 +53,13 @@ public class SlashAvatarCommand extends SlashCommandImpl
OptionMapping sizeArg = event.getOption("size");
if (sizeArg != null)
{
resolution = ProfileImage.parseResolution(sizeArg.getAsInt());
resolution = profileImage.parseResolution(sizeArg.getAsInt());
} else
{
resolution = ProfileImage.parseResolution(512);
resolution = profileImage.parseResolution(512);
}
MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.AVATAR);
MessageResponse response = profileImage.buildResponse(resolution, user, ProfileImage.ImageType.AVATAR);
if (response.content() != null)
{
event.getHook().editOriginal(response.content()).queue();

View File

@@ -7,11 +7,21 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.UserPunishment;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashBanCommand extends SlashCommandImpl
{
private final UserPunishment userPunishment;
public SlashBanCommand(@Autowired UserPunishment userPunishment)
{
this.userPunishment = userPunishment;
}
@Override
public CommandData getSlashCommandData()
{
@@ -31,6 +41,6 @@ public class SlashBanCommand extends SlashCommandImpl
@Override
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
{
UserPunishment.handle(event, UserPunishment.PunishmentType.BAN);
userPunishment.handle(event, UserPunishment.PunishmentType.BAN);
}
}

View File

@@ -7,12 +7,21 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.ProfileImage;
import wtf.beatrice.hidekobot.objects.MessageResponse;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashBannerCommand extends SlashCommandImpl
{
private final ProfileImage profileImage;
public SlashBannerCommand(@NotNull ProfileImage profileImage)
{
this.profileImage = profileImage;
}
@Override
public CommandData getSlashCommandData()
{
@@ -44,13 +53,13 @@ public class SlashBannerCommand extends SlashCommandImpl
OptionMapping sizeArg = event.getOption("size");
if (sizeArg != null)
{
resolution = ProfileImage.parseResolution(sizeArg.getAsInt());
resolution = profileImage.parseResolution(sizeArg.getAsInt());
} else
{
resolution = ProfileImage.parseResolution(512);
resolution = profileImage.parseResolution(512);
}
MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.BANNER);
MessageResponse response = profileImage.buildResponse(resolution, user, ProfileImage.ImageType.BANNER);
if (response.content() != null)
{
event.getHook().editOriginal(response.content()).queue();

View File

@@ -9,20 +9,29 @@ import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.Cache;
import wtf.beatrice.hidekobot.commands.base.ClearChat;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashClearCommand extends SlashCommandImpl
{
private final ClearChat clearChat;
public SlashClearCommand(@Autowired ClearChat clearChat)
{
this.clearChat = clearChat;
}
@Override
public CommandData getSlashCommandData()
{
return Commands.slash(ClearChat.getLabel(),
ClearChat.getDescription())
return Commands.slash(clearChat.getLabel(),
clearChat.getDescription())
.addOption(OptionType.INTEGER, "amount", "The amount of messages to delete.")
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(ClearChat.getPermission()));
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(clearChat.getPermission()));
}
@Override
@@ -32,7 +41,7 @@ public class SlashClearCommand extends SlashCommandImpl
event.deferReply().queue();
// check if user is trying to run command in dms.
String error = ClearChat.checkDMs(event.getChannel());
String error = clearChat.checkDMs(event.getChannel());
if (error != null)
{
event.getHook().editOriginal(error).queue();
@@ -46,9 +55,9 @@ public class SlashClearCommand extends SlashCommandImpl
int toDeleteAmount = amountOption == null ? 1 : amountOption.getAsInt();
// cap the amount to avoid abuse.
if (toDeleteAmount > ClearChat.getMaxAmount()) toDeleteAmount = 0;
if (toDeleteAmount > clearChat.getMaxAmount()) toDeleteAmount = 0;
error = ClearChat.checkDeleteAmount(toDeleteAmount);
error = clearChat.checkDeleteAmount(toDeleteAmount);
if (error != null)
{
event.getHook().editOriginal(error).queue();
@@ -60,15 +69,15 @@ public class SlashClearCommand extends SlashCommandImpl
Message botMessage = event.getHook().editOriginal(content).complete();
// actually delete the messages.
int deleted = ClearChat.delete(toDeleteAmount,
int deleted = clearChat.delete(toDeleteAmount,
event.getInteraction().getIdLong(),
event.getChannel());
// get a nicely formatted message that logs the deletion of messages.
content = ClearChat.parseAmount(deleted);
content = clearChat.parseAmount(deleted);
// edit the message text and attach a button.
Button dismiss = ClearChat.getDismissButton();
Button dismiss = clearChat.getDismissButton();
botMessage = botMessage.editMessage(content).setActionRow(dismiss).complete();
// add the message to database.

View File

@@ -4,11 +4,20 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.CoinFlip;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashCoinFlipCommand extends SlashCommandImpl
{
private final CoinFlip coinFlip;
public SlashCoinFlipCommand(@Autowired CoinFlip coinFlip)
{
this.coinFlip = coinFlip;
}
@Override
public CommandData getSlashCommandData()
@@ -21,14 +30,14 @@ public class SlashCoinFlipCommand extends SlashCommandImpl
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
{
// perform coin flip
event.reply(CoinFlip.genRandom())
.addActionRow(CoinFlip.getReflipButton())
event.reply(coinFlip.genRandom())
.addActionRow(coinFlip.getReflipButton())
.queue((interaction) ->
{
// set the command as expiring and restrict it to the user who ran it
interaction.retrieveOriginal().queue((message) ->
{
CoinFlip.trackAndRestrict(message, event.getUser());
coinFlip.trackAndRestrict(message, event.getUser());
}, (error) -> {
});
}, (error) -> {

View File

@@ -6,12 +6,21 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.DiceRoll;
import wtf.beatrice.hidekobot.objects.MessageResponse;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashDiceRollCommand extends SlashCommandImpl
{
private final DiceRoll diceRoll;
public SlashDiceRollCommand(@NotNull DiceRoll diceRoll)
{
this.diceRoll = diceRoll;
}
@Override
public CommandData getSlashCommandData()
{
@@ -37,7 +46,7 @@ public class SlashDiceRollCommand extends SlashCommandImpl
String[] args = messageContent.split("\\s");
MessageResponse response = DiceRoll.buildResponse(event.getUser(), args);
MessageResponse response = diceRoll.buildResponse(event.getUser(), args);
if (response.content() != null)
{

View File

@@ -10,11 +10,19 @@ import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.Invite;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashInviteCommand extends SlashCommandImpl
{
private final Invite invite;
public SlashInviteCommand(@NotNull Invite invite)
{
this.invite = invite;
}
@Override
public CommandData getSlashCommandData()
@@ -36,8 +44,8 @@ public class SlashInviteCommand extends SlashCommandImpl
}
replyCallbackAction.queue();
MessageEmbed inviteEmbed = Invite.generateEmbed();
Button inviteButton = Invite.getInviteButton();
MessageEmbed inviteEmbed = invite.generateEmbed();
Button inviteButton = invite.getInviteButton();
WebhookMessageEditAction<Message> reply =
event.getHook()

View File

@@ -7,11 +7,22 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.UserPunishment;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashKickCommand extends SlashCommandImpl
{
private final UserPunishment userPunishment;
public SlashKickCommand(@Autowired UserPunishment userPunishment)
{
this.userPunishment = userPunishment;
}
@Override
public CommandData getSlashCommandData()
{
@@ -31,6 +42,6 @@ public class SlashKickCommand extends SlashCommandImpl
@Override
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
{
UserPunishment.handle(event, UserPunishment.PunishmentType.KICK);
userPunishment.handle(event, UserPunishment.PunishmentType.KICK);
}
}

View File

@@ -8,11 +8,20 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.LoveCalculator;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashLoveCalculatorCommand extends SlashCommandImpl
{
private final LoveCalculator loveCalculator;
public SlashLoveCalculatorCommand(@NotNull LoveCalculator loveCalculator)
{
this.loveCalculator = loveCalculator;
}
@Override
public CommandData getSlashCommandData()
{
@@ -57,7 +66,7 @@ public class SlashLoveCalculatorCommand extends SlashCommandImpl
secondUser = event.getUser();
}
MessageEmbed embed = LoveCalculator.buildEmbedAndCacheResult(event.getUser(), firstUser, secondUser);
MessageEmbed embed = loveCalculator.buildEmbedAndCacheResult(event.getUser(), firstUser, secondUser);
event.replyEmbeds(embed).queue();
}
}

View File

@@ -7,16 +7,25 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.MagicBall;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashMagicBallCommand extends SlashCommandImpl
{
private final MagicBall magicBall;
public SlashMagicBallCommand(@NotNull MagicBall magicBall)
{
this.magicBall = magicBall;
}
@Override
public CommandData getSlashCommandData()
{
return Commands.slash(MagicBall.getLabels().get(0),
return Commands.slash(magicBall.getLabels().get(0),
"Ask a question to the magic ball.")
.addOption(OptionType.STRING, "question",
"The question to ask.",
@@ -43,7 +52,7 @@ public class SlashMagicBallCommand extends SlashCommandImpl
return;
}
MessageEmbed response = MagicBall.generateEmbed(question, event.getUser());
MessageEmbed response = magicBall.generateEmbed(question, event.getUser());
event.replyEmbeds(response).queue();
}
}

View File

@@ -8,11 +8,20 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.Say;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashSayCommand extends SlashCommandImpl
{
private final Say say;
public SlashSayCommand(@NotNull Say say)
{
this.say = say;
}
@Override
public CommandData getSlashCommandData()
{
@@ -22,7 +31,7 @@ public class SlashSayCommand extends SlashCommandImpl
"The message to send.",
true,
false)
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Say.getPermission()));
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(say.getPermission()));
}
@Override

View File

@@ -7,11 +7,22 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import wtf.beatrice.hidekobot.commands.base.UserPunishment;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
@Component
public class SlashTimeoutCommand extends SlashCommandImpl
{
private final UserPunishment userPunishment;
public SlashTimeoutCommand(@Autowired UserPunishment userPunishment)
{
this.userPunishment = userPunishment;
}
@Override
public CommandData getSlashCommandData()
{
@@ -35,6 +46,6 @@ public class SlashTimeoutCommand extends SlashCommandImpl
@Override
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
{
UserPunishment.handle(event, UserPunishment.PunishmentType.TIMEOUT);
userPunishment.handle(event, UserPunishment.PunishmentType.TIMEOUT);
}
}