use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class PickaxeCommand method shop.
@Command(value = "shop", description = "View all the pickaxes you are able to buy or craft")
@CommandId(360)
@Examples({ "pickaxe shop" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void shop(Sx4CommandEvent event) {
List<Pickaxe> pickaxes = event.getBot().getEconomyManager().getItems(Pickaxe.class);
PagedResult<Pickaxe> paged = new PagedResult<>(event.getBot(), pickaxes).setPerPage(12).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Pickaxe Shop", null, event.getSelfUser().getEffectiveAvatarUrl()).setTitle("Page " + page.getPage() + "/" + page.getMaxPage()).setDescription("Pickaxes are a good way to gain some extra money aswell as some materials").setFooter(PagedResult.DEFAULT_FOOTER_TEXT);
page.forEach((pickaxe, index) -> {
List<ItemStack<CraftItem>> items = pickaxe.getCraft();
String craft = items.isEmpty() ? "None" : items.stream().map(ItemStack::toString).collect(Collectors.joining("\n"));
embed.addField(pickaxe.getName(), String.format("Price: $%,d\nCraft: %s\nDurability: %,d", pickaxe.getPrice(), craft, pickaxe.getMaxDurability()), true);
});
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class ReputationCommand method amount.
@Command(value = "amount", description = "View the amount of reputation a user has")
@CommandId(420)
@Examples({ "reputation amount", "reputation amount @Shea#6653", "reputation amount Shea" })
public void amount(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
User user = member == null ? event.getAuthor() : member.getUser();
int amount = event.getMongo().getUserById(user.getIdLong(), Projections.include("reputation.amount")).getEmbedded(List.of("reputation", "amount"), 0);
event.replyFormat("%s has **%,d** reputation", user.getAsTag(), amount).queue();
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class ReputationCommand method leaderboard.
@Command(value = "leaderboard", aliases = { "lb" }, description = "View the leaderboard for reputation across the bot")
@CommandId(421)
@Redirects({ "leaderboard reputation", "lb rep", "lb reputation", "leaderboard rep" })
@Examples({ "reputation leaderboard", "reputation leaderboard --server" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void leaderboard(Sx4CommandEvent event, @Option(value = "server", aliases = { "guild" }, description = "View the leaderboard with a server filter") boolean guild) {
List<Bson> pipeline = List.of(Aggregates.project(Projections.computed("reputation", "$reputation.amount")), Aggregates.match(Filters.exists("reputation")), Aggregates.sort(Sorts.descending("reputation")));
event.getMongo().aggregateUsers(pipeline).whenComplete((documents, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
List<Map.Entry<User, Integer>> users = new ArrayList<>();
AtomicInteger userIndex = new AtomicInteger(-1);
int i = 0;
for (Document data : documents) {
User user = event.getShardManager().getUserById(data.getLong("_id"));
if (user == null) {
continue;
}
if (!event.getGuild().isMember(user) && guild) {
continue;
}
i++;
users.add(Map.entry(user, data.getInteger("reputation")));
if (user.getIdLong() == event.getAuthor().getIdLong()) {
userIndex.set(i);
}
}
if (users.isEmpty()) {
event.replyFailure("There are no users which fit into this leaderboard").queue();
return;
}
PagedResult<Map.Entry<User, Integer>> paged = new PagedResult<>(event.getBot(), users).setPerPage(10).setCustomFunction(page -> {
int rank = userIndex.get();
EmbedBuilder embed = new EmbedBuilder().setTitle("Reputation Leaderboard").setFooter(event.getAuthor().getName() + "'s Rank: " + (rank == -1 ? "N/A" : NumberUtility.getSuffixed(rank)) + " | Page " + page.getPage() + "/" + page.getMaxPage(), event.getAuthor().getEffectiveAvatarUrl());
page.forEach((entry, index) -> embed.appendDescription(String.format("%d. `%s` - %,d reputation\n", index + 1, MarkdownSanitizer.escape(entry.getKey().getAsTag()), entry.getValue())));
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
});
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class MarriageCommand method list.
@Command(value = "list", description = "Lists a users marriages")
@CommandId(270)
@Redirects({ "married" })
@Examples({ "marriage list", "marriage list @Shea#6653", "marriage list Shea" })
public void list(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
member = member == null ? event.getMember() : member;
User user = member.getUser();
Bson filter = Filters.or(Filters.eq("proposerId", user.getIdLong()), Filters.eq("partnerId", user.getIdLong()));
List<Document> marriages = event.getMongo().getMarriages(filter, Projections.include("proposerId", "partnerId")).sort(Sorts.ascending("_id")).into(new ArrayList<>());
if (marriages.isEmpty()) {
event.replyFailure("That user is not married to anyone").queue();
return;
}
StringJoiner joiner = new StringJoiner("\n");
for (Document marriage : marriages) {
long partnerId = marriage.getLong("partnerId");
long otherId = partnerId == user.getIdLong() ? marriage.getLong("proposerId") : partnerId;
User other = event.getShardManager().getUserById(otherId);
joiner.add((other == null ? "Anonymous#0000" : other.getAsTag()) + " (" + otherId + ")");
}
EmbedBuilder embed = new EmbedBuilder().setAuthor(user.getName() + "'s Partners", null, user.getEffectiveAvatarUrl()).setDescription(joiner.toString()).setColor(member.getColorRaw());
event.reply(embed.build()).queue();
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class WarnCommand method resetAfter.
@Command(value = "reset after", description = "The time it should take for warns to be taken away")
@CommandId(450)
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
@Examples({ "warn reset after 1 1 day", "warn reset after 3 5h 20s", "warn reset after 3 30d" })
public void resetAfter(Sx4CommandEvent event, @Argument(value = "amount") @Limit(min = 0) int amount, @Argument(value = "time", endless = true, nullDefault = true) Duration time) {
if (time != null && time.toMinutes() < 5) {
event.replyFailure("The duration has to be 5 minutes or above").queue();
return;
}
if (amount != 0 && time == null) {
event.reply("You need to provide a duration if attempts is more than 0").queue();
return;
}
Bson update = amount == 0 ? Updates.unset("warn.reset") : Updates.set("warn.reset", new Document("amount", amount).append("after", time.toSeconds()));
event.getMongo().updateGuildById(event.getGuild().getIdLong(), update).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Your warn reset configuration was already set to that").queue();
return;
}
event.reply(amount == 0 ? "Users warns will no longer reset" + event.getConfig().getSuccessEmote() : String.format("Users warns will now reset **%d** time%s after `%s` %s", amount, amount == 1 ? "" : "s", TimeUtility.LONG_TIME_FORMATTER.parse(time.toSeconds()), event.getConfig().getSuccessEmote())).queue();
});
}
Aggregations