use of com.sx4.bot.annotations.argument.ImageUrl in project Sx4 by sx4-discord-bot.
the class CannyCommand 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("canny")).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> ImageUtility.getImageMessage(event, response).queue());
}
use of com.sx4.bot.annotations.argument.ImageUrl in project Sx4 by sx4-discord-bot.
the class ChristmasCommand 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("christmas")).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> ImageUtility.getImageMessage(event, response).queue());
}
use of com.sx4.bot.annotations.argument.ImageUrl in project Sx4 by sx4-discord-bot.
the class ColourCoverageCommand 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("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());
List<Document> colours = data.getList("colours", Document.class);
long totalPixels = colours.stream().mapToInt(colour -> colour.getInteger("pixels")).sum();
PagedResult<Document> paged = new PagedResult<>(event.getBot(), colours).setAuthor("Colours", null, imageUrl).setIncreasedIndex(true).setSelect().setPerPage(15).setDisplayFunction(colour -> {
int pixels = colour.getInteger("pixels");
return "`#" + ColourUtility.toHexString(colour.getInteger("colour")) + "` - " + pixels + " pixel" + (pixels == 1 ? "" : "s") + " (" + NumberUtility.DEFAULT_DECIMAL_FORMAT.format((pixels / (double) totalPixels) * 100) + "%)";
});
paged.execute(event);
});
}
use of com.sx4.bot.annotations.argument.ImageUrl in project Sx4 by sx4-discord-bot.
the class CropCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "image url") @ImageUrl String imageUrl, @Argument(value = "width") @Limit(min = 0) double width, @Argument(value = "height") @Limit(min = 0) @DefaultNumber(1) double height) {
Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("crop")).addQuery("w", width).addQuery("h", height).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
ImageUtility.getImageMessage(event, response, (body, error) -> {
if (error == ImageError.INVALID_QUERY_VALUE) {
return event.replyFailure(body.getString("message"));
}
return null;
}).queue();
});
}
use of com.sx4.bot.annotations.argument.ImageUrl in project Sx4 by sx4-discord-bot.
the class EdgeCommand 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("edge")).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> ImageUtility.getImageMessage(event, response).queue());
}
Aggregations