forked from Fascinated/Bat
cleanup features and move all misc commands into a base feature
This commit is contained in:
@ -20,6 +20,11 @@ public abstract class Feature {
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The description of the feature
|
||||
*/
|
||||
public final boolean canBeDisabled;
|
||||
|
||||
/**
|
||||
* The category of the feature
|
||||
*/
|
||||
@ -32,7 +37,10 @@ public abstract class Feature {
|
||||
* @param command The command to register
|
||||
*/
|
||||
public void registerCommand(@NonNull CommandService commandService, @NonNull BatCommand command) {
|
||||
command.setCategory(category);
|
||||
// If the command using the default category then set the category to the feature's category
|
||||
if (command.getCategory() == Category.GENERAL) {
|
||||
command.setCategory(this.category);
|
||||
}
|
||||
command.setFeature(this);
|
||||
commandService.registerCommand(command);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class AfkFeature extends Feature {
|
||||
public AfkFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
|
||||
super("AFK", Category.GENERAL);
|
||||
super("AFK", true, Category.GENERAL);
|
||||
|
||||
registerCommand(commandService, context.getBean(AfkCommand.class));
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import org.springframework.stereotype.Component;
|
||||
public class AutoRoleFeature extends Feature {
|
||||
@Autowired
|
||||
public AutoRoleFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
|
||||
super("Auto Role", Category.SERVER);
|
||||
super("Auto Role",true, Category.SERVER);
|
||||
|
||||
registerCommand(commandService, context.getBean(AutoRoleCommand.class));
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
package cc.fascinated.bat.features.base;
|
||||
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
import cc.fascinated.bat.features.base.commands.botadmin.premium.PremiumAdminCommand;
|
||||
import cc.fascinated.bat.features.base.commands.fun.image.ImageCommand;
|
||||
import cc.fascinated.bat.features.base.commands.general.*;
|
||||
import cc.fascinated.bat.features.base.commands.general.avatar.AvatarCommand;
|
||||
import cc.fascinated.bat.features.base.commands.general.banner.BannerCommand;
|
||||
import cc.fascinated.bat.features.base.commands.server.MemberCountCommand;
|
||||
import cc.fascinated.bat.features.base.commands.server.PremiumCommand;
|
||||
import cc.fascinated.bat.features.base.commands.server.channel.ChannelCommand;
|
||||
import cc.fascinated.bat.features.base.commands.server.feature.FeatureCommand;
|
||||
import cc.fascinated.bat.service.CommandService;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
public class BaseFeature extends Feature {
|
||||
@Autowired
|
||||
public BaseFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
|
||||
super("Base", false, Category.GENERAL);
|
||||
|
||||
super.registerCommand(commandService, context.getBean(PremiumCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(PremiumAdminCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(MemberCountCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(ChannelCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(VoteCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(PingCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(InviteCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(HelpCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(BotStatsCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(BannerCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(AvatarCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(ImageCommand.class));
|
||||
super.registerCommand(commandService, context.getBean(FeatureCommand.class));
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cc.fascinated.bat.features.base.commands.botadmin.premium;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
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 = "premiumadmin", description = "Set a guild as premium", botOwnerOnly = true, category = Category.BOT_ADMIN)
|
||||
public class PremiumAdminCommand extends BatCommand {
|
||||
@Autowired
|
||||
public PremiumAdminCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(SetSubCommand.class));
|
||||
super.addSubCommand(context.getBean(RemoveSubCommand.class));
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package cc.fascinated.bat.features.base.commands.botadmin.premium;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.GuildService;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "remove", description = "Remove premium from a guild")
|
||||
public class RemoveSubCommand extends BatSubCommand {
|
||||
private final GuildService guildService;
|
||||
|
||||
@Autowired
|
||||
public RemoveSubCommand(GuildService guildService) {
|
||||
this.guildService = guildService;
|
||||
super.addOption(OptionType.STRING, "guild", "The guild id to set as premium", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
OptionMapping guildOption = interaction.getOption("guild");
|
||||
if (guildOption == null) {
|
||||
interaction.reply("Please provide a guild id").queue();
|
||||
return;
|
||||
}
|
||||
String guildId = guildOption.getAsString();
|
||||
BatGuild batGuild = guildService.getGuild(guildId);
|
||||
if (batGuild == null) {
|
||||
interaction.reply("The guild with the id %s does not exist".formatted(guildId)).queue();
|
||||
return;
|
||||
}
|
||||
BatGuild.Premium premium = batGuild.getPremium();
|
||||
if (!premium.hasPremium()) {
|
||||
interaction.reply("The guild does not have premium").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
premium.removePremium();
|
||||
guildService.saveGuild(batGuild);
|
||||
interaction.reply("The guild **%s** has had its premium removed".formatted(guild.getName())).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package cc.fascinated.bat.features.base.commands.botadmin.premium;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.GuildService;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "set", description = "Adds premium to a guild")
|
||||
public class SetSubCommand extends BatSubCommand {
|
||||
private final GuildService guildService;
|
||||
|
||||
@Autowired
|
||||
public SetSubCommand(GuildService guildService) {
|
||||
this.guildService = guildService;
|
||||
super.addOption(OptionType.STRING, "guild", "The guild id to set as premium", true);
|
||||
super.addOption(OptionType.BOOLEAN, "infinite", "Whether the premium length should be infinite", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
OptionMapping guildOption = interaction.getOption("guild");
|
||||
if (guildOption == null) {
|
||||
interaction.reply("Please provide a guild id").queue();
|
||||
return;
|
||||
}
|
||||
String guildId = guildOption.getAsString();
|
||||
OptionMapping infiniteOption = interaction.getOption("infinite");
|
||||
if (infiniteOption == null) {
|
||||
interaction.reply("Please provide whether the premium length should be infinite").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean infinite = infiniteOption.getAsBoolean();
|
||||
BatGuild batGuild = guildService.getGuild(guildId);
|
||||
if (batGuild == null) {
|
||||
interaction.reply("The guild with the id %s does not exist".formatted(guildId)).queue();
|
||||
return;
|
||||
}
|
||||
BatGuild.Premium premium = batGuild.getPremium();
|
||||
if (!infinite) {
|
||||
premium.addTime();
|
||||
} else {
|
||||
premium.addInfiniteTime();
|
||||
}
|
||||
guildService.saveGuild(batGuild);
|
||||
if (!infinite) {
|
||||
interaction.reply("The guild **%s** has been set as premium until <t:%s>".formatted(guild.getName(), premium.getExpiresAt().toInstant().toEpochMilli() / 1000)).queue();
|
||||
} else {
|
||||
interaction.reply("The guild **%s** has been set as premium indefinitely".formatted(guild.getName())).queue();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package cc.fascinated.bat.features.base.commands.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.model.token.thecatapi.CatImageToken;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@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);
|
||||
if (responseEntity == null || responseEntity.length == 0) {
|
||||
interaction.reply("Failed to get a cat image!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setAuthor("Here's a random cat image!")
|
||||
.setImage(responseEntity[0].getUrl())
|
||||
.build()).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package cc.fascinated.bat.features.base.commands.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.model.token.dogceo.RandomImage;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@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);
|
||||
if (responseEntity == null) {
|
||||
interaction.reply("Failed to get a dog image!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setAuthor("Here's a random dog image!")
|
||||
.setImage(responseEntity.getMessage())
|
||||
.build()).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package cc.fascinated.bat.features.base.commands.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.model.token.randomd.RandomDuck;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "duck", description = "Get a random duck image")
|
||||
public class DuckSubCommand extends BatSubCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
RandomDuck responseEntity = WebRequest.getAsEntity("https://random-d.uk/api/v2/random", RandomDuck.class);
|
||||
if (responseEntity == null) {
|
||||
interaction.reply("Failed to get a duck image!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setAuthor("Here's a random duck image!")
|
||||
.setImage(responseEntity.getUrl())
|
||||
.build()).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package cc.fascinated.bat.features.base.commands.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.model.token.randomfox.RandomFoxToken;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component
|
||||
@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);
|
||||
if (responseEntity == null) {
|
||||
interaction.reply("Failed to get a fox image!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setAuthor("Here's a random fox image!")
|
||||
.setImage(responseEntity.getImage())
|
||||
.build()).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package cc.fascinated.bat.features.base.commands.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
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, category = Category.FUN)
|
||||
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));
|
||||
super.addSubCommand(context.getBean(DuckSubCommand.class));
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package cc.fascinated.bat.features.base.commands.general;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.NumberFormatter;
|
||||
import cc.fascinated.bat.common.TimeUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.DiscordService;
|
||||
import cc.fascinated.bat.service.GuildService;
|
||||
import cc.fascinated.bat.service.UserService;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "botstats", description = "Shows the bot statistics", guildOnly = false)
|
||||
public class BotStatsCommand extends BatCommand {
|
||||
private final GuildService guildService;
|
||||
private final UserService userService;
|
||||
private final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
|
||||
|
||||
@Autowired
|
||||
public BotStatsCommand(@NonNull GuildService guildService, @NonNull UserService userService) {
|
||||
this.guildService = guildService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
JDA jda = DiscordService.JDA;
|
||||
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed().setDescription(
|
||||
"**Bot Statistics**\n" +
|
||||
"➜ Guilds: **%s**\n".formatted(NumberFormatter.format(jda.getGuilds().size())) +
|
||||
"➜ Users: **%s**\n".formatted(NumberFormatter.format(jda.getUsers().size())) +
|
||||
"➜ Gateway Ping: **%sms**\n".formatted(jda.getGatewayPing()) +
|
||||
"\n" +
|
||||
"**Bat Statistics**\n" +
|
||||
"➜ Uptime: **%s**\n".formatted(TimeUtils.format(bean.getUptime())) +
|
||||
"➜ Cached Guilds: **%s**\n".formatted(NumberFormatter.format(guildService.getGuilds().size())) +
|
||||
"➜ Cached Users: **%s**".formatted(NumberFormatter.format(userService.getUsers().size()))
|
||||
).build()).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
package cc.fascinated.bat.features.base.commands.general;
|
||||
|
||||
import cc.fascinated.bat.Consts;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.event.EventListener;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.CommandService;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
|
||||
import net.dv8tion.jda.api.interactions.components.selections.SelectOption;
|
||||
import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "help", description = "View the bots command categories.", guildOnly = false)
|
||||
public class HelpCommand extends BatCommand implements EventListener {
|
||||
private final CommandService commandService;
|
||||
|
||||
@Autowired
|
||||
public HelpCommand(@NonNull CommandService commandService) {
|
||||
this.commandService = commandService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
interaction.replyEmbeds(createHomeEmbed()).addComponents(createHomeActions()).queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStringSelectInteraction(BatGuild guild, @NonNull BatUser user, @NonNull StringSelectInteractionEvent event) {
|
||||
String item = event.getSelectedOptions().get(0).getValue();
|
||||
if (item.equalsIgnoreCase("home")) {
|
||||
event.editMessageEmbeds(createHomeEmbed()).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
Category category = Category.getByName(item);
|
||||
if (category == null) {
|
||||
event.reply("Invalid category selected.").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
String commands = "";
|
||||
List<BatCommand> categoryCommands = commandService.getCommandsByCategory(category, true);
|
||||
if (categoryCommands.isEmpty()) {
|
||||
commands = "No commands available in this category.";
|
||||
} else {
|
||||
for (BatCommand command : categoryCommands) {
|
||||
if (!command.getSubCommands().isEmpty()) {
|
||||
for (Map.Entry<String, BatSubCommand> entry : command.getSubCommands().entrySet()) {
|
||||
BatSubCommand subCommand = entry.getValue();
|
||||
SubcommandData commandData = subCommand.getCommandData();
|
||||
commands += "</%s %s:%s> - %s\n".formatted(
|
||||
command.getCommandInfo().name(),
|
||||
commandData.getName(),
|
||||
subCommand.getCommandSnowflake(),
|
||||
commandData.getDescription()
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
commands += "</%s:%s> - %s\n".formatted(
|
||||
command.getCommandInfo().name(),
|
||||
command.getCommandSnowflake(),
|
||||
command.getCommandInfo().description()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int subCommands = categoryCommands.stream().mapToInt(command -> command.getSubCommands().size()).sum();
|
||||
event.editMessageEmbeds(EmbedUtils.genericEmbed()
|
||||
.setAuthor("%s Category".formatted(category.getName()))
|
||||
.setDescription("%s command%s (with %s sub-command%s)\n\n**Commands:**\n%s".formatted(
|
||||
categoryCommands.size(),
|
||||
categoryCommands.size() == 1 ? "" : "s",
|
||||
subCommands,
|
||||
subCommands == 1 ? "" : "s",
|
||||
commands
|
||||
)).build()).queue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the home embed for the help command
|
||||
*
|
||||
* @return The home embed
|
||||
*/
|
||||
private MessageEmbed createHomeEmbed() {
|
||||
String categories = "";
|
||||
for (Category category : Category.getCategories()) {
|
||||
long commandCount = commandService.getCommandsByCategory(category, true).size();
|
||||
categories += "➜ %s - **%s Command%s**\n".formatted(
|
||||
category.getName(),
|
||||
commandCount,
|
||||
commandCount == 1 ? "" : "s"
|
||||
);
|
||||
}
|
||||
|
||||
return EmbedUtils.genericEmbed()
|
||||
.setDescription("Here are the available command categories: \n\n" + categories)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the home actions for the help command
|
||||
*
|
||||
* @return The layout components
|
||||
*/
|
||||
private LayoutComponent[] createHomeActions() {
|
||||
List<SelectOption> options = new ArrayList<>();
|
||||
options.add(SelectOption.of("Home", "home").withEmoji(Emoji.fromUnicode("U+1F3E0")));
|
||||
options.addAll(Category.getCategories().stream().map(category ->
|
||||
SelectOption.of(category.getName(), category.getName()).withEmoji(category.getEmoji()))
|
||||
.toList());
|
||||
|
||||
return new LayoutComponent[]{
|
||||
ActionRow.of(
|
||||
Button.of(ButtonStyle.LINK, Consts.INVITE_URL, "Invite"),
|
||||
Button.of(ButtonStyle.LINK, Consts.SUPPORT_INVITE_URL, "Support")
|
||||
),
|
||||
ActionRow.of(
|
||||
StringSelectMenu.create("help-menu")
|
||||
.addOptions(options)
|
||||
.build()
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cc.fascinated.bat.features.base.commands.general;
|
||||
|
||||
import cc.fascinated.bat.Consts;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "invite", description = "Invite the bot to your server!", guildOnly = false)
|
||||
public class InviteCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setDescription("You can invite the bot to your server by clicking [here](%s)".formatted(Consts.INVITE_URL))
|
||||
.build())
|
||||
.setEphemeral(true)
|
||||
.queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cc.fascinated.bat.features.base.commands.general;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.DiscordService;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "ping", description = "Gets the ping of the bot", guildOnly = false)
|
||||
public class PingCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
long time = System.currentTimeMillis();
|
||||
interaction.reply("Pinging...").queue(response -> {
|
||||
response.editOriginal("Gateway response time: `%sms`\nAPI response time `%sms`".formatted(
|
||||
DiscordService.JDA.getGatewayPing(),
|
||||
System.currentTimeMillis() - time
|
||||
)).queue();
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package cc.fascinated.bat.features.base.commands.general;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "vote", description = "Vote for the bot", guildOnly = false)
|
||||
public class VoteCommand extends BatCommand {
|
||||
private static final String[] VOTE_LINKS = new String[]{
|
||||
"https://top.gg/bot/1254161119975833652/vote"
|
||||
};
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("You can vote for the bot by clicking the following links:\n\n");
|
||||
for (String link : VOTE_LINKS) {
|
||||
builder.append("%s\n".formatted(link));
|
||||
}
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setDescription(builder.toString())
|
||||
.build()
|
||||
).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package cc.fascinated.bat.features.base.commands.general.avatar;
|
||||
|
||||
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 Nick (okNick)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "avatar", description = "View the avatar of the guild or a user", guildOnly = false)
|
||||
public class AvatarCommand extends BatCommand {
|
||||
@Autowired
|
||||
public AvatarCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(GuildSubCommand.class));
|
||||
super.addSubCommand(context.getBean(UserSubCommand.class));
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package cc.fascinated.bat.features.base.commands.general.avatar;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import net.dv8tion.jda.api.utils.ImageProxy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component("avatar:guild.sub")
|
||||
@CommandInfo(name = "guild", description = "View the avatar of the guild")
|
||||
public class GuildSubCommand extends BatSubCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
ImageProxy icon = guild.getDiscordGuild().getIcon();
|
||||
|
||||
if (icon == null) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("**%s** does not have an avatar!".formatted(guild.getName()))
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setAuthor("%s's Avatar".formatted(guild.getName()), null, guild.getDiscordGuild().getIconUrl())
|
||||
.setImage(icon.getUrl(4096))
|
||||
.build()
|
||||
).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package cc.fascinated.bat.features.base.commands.general.avatar;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
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 org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component("avatar:user.sub")
|
||||
@CommandInfo(name = "user", description = "View the avatar of a user", guildOnly = false)
|
||||
public class UserSubCommand extends BatSubCommand {
|
||||
public UserSubCommand() {
|
||||
super.addOption(OptionType.USER, "user", "The user to view the avatar of", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
OptionMapping userOption = interaction.getOption("user");
|
||||
if (userOption == null) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("You must provide a user to view the avatar of!")
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
User target = userOption.getAsUser();
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setAuthor("%s's Avatar".formatted(target.getName()), null, target.getEffectiveAvatarUrl())
|
||||
.setImage(target.getEffectiveAvatarUrl())
|
||||
.build()
|
||||
).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package cc.fascinated.bat.features.base.commands.general.banner;
|
||||
|
||||
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 Nick (okNick)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "banner", description = "View the banner of the guild or a user", guildOnly = false)
|
||||
public class BannerCommand extends BatCommand {
|
||||
@Autowired
|
||||
public BannerCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(GuildSubCommand.class));
|
||||
super.addSubCommand(context.getBean(UserSubCommand.class));
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package cc.fascinated.bat.features.base.commands.general.banner;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import net.dv8tion.jda.api.utils.ImageProxy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component("banner:guild.sub")
|
||||
@CommandInfo(name = "guild", description = "View the banner of the guild")
|
||||
public class GuildSubCommand extends BatSubCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
ImageProxy banner = guild.getDiscordGuild().getBanner();
|
||||
if (banner == null) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("**%s** does not have a banner!".formatted(guild.getName()))
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setAuthor("%s's Banner".formatted(guild.getName()))
|
||||
.setImage(banner.getUrl(512))
|
||||
.build()
|
||||
).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cc.fascinated.bat.features.base.commands.general.banner;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
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.utils.ImageProxy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component("banner:user.sub")
|
||||
@CommandInfo(name = "user", description = "View the banner of a user", guildOnly = false)
|
||||
public class UserSubCommand extends BatSubCommand {
|
||||
public UserSubCommand() {
|
||||
super.addOption(OptionType.USER, "user", "The user to view the banner of", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
OptionMapping userOption = interaction.getOption("user");
|
||||
if (userOption == null) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("You must provide a user to view the banner of!")
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
User target = userOption.getAsUser();
|
||||
ImageProxy banner = target.retrieveProfile().complete().getBanner();
|
||||
if (banner == null) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("**%s** does not have a banner!".formatted(target.getName()))
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setAuthor("%s's Banner".formatted(target.getName()))
|
||||
.setImage(banner.getUrl(512))
|
||||
.build()
|
||||
).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package cc.fascinated.bat.features.base.commands.server;
|
||||
|
||||
import cc.fascinated.bat.Emojis;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.NumberFormatter;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.OnlineStatus;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "membercount", description = "View the member count of the server!")
|
||||
public class MemberCountCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
EmbedBuilder embed = EmbedUtils.genericEmbed().setAuthor("Member Count");
|
||||
Guild discordGuild = guild.getDiscordGuild();
|
||||
int totalMembers = 0, totalUsers = 0, totalBots = 0;
|
||||
Map<OnlineStatus, Integer> memberCounts = new HashMap<>();
|
||||
for (Member guildMember : discordGuild.getMembers()) {
|
||||
OnlineStatus status = guildMember.getOnlineStatus();
|
||||
memberCounts.put(status, memberCounts.getOrDefault(status, 0) + 1);
|
||||
|
||||
if (guildMember.getUser().isBot()) {
|
||||
totalBots++;
|
||||
} else {
|
||||
totalUsers++;
|
||||
}
|
||||
totalMembers++;
|
||||
}
|
||||
|
||||
embed.setDescription("""
|
||||
Total Members: `%s`
|
||||
Total Users: `%s`
|
||||
Total Bots: `%s`
|
||||
\s
|
||||
%s Online: `%s`
|
||||
%s Idle: `%s`
|
||||
%s Do Not Disturb: `%s`
|
||||
%s Offline: `%s`""".formatted(
|
||||
NumberFormatter.format(totalMembers),
|
||||
NumberFormatter.format(totalUsers),
|
||||
NumberFormatter.format(totalBots),
|
||||
Emojis.ONLINE_EMOJI,
|
||||
NumberFormatter.format(memberCounts.getOrDefault(OnlineStatus.ONLINE, 0)),
|
||||
Emojis.IDLE_EMOJI,
|
||||
NumberFormatter.format(memberCounts.getOrDefault(OnlineStatus.IDLE, 0)),
|
||||
Emojis.DND_EMOJI,
|
||||
NumberFormatter.format(memberCounts.getOrDefault(OnlineStatus.DO_NOT_DISTURB, 0)),
|
||||
Emojis.OFFLINE_EMOJI,
|
||||
NumberFormatter.format(memberCounts.getOrDefault(OnlineStatus.OFFLINE, 0))));
|
||||
interaction.replyEmbeds(embed.build()).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package cc.fascinated.bat.features.base.commands.server;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "premium", description = "View the premium information for the guild", requiredPermissions = Permission.ADMINISTRATOR)
|
||||
public class PremiumCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
BatGuild.Premium premium = guild.getPremium();
|
||||
EmbedBuilder embed = EmbedUtils.genericEmbed().setAuthor("Premium Information");
|
||||
if (premium.hasPremium()) {
|
||||
embed.addField("Premium", premium.hasPremium() ? "Yes" : "No", true);
|
||||
embed.addField("Started", "<t:%d>".formatted(premium.getActivatedAt().toInstant().toEpochMilli() / 1000), true);
|
||||
embed.addField("Expires", premium.isInfinite() ? "Never" : "<t:%d>"
|
||||
.formatted(premium.getExpiresAt().toInstant().toEpochMilli() / 1000), true);
|
||||
} else {
|
||||
embed.setDescription("The guild does not have premium");
|
||||
}
|
||||
interaction.replyEmbeds(embed.build()).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package cc.fascinated.bat.features.base.commands.server.channel;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
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 Nick (okNick)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "channel", description = "View or set information about a channel", category = Category.SERVER)
|
||||
public class ChannelCommand extends BatCommand {
|
||||
@Autowired
|
||||
public ChannelCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(ViewTopicSubCommand.class));
|
||||
super.addSubCommand(context.getBean(SetTopicSubCommand.class));
|
||||
super.addSubCommand(context.getBean(RemoveTopicSubCommand.class));
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package cc.fascinated.bat.features.base.commands.server.channel;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.Channel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "removetopic", description = "Remove the topic of a channel", requiredPermissions = Permission.MANAGE_CHANNEL)
|
||||
public class RemoveTopicSubCommand extends BatSubCommand {
|
||||
public RemoveTopicSubCommand() {
|
||||
super.addOption(OptionType.CHANNEL, "channel", "The channel to remove the topic of", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
Channel target = interaction.getOption("channel") == null ? channel : interaction.getOption("channel").getAsChannel();
|
||||
if (!(target instanceof TextChannel textChannel)) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("<#%s> is not a text channel!".formatted(target.getId()))
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
if (textChannel.getTopic() == null) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("<#%s> does not have a topic!".formatted(textChannel.getId()))
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
textChannel.getManager().setTopic(null).queue();
|
||||
interaction.replyEmbeds(EmbedUtils.successEmbed()
|
||||
.setDescription("Successfully removed the topic of <#%s>".formatted(textChannel.getId()))
|
||||
.build()
|
||||
).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cc.fascinated.bat.features.base.commands.server.channel;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.Channel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "settopic", description = "Set the topic of a channel", requiredPermissions = Permission.MANAGE_CHANNEL)
|
||||
public class SetTopicSubCommand extends BatSubCommand {
|
||||
public SetTopicSubCommand() {
|
||||
super.addOption(OptionType.STRING, "topic", "The topic to set", true);
|
||||
super.addOption(OptionType.CHANNEL, "channel", "The channel to set the topic of", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
Channel target = interaction.getOption("channel") == null ? channel : interaction.getOption("channel").getAsChannel();
|
||||
if (!(target instanceof TextChannel textChannel)) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("<#%s> is not a text channel!".formatted(target.getId()))
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
String topic = interaction.getOption("topic").getAsString();
|
||||
if (topic.length() > 1024) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("The topic must be 1024 characters or less!")
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
textChannel.getManager().setTopic(topic).queue();
|
||||
interaction.replyEmbeds(EmbedUtils.successEmbed()
|
||||
.setDescription("Successfully set the topic of <#%s> to: \"%s\"".formatted(textChannel.getId(), topic))
|
||||
.build()
|
||||
).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package cc.fascinated.bat.features.base.commands.server.channel;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.Channel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "viewtopic", description = "View the topic of a channel")
|
||||
public class ViewTopicSubCommand extends BatSubCommand {
|
||||
public ViewTopicSubCommand() {
|
||||
super.addOption(OptionType.CHANNEL, "channel", "The channel to view the topic of", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
Channel target = interaction.getOption("channel") == null ? channel : interaction.getOption("channel").getAsChannel();
|
||||
if (!(target instanceof TextChannel textChannel)) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("<#%s> is not a text channel!".formatted(target.getId()))
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
String topic = textChannel.getTopic();
|
||||
if (topic == null) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("<#%s> does not have a topic!".formatted(textChannel.getId()))
|
||||
.build())
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
interaction.replyEmbeds(EmbedUtils.genericEmbed()
|
||||
.setDescription("The topic of <#%s> is: \"%s\"".formatted(textChannel.getId(), topic))
|
||||
.build()
|
||||
).queue();
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package cc.fascinated.bat.features.command;
|
||||
package cc.fascinated.bat.features.base.commands.server.feature;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
import cc.fascinated.bat.features.FeatureProfile;
|
||||
import cc.fascinated.bat.features.base.profile.FeatureProfile;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.FeatureService;
|
||||
@ -50,6 +50,13 @@ public class DisableSubCommand extends BatSubCommand {
|
||||
return;
|
||||
}
|
||||
Feature feature = FeatureService.INSTANCE.getFeature(featureName);
|
||||
if (!feature.isCanBeDisabled()) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("The feature `%s` cannot be disabled".formatted(feature.getName()))
|
||||
.build()).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
if (featureProfile.isFeatureDisabled(feature)) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("The feature `%s` is already disabled".formatted(feature.getName()))
|
@ -1,10 +1,10 @@
|
||||
package cc.fascinated.bat.features.command;
|
||||
package cc.fascinated.bat.features.base.commands.server.feature;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
import cc.fascinated.bat.features.FeatureProfile;
|
||||
import cc.fascinated.bat.features.base.profile.FeatureProfile;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.FeatureService;
|
@ -1,6 +1,7 @@
|
||||
package cc.fascinated.bat.features.command;
|
||||
package cc.fascinated.bat.features.base.commands.server.feature;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
@ -12,7 +13,7 @@ import org.springframework.stereotype.Component;
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "feature", description = "Configure features in your guild", requiredPermissions = Permission.ADMINISTRATOR)
|
||||
@CommandInfo(name = "feature", description = "Configure features in your guild", requiredPermissions = Permission.ADMINISTRATOR, category = Category.SERVER)
|
||||
public class FeatureCommand extends BatCommand {
|
||||
@Autowired
|
||||
public FeatureCommand(@NonNull ApplicationContext context) {
|
@ -1,10 +1,10 @@
|
||||
package cc.fascinated.bat.features.command;
|
||||
package cc.fascinated.bat.features.base.commands.server.feature;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
import cc.fascinated.bat.features.FeatureProfile;
|
||||
import cc.fascinated.bat.features.base.profile.FeatureProfile;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.FeatureService;
|
@ -1,6 +1,7 @@
|
||||
package cc.fascinated.bat.features;
|
||||
package cc.fascinated.bat.features.base.profile;
|
||||
|
||||
import cc.fascinated.bat.common.Profile;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
@ -23,7 +23,7 @@ public class BirthdayFeature extends Feature implements EventListener {
|
||||
private final GuildService guildService;
|
||||
|
||||
public BirthdayFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) {
|
||||
super("Birthday", Category.UTILITY);
|
||||
super("Birthday", true, Category.UTILITY);
|
||||
this.guildService = guildService;
|
||||
|
||||
registerCommand(commandService, context.getBean(BirthdayCommand.class));
|
||||
|
@ -2,6 +2,11 @@ package cc.fascinated.bat.features.namehistory;
|
||||
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
import cc.fascinated.bat.features.namehistory.command.NameHistoryCommand;
|
||||
import cc.fascinated.bat.service.CommandService;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -11,7 +16,10 @@ import org.springframework.stereotype.Component;
|
||||
public class NameHistoryFeature extends Feature {
|
||||
public static final int NAME_HISTORY_SIZE = 25;
|
||||
|
||||
public NameHistoryFeature() {
|
||||
super("Name History", Category.UTILITY);
|
||||
@Autowired
|
||||
public NameHistoryFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
|
||||
super("Name History", true,Category.UTILITY);
|
||||
|
||||
super.registerCommand(commandService, context.getBean(NameHistoryCommand.class));
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import org.springframework.stereotype.Component;
|
||||
public class ScoreSaberFeature extends Feature {
|
||||
@Autowired
|
||||
public ScoreSaberFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
|
||||
super("ScoreSaber", Category.BEAT_SABER);
|
||||
super("ScoreSaber", true, Category.BEAT_SABER);
|
||||
|
||||
registerCommand(commandService, context.getBean(ScoreSaberCommand.class));
|
||||
registerCommand(commandService, context.getBean(UserFeedCommand.class));
|
||||
|
@ -6,13 +6,16 @@ import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.SpotifyUtils;
|
||||
import cc.fascinated.bat.exception.BatException;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
import cc.fascinated.bat.features.spotify.command.SpotifyCommand;
|
||||
import cc.fascinated.bat.features.spotify.profile.SpotifyProfile;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.CommandService;
|
||||
import cc.fascinated.bat.service.SpotifyService;
|
||||
import lombok.NonNull;
|
||||
import lombok.SneakyThrows;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import se.michaelthelin.spotify.model_objects.miscellaneous.CurrentlyPlaying;
|
||||
import se.michaelthelin.spotify.model_objects.specification.AlbumSimplified;
|
||||
@ -25,8 +28,10 @@ import se.michaelthelin.spotify.model_objects.specification.Track;
|
||||
@Component
|
||||
public class SpotifyFeature extends Feature {
|
||||
@Autowired
|
||||
public SpotifyFeature() {
|
||||
super("Spotify", Category.MUSIC);
|
||||
public SpotifyFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
|
||||
super("Spotify", true,Category.MUSIC);
|
||||
|
||||
super.registerCommand(commandService, context.getBean(SpotifyCommand.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user