Search in sources :

Example 66 with Argument

use of com.jockie.bot.core.argument.Argument in project Sx4 by sx4-discord-bot.

the class HalloweenCommand 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("halloween")).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 67 with Argument

use of com.jockie.bot.core.argument.Argument in project Sx4 by sx4-discord-bot.

the class HowToGoogleCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "query", endless = true) @Limit(max = 50) String query) {
    Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("google")).addQuery("q", query).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) Argument(com.jockie.bot.core.argument.Argument) Limit(com.sx4.bot.annotations.argument.Limit) ImageRequest(com.sx4.bot.entities.image.ImageRequest) Request(okhttp3.Request) ImageRequest(com.sx4.bot.entities.image.ImageRequest)

Example 68 with Argument

use of com.jockie.bot.core.argument.Argument in project Sx4 by sx4-discord-bot.

the class HueCommand 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("hue")).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 69 with Argument

use of com.jockie.bot.core.argument.Argument 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 70 with Argument

use of com.jockie.bot.core.argument.Argument 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.getChannel(), 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)

Aggregations

Argument (com.jockie.bot.core.argument.Argument)112 ModuleCategory (com.sx4.bot.category.ModuleCategory)112 Sx4Command (com.sx4.bot.core.Sx4Command)112 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)112 Permission (net.dv8tion.jda.api.Permission)101 Document (org.bson.Document)67 HttpCallback (com.sx4.bot.http.HttpCallback)60 Request (okhttp3.Request)59 PagedResult (com.sx4.bot.paged.PagedResult)58 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)54 Command (com.jockie.bot.core.command.Command)49 ExceptionUtility (com.sx4.bot.utility.ExceptionUtility)43 Bson (org.bson.conversions.Bson)42 List (java.util.List)41 Operators (com.sx4.bot.database.mongo.model.Operators)40 CommandId (com.sx4.bot.annotations.command.CommandId)39 Examples (com.sx4.bot.annotations.command.Examples)39 Collectors (java.util.stream.Collectors)38 ImageUrl (com.sx4.bot.annotations.argument.ImageUrl)35 ImageRequest (com.sx4.bot.entities.image.ImageRequest)33