Search in sources :

Example 31 with BotPermissions

use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.

the class TwitchNotificationCommand method formatters.

@Command(value = "formatters", aliases = { "format", "formatting" }, description = "Get all the formatters for Twitch notifications you can use")
@CommandId(501)
@Examples({ "twitch notification formatters" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void formatters(Sx4CommandEvent event) {
    EmbedBuilder embed = new EmbedBuilder().setAuthor("Twitch Notification Formatters", null, event.getSelfUser().getEffectiveAvatarUrl());
    FormatterManager manager = FormatterManager.getDefaultManager();
    StringJoiner content = new StringJoiner("\n");
    for (FormatterVariable<?> variable : manager.getVariables(TwitchStream.class)) {
        content.add("`{stream." + variable.getName() + "}` - " + variable.getDescription());
    }
    for (FormatterVariable<?> variable : manager.getVariables(TwitchStreamer.class)) {
        content.add("`{streamer." + variable.getName() + "}` - " + variable.getDescription());
    }
    embed.setDescription(content.toString());
    event.reply(embed.build()).queue();
}
Also used : FormatterManager(com.sx4.bot.formatter.FormatterManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) Sx4Command(com.sx4.bot.core.Sx4Command) Command(com.jockie.bot.core.command.Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 32 with BotPermissions

use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.

the class YouTubeNotificationCommand method stats.

@Command(value = "stats", aliases = { "settings", "setting" }, description = "View the settings for a specific notification")
@CommandId(166)
@Examples({ "youtube notification stats 5e45ce6d3688b30ee75201ae" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void stats(Sx4CommandEvent event, @Argument(value = "id") ObjectId id) {
    Document notification = event.getMongo().getYouTubeNotification(Filters.eq("_id", id), Projections.include("uploaderId", "channelId", "message.content"));
    if (notification == null) {
        event.replyFailure("You don't have a notification with that id").queue();
        return;
    }
    this.sendStats(event, notification);
}
Also used : Document(org.bson.Document) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) Sx4Command(com.sx4.bot.core.Sx4Command) Command(com.jockie.bot.core.command.Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 33 with BotPermissions

use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.

the class YouTubeNotificationCommand method list.

@Command(value = "list", description = "View all the notifications you have setup throughout your server")
@CommandId(165)
@Examples({ "youtube notification list" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void list(Sx4CommandEvent event) {
    List<Document> notifications = event.getMongo().getYouTubeNotifications(Filters.eq("guildId", event.getGuild().getIdLong()), Projections.include("uploaderId", "channelId", "message")).into(new ArrayList<>());
    if (notifications.isEmpty()) {
        event.replyFailure("You have no notifications setup in this server").queue();
        return;
    }
    List<String> channels = notifications.stream().map(d -> d.getString("uploaderId")).distinct().collect(Collectors.toList());
    int size = channels.size();
    List<CompletableFuture<Map<String, String>>> futures = new ArrayList<>();
    for (int i = 0; i < Math.ceil(size / 50D); i++) {
        List<String> splitChannels = channels.subList(i * 50, Math.min((i + 1) * 50, size));
        String ids = String.join(",", splitChannels);
        Request request = new Request.Builder().url("https://www.googleapis.com/youtube/v3/channels?key=" + event.getConfig().getYouTube() + "&id=" + ids + "&part=snippet&maxResults=50").build();
        CompletableFuture<Map<String, String>> future = new CompletableFuture<>();
        event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
            Document data = Document.parse(response.body().string());
            List<Document> items = data.getList("items", Document.class);
            Map<String, String> names = new HashMap<>();
            for (Document item : items) {
                names.put(item.getString("id"), item.getEmbedded(List.of("snippet", "title"), String.class));
            }
            future.complete(names);
        });
        futures.add(future);
    }
    FutureUtility.allOf(futures).whenComplete((maps, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        Map<String, String> names = new HashMap<>();
        for (Map<String, String> map : maps) {
            names.putAll(map);
        }
        PagedResult<Document> paged = new PagedResult<>(event.getBot(), notifications).setIncreasedIndex(true).setAutoSelect(false).setAuthor("YouTube Notifications", null, event.getGuild().getIconUrl()).setDisplayFunction(data -> {
            String uploaderId = data.getString("uploaderId");
            return String.format("%s - [%s](https://youtube.com/channel/%s)", data.getObjectId("_id").toHexString(), names.getOrDefault(uploaderId, "Unknown"), uploaderId);
        }).setSelect(SelectType.INDEX);
        paged.onSelect(selected -> this.sendStats(event, selected.getSelected()));
        paged.execute(event);
    });
}
Also used : Document(org.bson.Document) FormatterVariable(com.sx4.bot.formatter.function.FormatterVariable) MongoWriteException(com.mongodb.MongoWriteException) Permission(net.dv8tion.jda.api.Permission) PagedResult(com.sx4.bot.paged.PagedResult) JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) ZoneOffset(java.time.ZoneOffset) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) AuthorPermissions(com.sx4.bot.annotations.command.AuthorPermissions) ErrorResponseException(net.dv8tion.jda.api.exceptions.ErrorResponseException) Request(okhttp3.Request) InsertOneResult(com.mongodb.client.result.InsertOneResult) HttpCallback(com.sx4.bot.http.HttpCallback) Sx4Command(com.sx4.bot.core.Sx4Command) CompletionException(java.util.concurrent.CompletionException) FormatterManager(com.sx4.bot.formatter.FormatterManager) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Examples(com.sx4.bot.annotations.command.Examples) OffsetDateTime(java.time.OffsetDateTime) YouTubeChannel(com.sx4.bot.entities.youtube.YouTubeChannel) MultipartBody(okhttp3.MultipartBody) Pattern(java.util.regex.Pattern) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) java.util(java.util) Command(com.jockie.bot.core.command.Command) JsonFormatter(com.sx4.bot.formatter.JsonFormatter) CommandId(com.sx4.bot.annotations.command.CommandId) CompletableFuture(java.util.concurrent.CompletableFuture) ErrorResponse(net.dv8tion.jda.api.requests.ErrorResponse) RequestBody(okhttp3.RequestBody) Bson(org.bson.conversions.Bson) AdvancedMessage(com.sx4.bot.annotations.argument.AdvancedMessage) XML(org.json.XML) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) com.mongodb.client.model(com.mongodb.client.model) YouTubeManager(com.sx4.bot.managers.YouTubeManager) FutureUtility(com.sx4.bot.utility.FutureUtility) Argument(com.jockie.bot.core.argument.Argument) Operators(com.sx4.bot.database.mongo.model.Operators) BaseGuildMessageChannel(net.dv8tion.jda.api.entities.BaseGuildMessageChannel) MessageUtility(com.sx4.bot.utility.MessageUtility) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ModuleCategory(com.sx4.bot.category.ModuleCategory) URLEncoder(java.net.URLEncoder) SelectType(com.sx4.bot.paged.PagedResult.SelectType) YouTubeVideo(com.sx4.bot.entities.youtube.YouTubeVideo) ImageUrl(com.sx4.bot.annotations.argument.ImageUrl) ObjectId(org.bson.types.ObjectId) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) JSONArray(org.json.JSONArray) ErrorCategory(com.mongodb.ErrorCategory) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Request(okhttp3.Request) Document(org.bson.Document) CompletableFuture(java.util.concurrent.CompletableFuture) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) Sx4Command(com.sx4.bot.core.Sx4Command) Command(com.jockie.bot.core.command.Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 34 with BotPermissions

use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.

the class YouTubeNotificationCommand method formatters.

@Command(value = "formatters", aliases = { "format", "formatting" }, description = "Get all the formatters for YouTube notifications you can use")
@CommandId(445)
@Examples({ "youtube notification formatters" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void formatters(Sx4CommandEvent event) {
    EmbedBuilder embed = new EmbedBuilder().setAuthor("YouTube Notification Formatters", null, event.getSelfUser().getEffectiveAvatarUrl());
    FormatterManager manager = FormatterManager.getDefaultManager();
    StringJoiner content = new StringJoiner("\n");
    for (FormatterVariable<?> variable : manager.getVariables(YouTubeVideo.class)) {
        content.add("`{video." + variable.getName() + "}` - " + variable.getDescription());
    }
    for (FormatterVariable<?> variable : manager.getVariables(YouTubeChannel.class)) {
        content.add("`{channel." + variable.getName() + "}` - " + variable.getDescription());
    }
    embed.setDescription(content.toString());
    event.reply(embed.build()).queue();
}
Also used : FormatterManager(com.sx4.bot.formatter.FormatterManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) Sx4Command(com.sx4.bot.core.Sx4Command) Command(com.jockie.bot.core.command.Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 35 with BotPermissions

use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.

the class StarboardCommand method formatters.

@Command(value = "formatters", aliases = { "format", "formatting" }, description = "Get all the formatters for starboard you can use")
@CommandId(444)
@Examples({ "starboard formatters" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void formatters(Sx4CommandEvent event) {
    EmbedBuilder embed = new EmbedBuilder().setAuthor("Starboard Formatters", null, event.getSelfUser().getEffectiveAvatarUrl());
    FormatterManager manager = FormatterManager.getDefaultManager();
    StringJoiner content = new StringJoiner("\n");
    for (FormatterVariable<?> variable : manager.getVariables(User.class)) {
        content.add("`{user." + variable.getName() + "}` - " + variable.getDescription());
    }
    for (FormatterVariable<?> variable : manager.getVariables(Member.class)) {
        content.add("`{member." + variable.getName() + "}` - " + variable.getDescription());
    }
    for (FormatterVariable<?> variable : manager.getVariables(Guild.class)) {
        content.add("`{server." + variable.getName() + "}` - " + variable.getDescription());
    }
    for (FormatterVariable<?> variable : manager.getVariables(TextChannel.class)) {
        content.add("`{channel." + variable.getName() + "}` - " + variable.getDescription());
    }
    for (FormatterVariable<?> variable : manager.getVariables(ReactionEmote.class)) {
        content.add("`{emote." + variable.getName() + "}` - " + variable.getDescription());
    }
    content.add("`{stars}` - Gets amount of stars the starboard has");
    content.add("`{stars.next}` - Gets the amount of stars the next milestone requires");
    content.add("`{stars.next.until}` - Gets the amount of stars needed to reach the next milestone");
    content.add("`{id}` - Gets the id for the starboard");
    embed.setDescription(content.toString());
    event.reply(embed.build()).queue();
}
Also used : FormatterManager(com.sx4.bot.formatter.FormatterManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) StringJoiner(java.util.StringJoiner) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command)

Aggregations

Command (com.jockie.bot.core.command.Command)44 Sx4Command (com.sx4.bot.core.Sx4Command)44 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)37 BotPermissions (com.sx4.bot.annotations.command.BotPermissions)33 CommandId (com.sx4.bot.annotations.command.CommandId)33 Examples (com.sx4.bot.annotations.command.Examples)31 Document (org.bson.Document)29 PagedResult (com.sx4.bot.paged.PagedResult)25 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)21 Bson (org.bson.conversions.Bson)20 Argument (com.jockie.bot.core.argument.Argument)14 ModuleCategory (com.sx4.bot.category.ModuleCategory)14 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)14 Permission (net.dv8tion.jda.api.Permission)14 User (net.dv8tion.jda.api.entities.User)14 Collectors (java.util.stream.Collectors)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 java.util (java.util)10 ArrayList (java.util.ArrayList)10 FormatterManager (com.sx4.bot.formatter.FormatterManager)9