From fd9fe4ead6c5dc15fd20b11de24156fa2310b157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Mon, 19 Dec 2022 20:38:32 +0100 Subject: [PATCH] Add basic love calculator message command --- .../wtf/beatrice/hidekobot/HidekoBot.java | 1 + .../message/LoveCalculatorCommand.java | 93 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/main/java/wtf/beatrice/hidekobot/commands/message/LoveCalculatorCommand.java diff --git a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java index e085906..96a477e 100644 --- a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java +++ b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java @@ -136,6 +136,7 @@ public class HidekoBot messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.ClearCommand()); messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.DiceRollCommand()); messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.InviteCommand()); + messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.LoveCalculatorCommand()); messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.MagicBallCommand()); messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.SayCommand()); Cache.setMessageCommandListener(messageCommandListener); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/LoveCalculatorCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/LoveCalculatorCommand.java new file mode 100644 index 0000000..daf2389 --- /dev/null +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/LoveCalculatorCommand.java @@ -0,0 +1,93 @@ +package wtf.beatrice.hidekobot.commands.message; + +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.IMentionable; +import net.dv8tion.jda.api.entities.Mentions; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import org.jetbrains.annotations.Nullable; +import wtf.beatrice.hidekobot.Cache; +import wtf.beatrice.hidekobot.HidekoBot; +import wtf.beatrice.hidekobot.commands.base.Say; +import wtf.beatrice.hidekobot.objects.commands.MessageCommand; +import wtf.beatrice.hidekobot.util.RandomUtil; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class LoveCalculatorCommand implements MessageCommand +{ + + + @Override + public LinkedList getCommandLabels() + { + return new LinkedList<>(Arrays.asList("lovecalc", "lovecalculator", "lc")); + } + + @Nullable + @Override + public List getPermissions() { + return null; //anyone can use it + } + + @Override + public boolean passRawArgs() { + return false; + } + + @Override + public void runCommand(MessageReceivedEvent event, String label, String[] args) + { + + Mentions mentionsObj = event.getMessage().getMentions(); + List mentions = mentionsObj.getMentions(); + + + if(args.length == 0 || mentions.isEmpty()) + { + event.getMessage().reply("\uD83D\uDE22 I need to know who to check!").queue(); + return; + } + + User user1, user2; + + String mentionedUserId = mentions.get(0).getId(); + user1 = HidekoBot.getAPI().retrieveUserById(mentionedUserId).complete(); + + if(mentions.size() == 1) + { + user2 = event.getAuthor(); + } else { + mentionedUserId = mentions.get(1).getId(); + user2 = HidekoBot.getAPI().retrieveUserById(mentionedUserId).complete(); + } + + int loveAmount = RandomUtil.getRandomNumber(0, 100); + + String formattedAmount = loveAmount + "%"; + if(loveAmount <= 30) formattedAmount += "... \uD83D\uDE22"; + else if(loveAmount < 60) formattedAmount += "! \uD83E\uDDD0"; + else if(loveAmount < 75) formattedAmount += "!!! \uD83E\uDD73"; + else formattedAmount = "✨ " + formattedAmount + "!!! \uD83D\uDE0D\uD83D\uDCA5"; + + EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setColor(Cache.getBotColor()); + embedBuilder.setAuthor(event.getAuthor().getAsTag(), null, event.getAuthor().getAvatarUrl()); + + embedBuilder.setTitle("Love Calculator"); + embedBuilder.addField("\uD83D\uDC65 People", + user1.getAsMention() + " & " + user2.getAsMention(), + false); + + embedBuilder.addField("❤️\u200D\uD83D\uDD25 Match", + formattedAmount, + false); + + event.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); + + } +}