2022-11-20 18:56:57 +01:00
|
|
|
package wtf.beatrice.hidekobot.commands.slash;
|
2022-11-20 06:04:00 +01:00
|
|
|
|
2022-11-20 22:09:58 +01:00
|
|
|
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
|
|
|
import net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent;
|
2022-11-20 06:04:00 +01:00
|
|
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
2022-11-20 22:09:58 +01:00
|
|
|
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
|
|
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
|
|
|
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
2022-11-20 06:04:00 +01:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import wtf.beatrice.hidekobot.utils.RandomUtil;
|
|
|
|
|
2022-11-20 22:09:58 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2022-11-20 06:04:00 +01:00
|
|
|
public class CoinFlipCommand
|
|
|
|
{
|
|
|
|
|
2022-11-20 22:09:58 +01:00
|
|
|
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
|
|
|
|
{
|
|
|
|
int rand = RandomUtil.getRandomNumber(0, 1);
|
|
|
|
String msg;
|
|
|
|
|
|
|
|
if(rand == 1)
|
|
|
|
{
|
|
|
|
msg = ":coin: It's **Heads**!";
|
|
|
|
} else {
|
|
|
|
msg = "It's **Tails**! :coin:";
|
|
|
|
}
|
|
|
|
|
|
|
|
event.reply(msg)
|
|
|
|
.addActionRow(Button.primary("reflip", "Flip again")
|
|
|
|
.withEmoji(Emoji.fromFormatted("\uD83E\uDE99")) // coin emoji
|
|
|
|
).queue();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void buttonReflip(ButtonInteractionEvent event)
|
2022-11-20 06:04:00 +01:00
|
|
|
{
|
2022-11-20 22:09:58 +01:00
|
|
|
List<ActionRow> actionRows = event.getMessage().getActionRows();
|
|
|
|
actionRows.set(0, actionRows.get(0).asDisabled());
|
|
|
|
event.editComponents(actionRows).queue();
|
|
|
|
|
2022-11-20 06:04:00 +01:00
|
|
|
int rand = RandomUtil.getRandomNumber(0, 1);
|
|
|
|
String msg;
|
|
|
|
|
|
|
|
if(rand == 1)
|
|
|
|
{
|
|
|
|
msg = ":coin: It's **Heads**!";
|
|
|
|
} else {
|
|
|
|
msg = "It's **Tails**! :coin:";
|
|
|
|
}
|
|
|
|
|
2022-11-20 22:09:58 +01:00
|
|
|
event.getHook().sendMessage(msg)
|
|
|
|
.addActionRow(Button.primary("reflip", "Flip again")
|
|
|
|
.withEmoji(Emoji.fromFormatted("\uD83E\uDE99")) // coin emoji
|
|
|
|
).queue();
|
2022-11-20 06:04:00 +01:00
|
|
|
}
|
2022-11-20 22:09:58 +01:00
|
|
|
|
2022-11-20 06:04:00 +01:00
|
|
|
}
|