-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added coin command and revamped command manager (a bit)
- Loading branch information
Showing
5 changed files
with
222 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/me/kub94ek/command/impl/commands/CoinCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package me.kub94ek.command.impl.commands; | ||
|
||
import me.kub94ek.command.Command; | ||
import me.kub94ek.command.CommandExecutor; | ||
import me.kub94ek.command.impl.executors.CoinCommandExecutor; | ||
import net.dv8tion.jda.api.interactions.DiscordLocale; | ||
import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
import net.dv8tion.jda.api.interactions.commands.build.Commands; | ||
import net.dv8tion.jda.api.interactions.commands.build.OptionData; | ||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData; | ||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; | ||
|
||
import java.util.Map; | ||
|
||
public class CoinCommand implements Command { | ||
private static final CoinCommandExecutor executor = new CoinCommandExecutor(); | ||
|
||
@Override | ||
public CommandExecutor getExecutor() { | ||
return executor; | ||
} | ||
|
||
@Override | ||
public SlashCommandData getCommand() { | ||
SlashCommandData command = Commands.slash("coin", "Command for managing coins"); | ||
command.addSubcommands( | ||
new SubcommandData("bal", "Shows you your coin balance") | ||
.setDescriptionLocalizations( | ||
Map.of( | ||
DiscordLocale.CZECH, "Ukáže vám váš zůstatek mincí", | ||
DiscordLocale.SPANISH, "Muestra el saldo de monedas" | ||
) | ||
), | ||
new SubcommandData("give", "Gives coins to somebody") | ||
.addOptions( | ||
new OptionData( | ||
OptionType.USER, | ||
"user", "The user to give the coins to", | ||
true | ||
).setDescriptionLocalizations( | ||
Map.of( | ||
DiscordLocale.CZECH, "Komu mince darovat", | ||
DiscordLocale.SPANISH, "A quién regalar las monedas" | ||
) | ||
), | ||
new OptionData( | ||
OptionType.INTEGER, | ||
"coins", "How many coins to give", | ||
true | ||
).setDescriptionLocalizations( | ||
Map.of( | ||
DiscordLocale.CZECH, "Kolik mincí chcete darovat", | ||
DiscordLocale.SPANISH, "Cuántas monedas desea regalar" | ||
) | ||
) | ||
) | ||
.setDescriptionLocalizations( | ||
Map.of( | ||
DiscordLocale.CZECH, "Darujte někomu vaše mince", | ||
DiscordLocale.SPANISH, "Regala sus monedas a alguien" | ||
) | ||
) | ||
); | ||
|
||
|
||
return command; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/me/kub94ek/command/impl/executors/CoinCommandExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package me.kub94ek.command.impl.executors; | ||
|
||
import me.kub94ek.Main; | ||
import me.kub94ek.command.CommandExecutor; | ||
import me.kub94ek.data.database.Database; | ||
import net.dv8tion.jda.api.entities.User; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.interactions.commands.OptionMapping; | ||
|
||
public class CoinCommandExecutor implements CommandExecutor { | ||
@Override | ||
public void executeCommand(SlashCommandInteractionEvent event) { | ||
String memberId = event.getMember().getId(); | ||
Database database = Main.getDatabase(); | ||
|
||
switch (event.getSubcommandName()) { | ||
case "bal" -> event.reply( | ||
"Your balance: " + database.getCoins(memberId) + " coins" | ||
).setEphemeral(true).queue(); | ||
case "give" -> { | ||
OptionMapping userOption = event.getOption("user"); | ||
OptionMapping coinsOption = event.getOption("coins"); | ||
User user = userOption.getAsUser(); | ||
int coins = coinsOption.getAsInt(); | ||
|
||
if (coins > database.getCoins(memberId)) { | ||
event.reply("You don't have enough coins!").setEphemeral(true).queue(); | ||
return; | ||
} | ||
|
||
if (user.isBot() || user.isSystem() || user.getId().equals(memberId)) { | ||
event.reply("Invalid user!").setEphemeral(true).queue(); | ||
return; | ||
} | ||
|
||
database.giveCoins(memberId, user.getId(), coins); | ||
event.reply("Gave " + coins + " coins to <@" + user.getId() + ">").setEphemeral(true).queue(); | ||
|
||
} | ||
} | ||
} | ||
|
||
} |