Search in sources :

Example 21 with ImageUrl

use of com.sx4.bot.annotations.argument.ImageUrl in project Sx4 by sx4-discord-bot.

the class InvertCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "image url", endless = true, acceptEmpty = true) @ImageUrl String imageUrl) {
    Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("invert")).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
    event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> ImageUtility.getImageMessage(event, response).queue());
}
Also used : ModuleCategory(com.sx4.bot.category.ModuleCategory) Request(okhttp3.Request) ImageRequest(com.sx4.bot.entities.image.ImageRequest) HttpCallback(com.sx4.bot.http.HttpCallback) ImageUtility(com.sx4.bot.utility.ImageUtility) Sx4Command(com.sx4.bot.core.Sx4Command) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) Permission(net.dv8tion.jda.api.Permission) ImageUrl(com.sx4.bot.annotations.argument.ImageUrl) Argument(com.jockie.bot.core.argument.Argument) ImageRequest(com.sx4.bot.entities.image.ImageRequest) Request(okhttp3.Request) ImageRequest(com.sx4.bot.entities.image.ImageRequest)

Example 22 with ImageUrl

use of com.sx4.bot.annotations.argument.ImageUrl in project Sx4 by sx4-discord-bot.

the class MostCommonColourCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "image url", acceptEmpty = true, endless = true) @ImageUrl String imageUrl) {
    Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("common-colour")).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
    event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
        if (!response.isSuccessful()) {
            ImageUtility.getErrorMessage(event.getTextChannel(), response.code(), response.body().string()).queue();
            return;
        }
        Document data = Document.parse(response.body().string());
        Document common = data.getList("colours", Document.class).get(0);
        int colour = common.getInteger("colour");
        EmbedBuilder embed = new EmbedBuilder().setTitle("Most Common Colour").setThumbnail(imageUrl).setColor(ImageUtility.getEmbedColour(colour)).addField("Colour", String.format("Hex: #%s\nRGB: %s", ColourUtility.toHexString(colour), ColourUtility.toRGBString(colour)), true).addField("Pixels", String.format("Amount: %,d", common.getInteger("pixels")), true);
        event.reply(embed.build()).queue();
    });
}
Also used : Document(org.bson.Document) Request(okhttp3.Request) ImageRequest(com.sx4.bot.entities.image.ImageRequest) HttpCallback(com.sx4.bot.http.HttpCallback) ImageUtility(com.sx4.bot.utility.ImageUtility) Sx4Command(com.sx4.bot.core.Sx4Command) Permission(net.dv8tion.jda.api.Permission) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ModuleCategory(com.sx4.bot.category.ModuleCategory) ColourUtility(com.sx4.bot.utility.ColourUtility) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) ImageUrl(com.sx4.bot.annotations.argument.ImageUrl) Argument(com.jockie.bot.core.argument.Argument) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ImageRequest(com.sx4.bot.entities.image.ImageRequest) Request(okhttp3.Request) ImageRequest(com.sx4.bot.entities.image.ImageRequest) Document(org.bson.Document)

Example 23 with ImageUrl

use of com.sx4.bot.annotations.argument.ImageUrl in project Sx4 by sx4-discord-bot.

the class LoggerCommand method avatar.

@Command(value = "avatar", description = "Set the avatar of the webhook that sends logs")
@CommandId(424)
@Examples({ "logger avatar #logs Shea#6653", "logger avatar https://i.imgur.com/i87lyNO.png" })
@Premium
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void avatar(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true) TextChannel channel, @Argument(value = "avatar", endless = true, acceptEmpty = true) @ImageUrl String url) {
    TextChannel effectiveChannel = channel == null ? event.getTextChannel() : channel;
    event.getMongo().updateLogger(Filters.eq("channelId", effectiveChannel.getIdLong()), Updates.set("webhook.avatar", url)).whenComplete((result, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        if (result.getModifiedCount() == 0) {
            event.replyFailure("Your webhook avatar for that logger was already set to that").queue();
            return;
        }
        event.replySuccess("Your webhook avatar has been updated for that logger, this only works with premium <https://patreon.com/Sx4>").queue();
    });
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command)

Aggregations

Sx4Command (com.sx4.bot.core.Sx4Command)23 Argument (com.jockie.bot.core.argument.Argument)22 ModuleCategory (com.sx4.bot.category.ModuleCategory)22 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)22 HttpCallback (com.sx4.bot.http.HttpCallback)22 Request (okhttp3.Request)22 ImageUrl (com.sx4.bot.annotations.argument.ImageUrl)21 ImageRequest (com.sx4.bot.entities.image.ImageRequest)21 ImageUtility (com.sx4.bot.utility.ImageUtility)21 Permission (net.dv8tion.jda.api.Permission)20 ImageError (com.sx4.bot.entities.image.ImageError)3 Document (org.bson.Document)3 DefaultNumber (com.sx4.bot.annotations.argument.DefaultNumber)2 Limit (com.sx4.bot.annotations.argument.Limit)2 PagedResult (com.sx4.bot.paged.PagedResult)2 ColourUtility (com.sx4.bot.utility.ColourUtility)2 List (java.util.List)2 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)2 Command (com.jockie.bot.core.command.Command)1 Option (com.jockie.bot.core.option.Option)1