Search in sources :

Example 16 with PagedResult

use of com.sx4.bot.paged.PagedResult in project Sx4 by sx4-discord-bot.

the class MarriageCommand method remove.

@Command(value = "remove", description = "Divorce someone you are currently married to")
@CommandId(269)
@Redirects({ "divorce" })
@Examples({ "marriage remove @Shea#6653", "marriage remove Shea", "marriage remove all" })
public void remove(Sx4CommandEvent event, @Argument(value = "user | all", endless = true, nullDefault = true) @AlternativeOptions("all") Alternative<Member> option) {
    User author = event.getAuthor();
    if (option == null) {
        Bson filter = Filters.or(Filters.eq("proposerId", author.getIdLong()), Filters.eq("partnerId", author.getIdLong()));
        List<Document> marriages = event.getMongo().getMarriages(filter, Projections.include("proposerId", "partnerId")).into(new ArrayList<>());
        if (marriages.isEmpty()) {
            event.replyFailure("You are not married to anyone").queue();
            return;
        }
        List<Long> userIds = marriages.stream().map(marriage -> {
            long partnerId = marriage.getLong("partnerId");
            return partnerId == author.getIdLong() ? marriage.getLong("proposerId") : partnerId;
        }).collect(Collectors.toList());
        PagedResult<Long> paged = new PagedResult<>(event.getBot(), userIds).setAuthor("Divorce", null, author.getEffectiveAvatarUrl()).setTimeout(60).setDisplayFunction(userId -> {
            User other = event.getShardManager().getUserById(userId);
            return (other == null ? "Anonymous#0000" : other.getAsTag()) + " (" + userId + ")";
        });
        paged.onTimeout(() -> event.reply("Timed out :stopwatch:").queue());
        paged.onSelect(select -> {
            long userId = select.getSelected();
            Bson deleteFilter = Filters.or(Filters.and(Filters.eq("proposerId", userId), Filters.eq("partnerId", author.getIdLong())), Filters.and(Filters.eq("proposerId", author.getIdLong()), Filters.eq("partnerId", userId)));
            event.getMongo().deleteMarriage(deleteFilter).whenComplete((result, exception) -> {
                if (ExceptionUtility.sendExceptionally(event, exception)) {
                    return;
                }
                User user = event.getShardManager().getUserById(userId);
                event.replySuccess("You are no longer married to **" + (user == null ? "Anonymous#0000" : user.getAsTag()) + "**").queue();
            });
        });
        paged.execute(event);
    } else if (option.isAlternative()) {
        List<Button> buttons = List.of(Button.success("yes", "Yes"), Button.danger("no", "No"));
        event.reply(author.getName() + ", are you sure you want to divorce everyone you are currently married to?").setActionRow(buttons).submit().thenCompose(message -> {
            return new Waiter<>(event.getBot(), ButtonClickEvent.class).setPredicate(e -> ButtonUtility.handleButtonConfirmation(e, message, event.getAuthor())).setCancelPredicate(e -> ButtonUtility.handleButtonCancellation(e, message, event.getAuthor())).onFailure(e -> ButtonUtility.handleButtonFailure(e, message)).setTimeout(60).start();
        }).whenComplete((e, exception) -> {
            Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
            if (cause instanceof CancelException) {
                GenericEvent cancelEvent = ((CancelException) cause).getEvent();
                if (cancelEvent != null) {
                    ((ButtonClickEvent) cancelEvent).reply("Cancelled " + event.getConfig().getSuccessEmote()).queue();
                }
                return;
            } else if (cause instanceof TimeoutException) {
                event.reply("Timed out :stopwatch:").queue();
                return;
            } else if (ExceptionUtility.sendExceptionally(event, exception)) {
                return;
            }
            Bson filter = Filters.or(Filters.eq("proposerId", author.getIdLong()), Filters.eq("partnerId", author.getIdLong()));
            event.getMongo().deleteManyMarriages(filter).whenComplete((result, databaseException) -> {
                if (ExceptionUtility.sendExceptionally(event, databaseException)) {
                    return;
                }
                if (result.getDeletedCount() == 0) {
                    e.reply("You are not married to anyone " + event.getConfig().getFailureEmote()).queue();
                    return;
                }
                e.reply("You are no longer married to anyone " + event.getConfig().getSuccessEmote()).queue();
            });
        });
    } else {
        Member member = option.getValue();
        Bson filter = Filters.or(Filters.and(Filters.eq("proposerId", member.getIdLong()), Filters.eq("partnerId", author.getIdLong())), Filters.and(Filters.eq("proposerId", author.getIdLong()), Filters.eq("partnerId", member.getIdLong())));
        event.getMongo().deleteMarriage(filter).whenComplete((result, exception) -> {
            if (ExceptionUtility.sendExceptionally(event, exception)) {
                return;
            }
            if (result.getDeletedCount() == 0) {
                event.replyFailure("You are not married to that user").queue();
                return;
            }
            event.replySuccess("You are no longer married to **" + member.getUser().getAsTag() + "**").queue();
        });
    }
}
Also used : Document(org.bson.Document) CancelException(com.sx4.bot.waiter.exception.CancelException) Command(com.jockie.bot.core.command.Command) ButtonClickEvent(net.dv8tion.jda.api.events.interaction.ButtonClickEvent) Projections(com.mongodb.client.model.Projections) Cooldown(com.jockie.bot.core.command.Command.Cooldown) CommandId(com.sx4.bot.annotations.command.CommandId) Member(net.dv8tion.jda.api.entities.Member) PagedResult(com.sx4.bot.paged.PagedResult) User(net.dv8tion.jda.api.entities.User) ArrayList(java.util.ArrayList) Filters(com.mongodb.client.model.Filters) Bson(org.bson.conversions.Bson) Redirects(com.sx4.bot.annotations.command.Redirects) Alternative(com.sx4.bot.entities.argument.Alternative) ButtonUtility(com.sx4.bot.utility.ButtonUtility) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) Button(net.dv8tion.jda.api.interactions.components.Button) AlternativeOptions(com.sx4.bot.annotations.argument.AlternativeOptions) Waiter(com.sx4.bot.waiter.Waiter) GenericEvent(net.dv8tion.jda.api.events.GenericEvent) ZoneOffset(java.time.ZoneOffset) EnumSet(java.util.EnumSet) Argument(com.jockie.bot.core.argument.Argument) Message(net.dv8tion.jda.api.entities.Message) Sx4Command(com.sx4.bot.core.Sx4Command) Updates(com.mongodb.client.model.Updates) CooldownMessage(com.sx4.bot.annotations.command.CooldownMessage) CompletionException(java.util.concurrent.CompletionException) TimeoutException(com.sx4.bot.waiter.exception.TimeoutException) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ModuleCategory(com.sx4.bot.category.ModuleCategory) List(java.util.List) Examples(com.sx4.bot.annotations.command.Examples) OffsetDateTime(java.time.OffsetDateTime) Sorts(com.mongodb.client.model.Sorts) DateTimeFormatter(java.time.format.DateTimeFormatter) StringJoiner(java.util.StringJoiner) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) User(net.dv8tion.jda.api.entities.User) ButtonClickEvent(net.dv8tion.jda.api.events.interaction.ButtonClickEvent) Document(org.bson.Document) Bson(org.bson.conversions.Bson) GenericEvent(net.dv8tion.jda.api.events.GenericEvent) CompletionException(java.util.concurrent.CompletionException) ArrayList(java.util.ArrayList) List(java.util.List) CancelException(com.sx4.bot.waiter.exception.CancelException) Member(net.dv8tion.jda.api.entities.Member) TimeoutException(com.sx4.bot.waiter.exception.TimeoutException) Redirects(com.sx4.bot.annotations.command.Redirects) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 17 with PagedResult

