diff --git a/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java b/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java index 55ff0f7c..97f23706 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java +++ b/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java @@ -12,6 +12,7 @@ import com.beanbeanjuice.cafebot.commands.fun.birthday.BirthdayCommand; import com.beanbeanjuice.cafebot.commands.fun.counting.CountingCommand; import com.beanbeanjuice.cafebot.commands.fun.meme.MemeCommand; +import com.beanbeanjuice.cafebot.commands.fun.rate.RateCommand; import com.beanbeanjuice.cafebot.commands.generic.PingCommand; import com.beanbeanjuice.cafebot.commands.generic.*; import com.beanbeanjuice.cafebot.utility.commands.CommandHandler; @@ -171,7 +172,8 @@ private void setupCommands() { new BirthdayCommand(this), new MemeCommand(this), new JokeCommand(this), - new CountingCommand(this) + new CountingCommand(this), + new RateCommand(this) // new EmbedCommand(this) ); @@ -273,6 +275,7 @@ public int getTotalServers() { return this.JDA.getGuilds().size(); } + // TODO: This is only getting cached users. public int getTotalUsers() { return this.JDA.getUsers().size(); } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/ServeCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/ServeCommand.java index 4a3c6459..d3381f49 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/ServeCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/ServeCommand.java @@ -67,7 +67,7 @@ private void handleServe(final SlashCommandInteractionEvent event, final CafeUse .exceptionallyAsync((e) -> { event.getHook().sendMessageEmbeds(Helper.errorEmbed( "Error Serving", - "There was an error serving: " + e.getMessage() + String.format("There was an error serving %s. Is it a real word?", word) )).queue(); return null; }); @@ -119,7 +119,7 @@ public String getName() { @Override public String getDescription() { - return "Serve some words to customers to earn some **bC** (beanCoins)!"; + return "Serve some words to customers to earn some bC (beanCoins)!"; } @Override diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/counting/CountingStatisticsSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/counting/CountingStatisticsSubCommand.java index eea5bec0..ad396c31 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/counting/CountingStatisticsSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/counting/CountingStatisticsSubCommand.java @@ -56,7 +56,7 @@ private int getLeaderboardPlace(final HashMap leade .toList(); for (int i = 0; i < lastNumberArray.size(); i++) { - if (lastNumberArray.get(i).getValue() < information.getLastNumber()) return i; + if (lastNumberArray.get(i).getValue() < information.getLastNumber()) return i + 1; } return lastNumberArray.size(); diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCaffeinatedSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCaffeinatedSubCommand.java new file mode 100644 index 00000000..abc34fdb --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCaffeinatedSubCommand.java @@ -0,0 +1,51 @@ +package com.beanbeanjuice.cafebot.commands.fun.rate; + +import com.beanbeanjuice.cafebot.CafeBot; +import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; +import com.beanbeanjuice.cafebot.utility.helper.Helper; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; + +import java.util.Optional; + +public class RateCaffeinatedSubCommand extends Command implements ISubCommand { + + public RateCaffeinatedSubCommand(CafeBot cafeBot) { + super(cafeBot); + } + + @Override + public void handle(SlashCommandInteractionEvent event) { + Optional userMapping = Optional.ofNullable(event.getOption("user")); + + User user = userMapping.map(OptionMapping::getAsUser).orElse(event.getUser()); + int percentage = Helper.getRandomInteger(0, 101); + + event.getHook().sendMessageEmbeds(Helper.successEmbed( + "☕ Caffeine Rating ☕", + String.format("%s is %d%% caffeinated! %s", user.getAsMention(), percentage, "") + )).mention(user).queue(); + } + + @Override + public String getName() { + return "caffeinated"; + } + + @Override + public String getDescription() { + return "Rate how caffeinated you or someone is!"; + } + + @Override + public OptionData[] getOptions() { + return new OptionData[] { + new OptionData(OptionType.USER, "user", "The person who's caffeine levels you want to see.") + }; + } + +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCommand.java new file mode 100644 index 00000000..3c7664c4 --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCommand.java @@ -0,0 +1,51 @@ +package com.beanbeanjuice.cafebot.commands.fun.rate; + +import com.beanbeanjuice.cafebot.CafeBot; +import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.ICommand; +import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; +import net.dv8tion.jda.api.Permission; + +public class RateCommand extends Command implements ICommand { + + public RateCommand(final CafeBot cafeBot) { + super(cafeBot); + } + + @Override + public String getName() { + return "rate"; + } + + @Override + public String getDescription() { + return "Rate something!"; + } + + @Override + public Permission[] getPermissions() { + return new Permission[0]; + } + + @Override + public boolean isEphemeral() { + return false; + } + + @Override + public boolean isNSFW() { + return false; + } + + @Override + public boolean allowDM() { + return true; + } + + @Override + public ISubCommand[] getSubCommands() { + return new ISubCommand[] { + new RateCaffeinatedSubCommand(cafeBot) + }; + } +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/DefineCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/DefineCommand.java index ada6f303..903814fb 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/DefineCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/DefineCommand.java @@ -15,6 +15,7 @@ public class DefineCommand extends Command implements ICommand { + // TODO: Check if other languages actually work. public DefineCommand(CafeBot cafeBot) { super(cafeBot); } diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/CountingListener.java b/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/CountingListener.java index 8df99006..b5829aa4 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/CountingListener.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/CountingListener.java @@ -23,6 +23,8 @@ public CountingListener(final CafeBot cafeBot) { @Override public void onMessageReceived(final MessageReceivedEvent event) { + if (!event.isFromGuild()) return; + String guildID = event.getGuild().getId(); String channelID = event.getChannel().getId(); diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/sections/cafe/MenuListener.java b/src/main/java/com/beanbeanjuice/cafebot/utility/sections/cafe/MenuListener.java index f113a62e..73b8eb66 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/sections/cafe/MenuListener.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/sections/cafe/MenuListener.java @@ -5,6 +5,7 @@ import com.beanbeanjuice.cafeapi.wrapper.endpoints.cafe.CafeUsersEndpoint; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.helper.Helper; +import com.beanbeanjuice.cafebot.utility.logging.LogLevel; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.IMentionable; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -17,6 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; public class MenuListener extends ListenerAdapter { @@ -37,6 +39,7 @@ public void onEntitySelectInteraction(EntitySelectInteractionEvent event) { if (event.getComponentId().startsWith("menu-entity:")) handlePurchase(event); } + // TODO: Component sometimes disappears. private void handleCategory(final StringSelectInteractionEvent event) { List values = event.getValues(); // the values the user selected String value = values.getFirst(); @@ -45,11 +48,14 @@ private void handleCategory(final StringSelectInteractionEvent event) { boolean isHome = value.equalsIgnoreCase("all"); MessageEmbed menuEmbed = isHome ? menuHandler.getAllMenuEmbed() : menuHandler.getCategoryMenuEmbed(CafeCategory.valueOf(value)); + // TODO: Sometimes replaces after adding the components. event.editMessageEmbeds(menuEmbed).setReplace(true).queue((hook) -> { List rows = new ArrayList<>(); rows.add(ActionRow.of(menuHandler.getAllStringSelectMenu())); if (!isHome) rows.add(ActionRow.of(menuHandler.getItemStringSelectMenu(CafeCategory.valueOf(value)))); - hook.editOriginalComponents(rows).queue(); + hook.editOriginalComponents(rows).delay(1, TimeUnit.SECONDS).queue((ignored) -> { }, (e) -> { // TODO: Check this. + cafeBot.getLogger().log(MenuListener.class, LogLevel.ERROR, "Error Adding Components: " + e, e); + }); }); } @@ -65,7 +71,9 @@ private void handleItem(final StringSelectInteractionEvent event) { List rows = new ArrayList<>(); rows.add(ActionRow.of(menuHandler.getAllStringSelectMenu())); rows.add(ActionRow.of(menuHandler.getItemEntitySelectMenu(itemString))); - hook.editOriginalComponents(rows).queue(); + hook.editOriginalComponents(rows).delay(1, TimeUnit.SECONDS).queue((ignored) -> { }, (e) -> { // TODO: Check this. + cafeBot.getLogger().log(MenuListener.class, LogLevel.ERROR, "Error Adding Components: " + e, e); + }); }); }); }