Search in sources :

Example 16 with ImageRequest

use of com.sx4.bot.entities.image.ImageRequest in project Sx4 by sx4-discord-bot.

the class ScrollCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "text", endless = true) @Limit(max = 45) String text) {
    Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("scroll")).addQuery("text", text).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 17 with ImageRequest

use of com.sx4.bot.entities.image.ImageRequest in project Sx4 by sx4-discord-bot.

the class ShipCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "first user") Member firstMember, @Argument(value = "second user", endless = true, nullDefault = true) Member secondMember) {
    User firstUser = firstMember.getUser();
    User secondUser = secondMember == null ? event.getAuthor() : secondMember.getUser();
    this.random.setSeed(firstUser.getIdLong() + secondUser.getIdLong());
    int percent = this.random.nextInt(100) + 1;
    String firstName = firstUser.getName(), secondName = secondUser.getName();
    String shipName = firstName.substring(0, (int) Math.ceil((double) firstName.length() / 2)) + secondName.substring((int) Math.ceil((double) secondName.length() / 2));
    String message = String.format("Ship Name: **%s**\nLove Percentage: **%d%%**", shipName, percent);
    Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("ship")).addQuery("first_image", firstUser.getEffectiveAvatarUrl()).addQuery("second_image", secondUser.getEffectiveAvatarUrl()).addQuery("percent", percent).build(event.getConfig().getImageWebserver());
    if (event.getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_ATTACH_FILES)) {
        event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
            MessageAction action = ImageUtility.getImageMessage(event, response);
            if (response.isSuccessful()) {
                action.content(message);
            }
            action.queue();
        });
    } else {
        event.reply(message).queue();
    }
}
Also used : 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) Random(java.util.Random) Member(net.dv8tion.jda.api.entities.Member) User(net.dv8tion.jda.api.entities.User) ModuleCategory(com.sx4.bot.category.ModuleCategory) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction) Argument(com.jockie.bot.core.argument.Argument) User(net.dv8tion.jda.api.entities.User) ImageRequest(com.sx4.bot.entities.image.ImageRequest) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction) Request(okhttp3.Request) ImageRequest(com.sx4.bot.entities.image.ImageRequest)

Example 18 with ImageRequest

use of com.sx4.bot.entities.image.ImageRequest in project Sx4 by sx4-discord-bot.

the class StatusCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "status") Status status, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
    Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("status")).addQuery("image", member == null ? event.getMember().getEffectiveAvatarUrl() : member.getEffectiveAvatarUrl()).addQuery("status", status.toString().toLowerCase()).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) Member(net.dv8tion.jda.api.entities.Member) 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 19 with ImageRequest

use of com.sx4.bot.entities.image.ImageRequest in project Sx4 by sx4-discord-bot.

the class TrashCommand 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("trash")).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 20 with ImageRequest

use of com.sx4.bot.entities.image.ImageRequest in project Sx4 by sx4-discord-bot.

the class TrumpTweetCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "text", endless = true) @Limit(max = 280) String text) {
    Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("trump")).addQuery("text", ImageUtility.escapeMentions(event.getGuild(), text)).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)

Aggregations

ImageRequest (com.sx4.bot.entities.image.ImageRequest)35 HttpCallback (com.sx4.bot.http.HttpCallback)35 ModuleCategory (com.sx4.bot.category.ModuleCategory)34 Sx4Command (com.sx4.bot.core.Sx4Command)34 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)34 Argument (com.jockie.bot.core.argument.Argument)33 ImageUtility (com.sx4.bot.utility.ImageUtility)33 Request (okhttp3.Request)33 Permission (net.dv8tion.jda.api.Permission)31 ImageUrl (com.sx4.bot.annotations.argument.ImageUrl)21 Limit (com.sx4.bot.annotations.argument.Limit)8 Member (net.dv8tion.jda.api.entities.Member)8 Document (org.bson.Document)8 User (net.dv8tion.jda.api.entities.User)6 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)5 DefaultNumber (com.sx4.bot.annotations.argument.DefaultNumber)3 ImageError (com.sx4.bot.entities.image.ImageError)3 ColourUtility (com.sx4.bot.utility.ColourUtility)3 Option (com.jockie.bot.core.option.Option)2 Colour (com.sx4.bot.annotations.argument.Colour)2