Search in sources :

Example 41 with HttpCallback

use of com.sx4.bot.http.HttpCallback 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 42 with HttpCallback

use of com.sx4.bot.http.HttpCallback 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 43 with HttpCallback

use of com.sx4.bot.http.HttpCallback 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)

Example 44 with HttpCallback

use of com.sx4.bot.http.HttpCallback in project Sx4 by sx4-discord-bot.

the class WhoWouldWinCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "first image url") @ImageUrl String firstImageUrl, @Argument(value = "second image url", endless = true, acceptEmpty = true) @ImageUrl String secondImageUrl) {
    Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("www")).addQuery("first_image", firstImageUrl).addQuery("second_image", secondImageUrl).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) 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 45 with HttpCallback

use of com.sx4.bot.http.HttpCallback in project Sx4 by sx4-discord-bot.

the class AvatarCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member, @Option(value = "global", description = "Forced to show their global avatar") boolean global) {
    Member effectiveMember = member == null ? event.getMember() : member;
    User user = effectiveMember.getUser();
    String avatar = global ? user.getEffectiveAvatarUrl() : effectiveMember.getEffectiveAvatarUrl();
    Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("median-colour")).addQuery("image", avatar).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());
        String sizedAvatar = avatar + "?size=1024";
        EmbedBuilder embed = new EmbedBuilder().setImage(sizedAvatar).setColor(data.getInteger("colour")).setAuthor(user.getAsTag(), sizedAvatar, user.getEffectiveAvatarUrl());
        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) 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) Option(com.jockie.bot.core.option.Option) Argument(com.jockie.bot.core.argument.Argument) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) User(net.dv8tion.jda.api.entities.User) ImageRequest(com.sx4.bot.entities.image.ImageRequest) Request(okhttp3.Request) ImageRequest(com.sx4.bot.entities.image.ImageRequest) Document(org.bson.Document) Member(net.dv8tion.jda.api.entities.Member)

Aggregations

HttpCallback (com.sx4.bot.http.HttpCallback)85 Request (okhttp3.Request)83 ModuleCategory (com.sx4.bot.category.ModuleCategory)68 Sx4Command (com.sx4.bot.core.Sx4Command)68 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)68 Permission (net.dv8tion.jda.api.Permission)67 Argument (com.jockie.bot.core.argument.Argument)63 Document (org.bson.Document)51 ImageRequest (com.sx4.bot.entities.image.ImageRequest)35 ImageUtility (com.sx4.bot.utility.ImageUtility)33 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)33 ImageUrl (com.sx4.bot.annotations.argument.ImageUrl)28 PagedResult (com.sx4.bot.paged.PagedResult)24 StandardCharsets (java.nio.charset.StandardCharsets)23 URLEncoder (java.net.URLEncoder)22 java.util (java.util)20 OffsetDateTime (java.time.OffsetDateTime)18 Collectors (java.util.stream.Collectors)18 Bson (org.bson.conversions.Bson)17 Command (com.jockie.bot.core.command.Command)16