use of com.github.kaktushose.jda.commands.dispatching.CommandEvent in project Levelbot by Kaktushose.
the class LeaderboardCommand method showLeaderboard.
public void showLeaderboard(CommandEvent event, Message sentMessage) {
Pagination pagination = paginationMap.get(currencyType);
Consumer<Message> success = message -> {
addReactions(message, pagination.index(), pagination.pages());
ReactionWaiter waiter = new ReactionWaiter(message, event.getMember(), BACK, FORTH, XP, COINS, DIAMONDS);
waiter.onEvent(reactionEvent -> {
switch(reactionEvent.getEmote()) {
case BACK:
if (pagination.index() == 0) {
return;
}
pagination.previousPage();
break;
case FORTH:
if (pagination.index() + 1 == pagination.pages()) {
return;
}
pagination.nextPage();
break;
case XP:
if (currencyType == CurrencyType.XP) {
return;
}
currencyType = CurrencyType.XP;
break;
case COINS:
if (currencyType == CurrencyType.COINS) {
return;
}
currencyType = CurrencyType.COINS;
break;
case DIAMONDS:
if (currencyType == CurrencyType.DIAMONDS) {
return;
}
currencyType = CurrencyType.DIAMONDS;
break;
default:
break;
}
showLeaderboard(event, message);
waiter.stopWaiting(true);
});
};
if (sentMessage == null) {
event.reply(buildEmbed(pagination.getPage(), pagination.index(), pagination.pages()), success);
} else {
sentMessage.editMessage(buildEmbed(pagination.getPage(), pagination.index(), pagination.pages()).build()).queue(success);
}
}
use of com.github.kaktushose.jda.commands.dispatching.CommandEvent in project Levelbot by Kaktushose.
the class AddItemCommand method sendSpecificShop.
private void sendSpecificShop(CommandEvent event, Message shopMessage, Member target, ItemCategory itemCategory) {
EmbedBuilder embedBuilder = specificShops.get(itemCategory);
List<Item> items = levelService.getItemsByCategoryId(itemCategory.id);
long amount = items.stream().filter(Item::isVisible).count();
Consumer<Message> success = message -> {
message.clearReactions().queue();
for (int i = 0; i < amount; i++) {
message.addReaction(EmoteType.getNumber(i + 1).unicode).queue();
}
message.addReaction(BACK).and(message.addReaction(CANCEL)).queue();
ReactionWaiter reactionWaiter = new ReactionWaiter(message, event.getMember(), BACK, CANCEL, NumberEmojis.ONE, NumberEmojis.TWO, NumberEmojis.THREE, NumberEmojis.FOUR);
reactionWaiter.onEvent(reactionEvent -> {
int variant = 0;
switch(reactionEvent.getEmote()) {
case NumberEmojis.ONE:
variant = 1;
break;
case NumberEmojis.TWO:
variant = 2;
break;
case NumberEmojis.THREE:
variant = 3;
break;
case NumberEmojis.FOUR:
variant = 4;
break;
case BACK:
sendDefaultShop(event, message, target);
reactionWaiter.stopWaiting(false);
return;
case CANCEL:
message.delete().and(event.getMessage().delete()).queue();
reactionWaiter.stopWaiting(false);
return;
}
if (amount < variant) {
return;
}
Item item = items.get(variant - 1);
Optional<String> buyResult = addItem(target, item);
if (buyResult.isEmpty()) {
message.editMessage(embedCache.getEmbed("addItemSuccess").injectValue("user", target.getAsMention()).injectValue("item", item.getName()).injectValue("days", TimeUnit.MILLISECONDS.toDays(item.getDuration())).toMessageEmbed()).and(message.clearReactions()).queue();
} else {
message.editMessage(embedCache.getEmbed("shopError").injectValue("message", buyResult.get()).toMessageEmbed()).queue(errorMessage -> {
errorMessage.clearReactions().queue();
errorMessage.addReaction(BACK).and(errorMessage.addReaction(CANCEL)).queue();
ReactionWaiter waiter = new ReactionWaiter(message, event.getMember(), BACK, CANCEL);
waiter.onEvent(errorMessageEvent -> {
if (errorMessageEvent.getEmote().equals(BACK)) {
sendDefaultShop(event, message, target);
} else {
message.delete().and(event.getMessage().delete()).queue();
}
waiter.stopWaiting(false);
});
});
}
reactionWaiter.stopWaiting(false);
});
};
if (shopMessage == null) {
event.reply(embedBuilder, success);
} else {
shopMessage.editMessage(embedBuilder.build()).queue(success);
}
}
Aggregations