Search in sources :

Example 21 with ChannelJSON

use of io.discloader.discloader.network.json.ChannelJSON in project DiscLoader by R3alCl0ud.

the class TextChannel method setTopic.

public CompletableFuture<IGuildTextChannel> setTopic(String topic) {
    if (!this.permissionsOf(guild.getCurrentMember()).hasAny(Permissions.MANAGE_CHANNELS, Permissions.ADMINISTRATOR) && !guild.isOwner()) {
        throw new PermissionsException("Insufficient Permissions");
    }
    if (topic.length() > 1024) {
        throw new RuntimeException("topic length [" + topic.length() + "] > 1024");
    }
    CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
    JSONObject payload = new JSONObject().put("topic", topic);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(payload), ChannelJSON.class);
    cf.thenAcceptAsync(data -> {
        IGuildTextChannel channel = (IGuildTextChannel) EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), getGuild(), false);
        future.complete(channel);
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) CompletableFuture(java.util.concurrent.CompletableFuture) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

Aggregations

ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)21 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)13 CompletableFuture (java.util.concurrent.CompletableFuture)13 IGuildTextChannel (io.discloader.discloader.entity.channel.IGuildTextChannel)8 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)7 JSONObject (org.json.JSONObject)7 IGuildVoiceChannel (io.discloader.discloader.entity.channel.IGuildVoiceChannel)5 ChannelPayload (io.discloader.discloader.network.rest.payloads.ChannelPayload)5 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)4 IChannel (io.discloader.discloader.entity.channel.IChannel)3 IGuild (io.discloader.discloader.entity.guild.IGuild)3 ChannelCreateEvent (io.discloader.discloader.common.event.channel.ChannelCreateEvent)1 ChannelDeleteEvent (io.discloader.discloader.common.event.channel.ChannelDeleteEvent)1 ChannelUpdateEvent (io.discloader.discloader.common.event.channel.ChannelUpdateEvent)1 GuildChannelUpdateEvent (io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)1 AccountTypeException (io.discloader.discloader.common.exceptions.AccountTypeException)1 GuildSyncException (io.discloader.discloader.common.exceptions.GuildSyncException)1 MissmatchException (io.discloader.discloader.common.exceptions.MissmatchException)1 UnauthorizedException (io.discloader.discloader.common.exceptions.UnauthorizedException)1 DLUser (io.discloader.discloader.core.entity.user.DLUser)1