|
1 | 1 | package technobot.commands.economy; |
2 | 2 |
|
3 | 3 | import net.dv8tion.jda.api.Permission; |
| 4 | +import net.dv8tion.jda.api.entities.User; |
4 | 5 | import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; |
5 | 6 | import net.dv8tion.jda.api.interactions.commands.OptionMapping; |
6 | 7 | import net.dv8tion.jda.api.interactions.commands.OptionType; |
@@ -28,6 +29,12 @@ public EconomyCommand(TechnoBot bot) { |
28 | 29 | this.permission = Permission.MANAGE_SERVER; |
29 | 30 | this.subCommands.add(new SubcommandData("currency", "Set the currency symbol.") |
30 | 31 | .addOptions(new OptionData(OptionType.STRING, "symbol", "The emoji or symbol to set as the currency."))); |
| 32 | + this.subCommands.add(new SubcommandData("add", "Add money to the balance of a user.") |
| 33 | + .addOptions(new OptionData(OptionType.USER, "user", "The user you want to add money to.", true)) |
| 34 | + .addOptions(new OptionData(OptionType.INTEGER, "amount", "The amount of money to add", true))); |
| 35 | + this.subCommands.add(new SubcommandData("remove", "Remove money from the balance of a user.") |
| 36 | + .addOptions(new OptionData(OptionType.USER, "user", "The user you want to remove money from.", true)) |
| 37 | + .addOptions(new OptionData(OptionType.INTEGER, "amount", "The amount of money to remove", true))); |
31 | 38 | } |
32 | 39 |
|
33 | 40 | @Override |
@@ -59,6 +66,26 @@ public void execute(SlashCommandInteractionEvent event) { |
59 | 66 | text = EmbedUtils.BLUE_TICK + " The currency symbol has been reset."; |
60 | 67 | } |
61 | 68 | } |
| 69 | + case "add" -> { |
| 70 | + User user = event.getOption("user").getAsUser(); |
| 71 | + long amount = event.getOption("amount").getAsLong(); |
| 72 | + economyHandler.addMoney(user.getIdLong(), amount); |
| 73 | + String currency = economyHandler.getCurrency() + " **" + EconomyHandler.FORMATTER.format(amount) + "**"; |
| 74 | + text = EmbedUtils.BLUE_TICK + " Successfully added " + currency + " to " + user.getAsMention(); |
| 75 | + } |
| 76 | + case "remove" -> { |
| 77 | + User user = event.getOption("user").getAsUser(); |
| 78 | + long amount = event.getOption("amount").getAsLong(); |
| 79 | + long networth = economyHandler.getNetworth(user.getIdLong()); |
| 80 | + if (amount > networth) { |
| 81 | + text = "You cannot remove more money than a user has!"; |
| 82 | + event.getHook().sendMessageEmbeds(EmbedUtils.createError(text)).queue(); |
| 83 | + return; |
| 84 | + } |
| 85 | + economyHandler.removeMoney(user.getIdLong(), amount); |
| 86 | + String currency = economyHandler.getCurrency() + " **" + EconomyHandler.FORMATTER.format(amount) + "**"; |
| 87 | + text = EmbedUtils.BLUE_TICK + " Successfully removed " + currency + " from " + user.getAsMention(); |
| 88 | + } |
62 | 89 | } |
63 | 90 | event.getHook().sendMessageEmbeds(EmbedUtils.createDefault(text)).queue(); |
64 | 91 | } |
|
0 commit comments