Search in sources :

Example 1 with ChannelPayload

use of io.discloader.discloader.network.rest.payloads.ChannelPayload in project DiscLoader by R3alCl0ud.

the class ChannelCategory method createTextChannel.

@Override
public CompletableFuture<IGuildTextChannel> createTextChannel(String name, IOverwrite... overwrites) {
    CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
    ChannelPayload data = new ChannelPayload(name, ChannelTypes.TEXT, overwrites);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getGuild().getID()), new RESTOptions(data), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildTextChannel channel = (IGuildTextChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), getGuild(), false);
            if (channel != null)
                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) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) ChannelPayload(io.discloader.discloader.network.rest.payloads.ChannelPayload) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel)

Example 2 with ChannelPayload

use of io.discloader.discloader.network.rest.payloads.ChannelPayload in project DiscLoader by R3alCl0ud.

the class ChannelCategory method createVoiceChannel.

@Override
public CompletableFuture<IGuildVoiceChannel> createVoiceChannel(String name, IOverwrite... overwrites) {
    CompletableFuture<IGuildVoiceChannel> future = new CompletableFuture<>();
    ChannelPayload data = new ChannelPayload(name, ChannelTypes.VOICE, overwrites);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getGuild().getID()), new RESTOptions(data), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildVoiceChannel channel = (IGuildVoiceChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), getGuild(), false);
            if (channel != null)
                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) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) ChannelPayload(io.discloader.discloader.network.rest.payloads.ChannelPayload) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel)

Example 3 with ChannelPayload

use of io.discloader.discloader.network.rest.payloads.ChannelPayload in project DiscLoader by R3alCl0ud.

the class Guild method createTextChannel.

@Override
public CompletableFuture<IGuildTextChannel> createTextChannel(String name, IChannelCategory category, IOverwrite... overwrites) {
    CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
    if (!hasPermission(Permissions.MANAGE_CHANNELS)) {
        PermissionsException ex = new PermissionsException("Insufficient Permissions");
        future.completeExceptionally(ex);
        // return early
        return future;
    }
    ChannelPayload data = new ChannelPayload(name, ChannelTypes.TEXT, overwrites);
    data.setParent(category);
    CompletableFuture<ChannelJSON> cf = getLoader().rest.request(Methods.POST, Endpoints.guildChannels(getID()), new RESTOptions(data), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        IGuildTextChannel channel = (IGuildTextChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), this, 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) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) ChannelPayload(io.discloader.discloader.network.rest.payloads.ChannelPayload) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

Example 4 with ChannelPayload

use of io.discloader.discloader.network.rest.payloads.ChannelPayload in project DiscLoader by R3alCl0ud.

the class Guild method createVoiceChannel.

@Override
public CompletableFuture<IGuildVoiceChannel> createVoiceChannel(String name, int bitRate, int userLimit, IChannelCategory category, IOverwrite... overwrites) {
    CompletableFuture<IGuildVoiceChannel> future = new CompletableFuture<>();
    if (!hasPermission(Permissions.MANAGE_CHANNELS)) {
        PermissionsException ex = new PermissionsException("Insufficient Permissions");
        future.completeExceptionally(ex);
        // return early
        return future;
    }
    // normalize
    bitRate = Math.max(8, Math.min(96, bitRate)) * 1000;
    // normalize
    userLimit = Math.max(0, Math.min(99, userLimit));
    ChannelPayload data = new ChannelPayload(name, bitRate, userLimit, overwrites);
    if (category != null && getChannelCategoryByID(category.getID()) != null) {
        data.setParent(category);
    }
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getID()), new RESTOptions(data), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildVoiceChannel channel = (IGuildVoiceChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), this, false);
            if (channel != null)
                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) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) ChannelPayload(io.discloader.discloader.network.rest.payloads.ChannelPayload) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

Example 5 with ChannelPayload

use of io.discloader.discloader.network.rest.payloads.ChannelPayload in project DiscLoader by R3alCl0ud.

the class ChannelCategory method createChannel.

@Override
public CompletableFuture<IGuildChannel> createChannel(String name, ChannelTypes type, IOverwrite... overwrites) {
    CompletableFuture<IGuildChannel> future = new CompletableFuture<>();
    // JSONObject data = new JSONObject().put("parent_id",
    // SnowflakeUtil.asString(this)).put("name", name).put("type", type.toInt()).;
    ChannelPayload data = new ChannelPayload(name, type, overwrites);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getGuild().getID()), new RESTOptions(data), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildChannel channel = (IGuildChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), getGuild(), false);
            if (channel != null)
                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) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) ChannelPayload(io.discloader.discloader.network.rest.payloads.ChannelPayload)

Aggregations

ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)5 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)5 ChannelPayload (io.discloader.discloader.network.rest.payloads.ChannelPayload)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)2 IGuildTextChannel (io.discloader.discloader.entity.channel.IGuildTextChannel)2 IGuildVoiceChannel (io.discloader.discloader.entity.channel.IGuildVoiceChannel)2 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)1