use of com.sx4.bot.paged.PagedResult in project Sx4 by sx4-discord-bot.

the class GameCommand method leaderboard.

@Command(value = "leaderboard", aliases = { "lb" }, description = "View the users who have played/won/lost/drawn the most games")
@CommandId(457)
@Redirects({ "lb games", "leaderboard games", "lb game", "leaderboard game" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void leaderboard(Sx4CommandEvent event, @Argument(value = "games") @Endless(minArguments = 0) GameType[] gameTypes, @Option(value = "server", aliases = { "guild" }, description = "Filters by only users in the current server") boolean guild, @Option(value = "state", description = "Filters whether the leaderboard should be for wins, played, losses or draws") GameState state) {
    List<Bson> filters = new ArrayList<>();
    if (gameTypes.length > 0) {
        filters.add(Filters.in("type", Arrays.stream(gameTypes).map(GameType::getId).collect(Collectors.toList())));
    }
    if (state != null) {
        filters.add(Filters.eq("state", state.getId()));
    }
    List<Bson> pipeline = List.of(Aggregates.project(Projections.include("state", "type", "userId")), Aggregates.match(filters.isEmpty() ? Filters.empty() : Filters.and(filters)), Aggregates.group("$userId", Accumulators.sum("count", 1L)), Aggregates.sort(Sorts.descending("count")));
    event.getMongo().aggregateGames(pipeline).whenComplete((games, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        List<Map.Entry<User, Long>> users = new ArrayList<>();
        AtomicInteger userIndex = new AtomicInteger(-1);
        int i = 0;
        for (Document game : games) {
            User user = event.getShardManager().getUserById(game.getLong("_id"));
            if (user == null) {
                continue;
            }
            if (!event.getGuild().isMember(user) && guild) {
                continue;
            }
            i++;
            users.add(Map.entry(user, game.getLong("count")));
            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, Long>> paged = new PagedResult<>(event.getBot(), users).setPerPage(10).setCustomFunction(page -> {
            int rank = userIndex.get();
            EmbedBuilder embed = new EmbedBuilder().setTitle("Games 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 game%s\n", index + 1, MarkdownSanitizer.escape(entry.getKey().getAsTag()), entry.getValue(), entry.getValue() == 1 ? "" : "s")));
            return new MessageBuilder().setEmbeds(embed.build());
        });
        paged.execute(event);
    });
}
Also used : User(net.dv8tion.jda.api.entities.User) ArrayList(java.util.ArrayList) Document(org.bson.Document) Bson(org.bson.conversions.Bson) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PagedResult(com.sx4.bot.paged.PagedResult) Redirects(com.sx4.bot.annotations.command.Redirects) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId)

