forked from Fascinated/Bat
merge cat, dog, and fox commands into 1
This commit is contained in:
parent
dc18c9fe7a
commit
f737b7d571
@ -1,7 +1,6 @@
|
||||
package cc.fascinated.bat.command.impl.fun;
|
||||
package cc.fascinated.bat.command.impl.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
@ -18,8 +17,8 @@ import org.springframework.stereotype.Component;
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "cat", description = "Get a random cat image", category = Category.FUN, guildOnly = false)
|
||||
public class CatCommand extends BatCommand {
|
||||
@CommandInfo(name = "cat", description = "Get a random cat image")
|
||||
public class CatSubCommand extends BatSubCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
CatImageToken[] responseEntity = WebRequest.getAsEntity("https://api.thecatapi.com/v1/images/search", CatImageToken[].class);
|
@ -1,7 +1,6 @@
|
||||
package cc.fascinated.bat.command.impl.fun;
|
||||
package cc.fascinated.bat.command.impl.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
@ -18,8 +17,8 @@ import org.springframework.stereotype.Component;
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "dog", description = "Get a random dog image", category = Category.FUN, guildOnly = false)
|
||||
public class DogCommand extends BatCommand {
|
||||
@CommandInfo(name = "dog", description = "Get a random dog image")
|
||||
public class DogSubCommand extends BatSubCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
RandomImage responseEntity = WebRequest.getAsEntity("https://dog.ceo/api/breeds/image/random", RandomImage.class);
|
@ -1,7 +1,6 @@
|
||||
package cc.fascinated.bat.command.impl.fun;
|
||||
package cc.fascinated.bat.command.impl.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
@ -18,8 +17,8 @@ import org.springframework.stereotype.Component;
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "fox", description = "Get a random fox image", category = Category.FUN, guildOnly = false)
|
||||
public class FoxCommand extends BatCommand {
|
||||
@CommandInfo(name = "fox", description = "Get a random fox image")
|
||||
public class FoxSubCommand extends BatSubCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
RandomFoxToken responseEntity = WebRequest.getAsEntity("https://randomfox.ca/floof/", RandomFoxToken.class);
|
@ -0,0 +1,22 @@
|
||||
package cc.fascinated.bat.command.impl.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "image", description = "View a random image", guildOnly = false)
|
||||
public class ImageCommand extends BatCommand {
|
||||
@Autowired
|
||||
public ImageCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(CatSubCommand.class));
|
||||
super.addSubCommand(context.getBean(DogSubCommand.class));
|
||||
super.addSubCommand(context.getBean(FoxSubCommand.class));
|
||||
}
|
||||
}
|
@ -75,8 +75,9 @@ public class CommandService extends ListenerAdapter {
|
||||
|
||||
// Unregister all commands that Discord has but we don't
|
||||
jda.retrieveCommands().complete().forEach(command -> {
|
||||
CommandInfo commandInfo = commands.get(command.getName()).getCommandInfo();
|
||||
if (commands.containsKey(command.getName()) && (commandInfo.category().isHidden() || commandInfo.botOwnerOnly())) {
|
||||
if (commands.containsKey(command.getName())
|
||||
&& (commands.get(command.getName()).getCommandInfo().category().isHidden()
|
||||
|| commands.get(command.getName()).getCommandInfo().botOwnerOnly())) {
|
||||
jda.deleteCommandById(command.getId()).complete(); // Unregister the command on Discord
|
||||
log.info("Unregistered hidden command \"{}\" from Discord", command.getName());
|
||||
return;
|
||||
@ -111,7 +112,7 @@ public class CommandService extends ListenerAdapter {
|
||||
log.error("Unable to find the admin guild to register hidden commands");
|
||||
}
|
||||
|
||||
log.info("Registered all slash commands in {}ms", System.currentTimeMillis() - before);
|
||||
log.info("Registered {} slash commands in {}ms", discordCommands.size(), System.currentTimeMillis() - before);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user