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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations