cleanup and acc country flag to ss me and user command

This commit is contained in:
Lee 2024-06-27 16:30:47 +01:00
parent 50b921c66d
commit 406d6b7164
3 changed files with 15 additions and 6 deletions

@ -44,7 +44,7 @@ public class HelpCommand extends BatCommand implements EventListener {
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
String categories = "";
for (Category category : Category.values()) {
long commandCount = commandService.getCommands().values().stream().filter(command -> command.getCategory() == category).count();
long commandCount = commandService.getCommandsByCategory(category).size();
categories += "**%s** - %s Commands\n".formatted(category.getName(), commandCount);
}
@ -76,9 +76,7 @@ public class HelpCommand extends BatCommand implements EventListener {
}
String commands = "";
List<BatCommand> categoryCommands = commandService.getCommands().values().stream()
.filter(command -> command.getCategory() == category)
.toList();
List<BatCommand> categoryCommands = commandService.getCommandsByCategory(category);
if (categoryCommands.isEmpty()) {
commands = "No commands available in this category.";
} else {
@ -105,7 +103,7 @@ public class HelpCommand extends BatCommand implements EventListener {
}
event.editMessageEmbeds(EmbedUtils.genericEmbed()
.setDescription("The available commands in the **%s** category: \n\n%s".formatted(category.getName(), commands))
.setDescription("There is %S commands in the **%s** category: \n\n%s".formatted(categoryCommands.size(), category.getName(), commands))
.build()).queue();
}
}

@ -93,7 +93,7 @@ public class ScoreSaberCommand extends BatCommand {
.addField("PP", NumberUtils.formatNumberCommas(account.getPp()), true)
.addField("Joined", "<t:%s>".formatted(DateUtils.getDateFromString(account.getFirstSeen()).toInstant().toEpochMilli() / 1000), true)
.setTimestamp(LocalDateTime.now())
.setFooter(fetchTime > 3 ? "Fetched in %sms".formatted(fetchTime) : "Cached", null)
.setFooter(fetchTime > 3 ? "Fetched in %sms".formatted(fetchTime) : "Cached", "https://flagcdn.com/h120/%s.png".formatted(account.getCountry().toLowerCase()))
.setColor(Colors.DEFAULT)
.build()).queue();
} catch (RateLimitException ex) {

@ -3,6 +3,7 @@ package cc.fascinated.bat.service;
import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.command.BatCommandExecutor;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.command.Category;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
@ -98,6 +99,16 @@ public class CommandService extends ListenerAdapter {
log.info("Registered all slash commands in {}ms", System.currentTimeMillis() - before);
}
/**
* Gets commands that are in a specific category
*
* @param category The category
* @return The commands
*/
public List<BatCommand> getCommandsByCategory(Category category) {
return commands.values().stream().filter(command -> command.getCategory() == category).toList();
}
@Override
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
Guild discordGuild = event.getGuild();