Example 18 with PagedResult

use of com.sx4.bot.paged.PagedResult in project Sx4 by sx4-discord-bot.

the class BotListCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "page") @DefaultNumber(1) @Limit(min = 1, max = 50) int page) {
    Request request = new Request.Builder().url("https://top.gg/api/bots?sort=server_count&limit=500&fields=username,server_count,id").addHeader("Authorization", event.getConfig().getTopGG()).build();
    event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
        Document data = Document.parse(response.body().string());
        List<Document> results = data.getList("results", Document.class);
        PagedResult<Document> paged = new PagedResult<>(event.getBot(), results).setPage(page).setAuthor("Bot List", null, "https://imgur.com/HlfRQ3g.png").setIncreasedIndex(true).setSelect().setDisplayFunction(bot -> String.format("[%s](https://top.gg/bot/%s) - **%,d** servers", bot.getString("username"), bot.getString("id"), bot.getInteger("server_count")));
        paged.execute(event);
    });
}
Also used : Document(org.bson.Document) ModuleCategory(com.sx4.bot.category.ModuleCategory) Request(okhttp3.Request) List(java.util.List) DefaultNumber(com.sx4.bot.annotations.argument.DefaultNumber) HttpCallback(com.sx4.bot.http.HttpCallback) Sx4Command(com.sx4.bot.core.Sx4Command) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) Permission(net.dv8tion.jda.api.Permission) PagedResult(com.sx4.bot.paged.PagedResult) Argument(com.jockie.bot.core.argument.Argument) Limit(com.sx4.bot.annotations.argument.Limit) Request(okhttp3.Request) List(java.util.List) Document(org.bson.Document) PagedResult(com.sx4.bot.paged.PagedResult)

