use of com.sx4.bot.entities.economy.item.ItemType in project Sx4 by sx4-discord-bot.
the class ShopCommand method list.
@Command(value = "list", description = "View what items the bot has")
@CommandId(455)
@Examples({ "shop list" })
public void list(Sx4CommandEvent event) {
List<Bson> pipeline = List.of(Aggregates.match(Filters.and(Filters.eq("userId", event.getSelfUser().getIdLong()), Filters.ne("amount", 0))), Aggregates.project(Projections.fields(Projections.computed("name", "$item.name"), Projections.computed("type", "$item.type"), Projections.include("item", "amount"))), Aggregates.sort(Sorts.descending("amount")));
event.getMongo().aggregateItems(pipeline).whenComplete((items, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
EmbedBuilder embed = new EmbedBuilder().setAuthor("Shop List", null, event.getSelfUser().getEffectiveAvatarUrl()).setColor(event.getSelfMember().getColorRaw());
if (items.isEmpty()) {
event.replyFailure("That user does not have any items").queue();
return;
}
Map<ItemType, StringJoiner> types = new HashMap<>();
for (Document item : items) {
ItemType type = ItemType.fromId(item.getInteger("type"));
ItemStack<?> stack = new ItemStack<>(event.getBot().getEconomyManager(), item);
types.compute(type, (key, value) -> (value == null ? new StringJoiner("\n") : value).add(stack.toString()));
}
types.forEach((type, joiner) -> embed.addField(type.getName(), joiner.toString(), true));
event.reply(embed.build()).queue();
});
}
use of com.sx4.bot.entities.economy.item.ItemType in project Sx4 by sx4-discord-bot.
the class ItemsCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
Member effectiveMember = member == null ? event.getMember() : member;
List<Bson> usersPipeline = List.of(Aggregates.match(Filters.eq("_id", effectiveMember.getIdLong())), Aggregates.project(Projections.computed("balance", Operators.ifNull("$economy.balance", 0L))), Aggregates.addFields(new Field<>("name", "balance")));
List<Bson> pipeline = List.of(Aggregates.match(Filters.and(Filters.eq("userId", effectiveMember.getIdLong()), Filters.ne("amount", 0))), Aggregates.project(Projections.fields(Projections.computed("name", "$item.name"), Projections.computed("type", "$item.type"), Projections.include("item", "amount"))), Aggregates.sort(Sorts.descending("amount")), Aggregates.unionWith("users", usersPipeline));
event.getMongo().aggregateItems(pipeline).whenComplete((items, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
EmbedBuilder embed = new EmbedBuilder().setAuthor("Items", null, effectiveMember.getUser().getEffectiveAvatarUrl()).setColor(effectiveMember.getColorRaw());
if (items.isEmpty()) {
event.replyFailure("That user does not have any items").queue();
return;
}
String footerText = "If a category isn't shown it means you have no items in that category | Balance: $";
StringBuilder footer = new StringBuilder(footerText);
Map<ItemType, StringJoiner> types = new HashMap<>();
for (Document item : items) {
String name = item.getString("name");
if (name.equals("balance")) {
if (items.size() == 1) {
event.replyFailure("That user does not have any items").queue();
return;
}
footer.append(String.format("%,d", item.get("balance", 0L)));
continue;
}
ItemType type = ItemType.fromId(item.getInteger("type"));
ItemStack<?> stack = new ItemStack<>(event.getBot().getEconomyManager(), item);
types.compute(type, (key, value) -> (value == null ? new StringJoiner("\n") : value).add(stack.toString()));
}
if (footer.length() == footerText.length()) {
footer.append("0");
}
types.forEach((type, joiner) -> embed.addField(type.getName(), joiner.toString(), true));
embed.setFooter(footer.toString());
event.reply(embed.build()).queue();
});
}
Aggregations