Skip to content

Commit cfe0c14

Browse files
Add the /economy add and remove commands
1 parent 0433ae6 commit cfe0c14

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/main/java/technobot/commands/economy/EconomyCommand.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package technobot.commands.economy;
22

33
import net.dv8tion.jda.api.Permission;
4+
import net.dv8tion.jda.api.entities.User;
45
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
56
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
67
import net.dv8tion.jda.api.interactions.commands.OptionType;
@@ -28,6 +29,12 @@ public EconomyCommand(TechnoBot bot) {
2829
this.permission = Permission.MANAGE_SERVER;
2930
this.subCommands.add(new SubcommandData("currency", "Set the currency symbol.")
3031
.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)));
3138
}
3239

3340
@Override
@@ -59,6 +66,26 @@ public void execute(SlashCommandInteractionEvent event) {
5966
text = EmbedUtils.BLUE_TICK + " The currency symbol has been reset.";
6067
}
6168
}
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+
}
6289
}
6390
event.getHook().sendMessageEmbeds(EmbedUtils.createDefault(text)).queue();
6491
}

0 commit comments

Comments
 (0)