Example 19 with PagedResult

use of com.sx4.bot.paged.PagedResult in project Sx4 by sx4-discord-bot.

the class CSGOSkinCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "skin name", endless = true) String query, @Option(value = "sort", description = "You can sort by `price`, `age`, `deal`, `popularity`, `wear or `discount`") Sort sort, @Option(value = "reverse", description = "Reverse the order of the sorting") boolean reverse, @Option(value = "wear", description = "What wear you would like to filter by, options are `fn`, `mw`, `ft`, `ww` and `bs`") Wear wear, @Option(value = "phase", description = "Filter by phase of a knife") @Lowercase String phase, @Option(value = "currency", description = "What currency to use for the prices of items") @Uppercase @DefaultString("GBP") String currency) {
    SkinPortManager manager = event.getBot().getSkinPortManager();
    String cookie = manager.getCSRFCookie();
    double rate = manager.getCurrencyRate(currency);
    if (rate == -1D) {
        event.replyFailure("SkinPort does not support that currency").queue();
        return;
    }
    FormBody body = new FormBody.Builder().add("prefix", query).add("_csrf", manager.getCSRFToken()).build();
    Request suggestionRequest = new Request.Builder().url("https://skinport.com/api/suggestions/730").post(body).addHeader("Content-Type", "application/x-www-form-urlencoded").addHeader("Cookie", cookie).build();
    event.getHttpClient().newCall(suggestionRequest).enqueue((HttpCallback) suggestionResponse -> {
        Document data = Document.parse(suggestionResponse.body().string());
        List<Document> variants = data.getList("suggestions", Document.class);
        if (variants.isEmpty()) {
            event.replyFailure("I could not find any skins from that query").queue();
            return;
        }
        PagedResult<Document> suggestions = new PagedResult<>(event.getBot(), variants).setAuthor("SkinPort", null, "https://skinport.com/static/favicon-32x32.png").setDisplayFunction(suggestion -> {
            String type = suggestion.getString("type");
            return (type == null ? "" : type + " | ") + suggestion.getString("item");
        }).setIndexed(true).setAutoSelect(true);
        suggestions.onSelect(select -> {
            Document selected = select.getSelected();
            String type = selected.getString("type");
            StringBuilder url = new StringBuilder("https://skinport.com/api/browse/730?cat=" + URLEncoder.encode(selected.getString("category"), StandardCharsets.UTF_8) + (type != null ? "&type=" + URLEncoder.encode(type, StandardCharsets.UTF_8) : "") + "&item=" + URLEncoder.encode(selected.getString("item"), StandardCharsets.UTF_8));
            if (wear != null) {
                url.append("&exterior=").append(wear.getId());
            }
            if (sort != null) {
                url.append("&sort=").append(sort.getIdentifier()).append("&order=").append(reverse ? "desc" : "asc");
            }
            if (phase != null) {
                int phaseId = this.phases.getOrDefault(phase, -1);
                if (phaseId != -1) {
                    url.append("&phase=").append(phaseId);
                }
            }
            Request request = new Request.Builder().url(url.toString()).addHeader("Cookie", cookie).build();
            event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
                Document skinData = Document.parse(response.body().string());
                List<Document> items = skinData.getList("items", Document.class);
                if (items.isEmpty()) {
                    event.replyFailure("There are no skins listed with those filters").queue();
                    return;
                }
                PagedResult<Document> skins = new PagedResult<>(event.getBot(), items).setPerPage(1).setSelect().setCustomFunction(page -> {
                    List<MessageEmbed> embeds = new ArrayList<>();
                    EmbedBuilder embed = new EmbedBuilder();
                    embed.setFooter("Skin " + page.getPage() + "/" + page.getMaxPage());
                    page.forEach((d, index) -> {
                        double steamPrice = (d.getInteger("suggestedPrice") / 100D) * rate;
                        double price = (d.getInteger("salePrice") / 100D) * rate;
                        double increase = steamPrice - price;
                        embed.setTitle(d.getString("marketName"), "https://skinport.com/item/" + d.getString("url") + "/" + d.getInteger("saleId"));
                        embed.setImage("https://community.cloudflare.steamstatic.com/economy/image/" + d.getString("image"));
                        embed.addField("Price", String.format("~~%,.2f %s~~ %,.2f %2$s (%s%.2f%%)", steamPrice, currency, price, increase > 0 ? "-" : "+", Math.abs((increase / steamPrice) * 100D)), true);
                        String exterior = d.getString("exterior");
                        if (exterior != null) {
                            embed.addField("Wear", exterior, true);
                            embed.addField("Float", String.format("%.3f", d.get("wear", Number.class).doubleValue()), true);
                        }
                        String lock = d.getString("lock");
                        embed.addField("Trade Locked", lock == null ? "No" : this.formatter.parse(Duration.between(OffsetDateTime.now(ZoneOffset.UTC), OffsetDateTime.parse(lock))), true);
                        embeds.add(embed.build());
                        if (d.getBoolean("canHaveScreenshots")) {
                            embed.setImage("https://cdn.skinport.com/images/screenshots/" + d.getInteger("assetId") + "/backside_512x384.png");
                            embeds.add(embed.build());
                            embed.setImage("https://cdn.skinport.com/images/screenshots/" + d.getInteger("assetId") + "/playside_512x384.png");
                            embeds.add(embed.build());
                        }
                    });
                    return new MessageBuilder().setEmbeds(embeds);
                });
                skins.execute(event);
            });
        });
        suggestions.execute(event);
    });
}
Also used : Document(org.bson.Document) Uppercase(com.sx4.bot.annotations.argument.Uppercase) HashMap(java.util.HashMap) SkinPortManager(com.sx4.bot.managers.SkinPortManager) PagedResult(com.sx4.bot.paged.PagedResult) ArrayList(java.util.ArrayList) FormBody(okhttp3.FormBody) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) TimeUtility(com.sx4.bot.utility.TimeUtility) Duration(java.time.Duration) Map(java.util.Map) Option(com.jockie.bot.core.option.Option) TimeFormatter(com.sx4.bot.entities.utility.TimeFormatter) ZoneOffset(java.time.ZoneOffset) Argument(com.jockie.bot.core.argument.Argument) Lowercase(com.sx4.bot.annotations.argument.Lowercase) Request(okhttp3.Request) HttpCallback(com.sx4.bot.http.HttpCallback) Sx4Command(com.sx4.bot.core.Sx4Command) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) StandardCharsets(java.nio.charset.StandardCharsets) ModuleCategory(com.sx4.bot.category.ModuleCategory) URLEncoder(java.net.URLEncoder) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) DefaultString(com.sx4.bot.annotations.argument.DefaultString) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) FormBody(okhttp3.FormBody) Request(okhttp3.Request) HttpCallback(com.sx4.bot.http.HttpCallback) ArrayList(java.util.ArrayList) DefaultString(com.sx4.bot.annotations.argument.DefaultString) Document(org.bson.Document) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) SkinPortManager(com.sx4.bot.managers.SkinPortManager) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) ArrayList(java.util.ArrayList) List(java.util.List) PagedResult(com.sx4.bot.paged.PagedResult)

