Search in sources :

Example 1 with CreateEmoji

use of io.discloader.discloader.entity.sendable.CreateEmoji in project DiscLoader by R3alCl0ud.

the class Guild method createEmoji.

@Override
public CompletableFuture<IGuildEmoji> createEmoji(String name, String image, IRole... roles) {
    CompletableFuture<IGuildEmoji> future = new CompletableFuture<>();
    String base64 = null;
    try {
        base64 = new String("data:image/jpg;base64," + Base64.encodeBase64String(Files.readAllBytes(Paths.get(image))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    String[] rids = new String[roles.length];
    for (int i = 0; i < rids.length; i++) {
        rids[i] = SnowflakeUtil.asString(roles[i]);
    }
    CreateEmoji ce = new CreateEmoji(name, base64, rids);
    CompletableFuture<EmojiJSON> cf = getLoader().rest.request(Methods.POST, Endpoints.guildEmojis(getID()), new RESTOptions(ce), EmojiJSON.class);
    cf.thenAcceptAsync(ed -> {
        future.complete(new GuildEmoji(ed, this));
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : IGuildEmoji(io.discloader.discloader.entity.guild.IGuildEmoji) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) CreateEmoji(io.discloader.discloader.entity.sendable.CreateEmoji) IGuildEmoji(io.discloader.discloader.entity.guild.IGuildEmoji) IOException(java.io.IOException) EmojiJSON(io.discloader.discloader.network.json.EmojiJSON)

Aggregations

IGuildEmoji (io.discloader.discloader.entity.guild.IGuildEmoji)1 CreateEmoji (io.discloader.discloader.entity.sendable.CreateEmoji)1 EmojiJSON (io.discloader.discloader.network.json.EmojiJSON)1 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)1 IOException (java.io.IOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1