Example 20 with PagedResult

use of com.sx4.bot.paged.PagedResult in project Sx4 by sx4-discord-bot.

the class CommandStatsCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Option(value = "group", description = "What to group the data by, default is command") GroupType group, @Option(value = "command", description = "Provide a command filter") Sx4Command command, @Option(value = "server", aliases = { "guild" }, description = "Provide a server filter") Guild guild, @Option(value = "channel", description = "Provide a channel filter") TextChannel channel, @Option(value = "user", description = "Provide a user id argument") long userId, @Option(value = "from", description = "When the data should start in epoch seconds") long from, @Option(value = "to", description = "When the data should end in epoch seconds") long to) {
    List<Bson> filters = new ArrayList<>();
    if (command != null) {
        filters.add(Filters.eq("command.id", command.getId()));
    }
    if (group == GroupType.CHANNEL) {
        filters.add(Filters.eq("guildId", event.getGuild().getIdLong()));
    } else if (guild != null) {
        filters.add(Filters.eq("guildId", guild.getIdLong()));
    }
    if (userId != 0L) {
        filters.add(Filters.eq("authorId", userId));
    }
    if (channel != null) {
        filters.add(Filters.eq("channelId", channel.getIdLong()));
    }
    if (from != 0L) {
        filters.add(Filters.gte("_id", new ObjectId(Date.from(Instant.ofEpochSecond(from)))));
    }
    if (to != 0L) {
        filters.add(Filters.lte("_id", new ObjectId(Date.from(Instant.ofEpochSecond(to)))));
    }
    List<Bson> pipeline = List.of(Aggregates.match(filters.isEmpty() ? Filters.empty() : Filters.and(filters)), Aggregates.group("$" + (group == null ? GroupType.COMMAND : group).getField(), Accumulators.sum("count", 1L)), Aggregates.sort(Sorts.descending("count")));
    event.getMongo().aggregateCommands(pipeline).whenComplete((commands, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        if (commands.isEmpty()) {
            event.replyFailure("No data was found with those filters").queue();
            return;
        }
        PagedResult<Document> paged = new PagedResult<>(event.getBot(), commands).setIndexed(false).setSelect().setAuthor("Command Stats", null, event.getSelfUser().getEffectiveAvatarUrl()).setDisplayFunction(data -> {
            String prefix = null;
            if (group == null || group == GroupType.COMMAND) {
                prefix = "`" + data.getString("_id") + "`";
            } else if (group == GroupType.CHANNEL) {
                long id = data.getLong("_id");
                TextChannel textChannel = event.getGuild().getTextChannelById(id);
                prefix = textChannel == null ? "#deleted-channel (" + id + ")" : textChannel.getAsMention();
            } else if (group == GroupType.USER) {
                long id = data.getLong("_id");
                User user = event.getShardManager().getUserById(id);
                prefix = "`" + (user == null ? "Anonymous#0000 (" + id + ")" : MarkdownSanitizer.escape(user.getAsTag())) + "`";
            } else if (group == GroupType.SERVER) {
                Long id = data.getLong("_id");
                if (id == null) {
                    prefix = "`Private Messages`";
                } else {
                    Guild guildGroup = event.getShardManager().getGuildById(id);
                    prefix = "`" + (guildGroup == null ? "Unknown Server (" + id + ")" : MarkdownSanitizer.escape(guildGroup.getName())) + "`";
                }
            }
            long count = data.getLong("count");
            return (prefix == null ? "Unknown" : prefix) + " - " + String.format("%,d", count) + " use" + (count == 1 ? "" : "s");
        });
        paged.execute(event);
    });
}
Also used : User(net.dv8tion.jda.api.entities.User) ObjectId(org.bson.types.ObjectId) ArrayList(java.util.ArrayList) Document(org.bson.Document) Guild(net.dv8tion.jda.api.entities.Guild) Bson(org.bson.conversions.Bson) TextChannel(net.dv8tion.jda.api.entities.TextChannel) PagedResult(com.sx4.bot.paged.PagedResult)

Aggregations

Sx4Command (com.sx4.bot.core.Sx4Command)54 PagedResult (com.sx4.bot.paged.PagedResult)50 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)43 Document (org.bson.Document)43 Command (com.jockie.bot.core.command.Command)41 CommandId (com.sx4.bot.annotations.command.CommandId)35 Examples (com.sx4.bot.annotations.command.Examples)33 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)32 ModuleCategory (com.sx4.bot.category.ModuleCategory)26 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)26 User (net.dv8tion.jda.api.entities.User)26 Argument (com.jockie.bot.core.argument.Argument)25 Bson (org.bson.conversions.Bson)23 Permission (net.dv8tion.jda.api.Permission)22 BotPermissions (com.sx4.bot.annotations.command.BotPermissions)20 List (java.util.List)19 ArrayList (java.util.ArrayList)18 HttpCallback (com.sx4.bot.http.HttpCallback)15 Request (okhttp3.Request)15 Collectors (java.util.stream.Collectors)13