use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class ChannelCategory method removeChannel.
@Override
public <T extends IGuildChannel> CompletableFuture<T> removeChannel(T channel) {
CompletableFuture<T> future = new CompletableFuture<>();
JSONObject settings = new JSONObject().put("parent_id", (String) null);
loader.rest.request(Methods.PATCH, Endpoints.channel(channel.getID()), new RESTOptions(settings), ChannelJSON.class).thenAcceptAsync(data -> {
@SuppressWarnings("unchecked") T newChannel = (T) EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), guild, false);
future.complete(newChannel);
}).exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.network.rest.RESTOptions 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;
}
use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class ChannelCategory method createVoiceChannel.
@Override
public CompletableFuture<IGuildVoiceChannel> createVoiceChannel(String name) {
CompletableFuture<IGuildVoiceChannel> future = new CompletableFuture<>();
JSONObject data = new JSONObject().put("parent_id", SnowflakeUtil.asString(this)).put("name", name).put("type", 2);
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.RESTOptions in project DiscLoader by R3alCl0ud.
the class GroupChannel method sendMessage.
/*
* (non-Javadoc)
*
* @see io.discloader.discloader.entity.channel.ITextChannel#sendMessage(java.
* lang.String, io.discloader.discloader.core.entity.RichEmbed,
* io.discloader.discloader.entity.sendable.Attachment)
*/
@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, Attachment attachment) {
SendableMessage sendable = new SendableMessage(content, false, embed, attachment, new File(attachment.filename));
CompletableFuture<IMessage> future = new CompletableFuture<>();
CompletableFuture<MessageJSON> mcf = loader.rest.request(Methods.POST, Endpoints.messages(getID()), new RESTOptions(sendable), MessageJSON.class);
mcf.thenAcceptAsync(e -> {
future.complete(new Message<>(this, e));
});
mcf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class GuildChannel method edit.
@Override
public CompletableFuture<? extends IGuildChannel> edit(String name, int position, boolean nsfw, IOverwrite... overwrites) throws PermissionsException {
CompletableFuture<IGuildChannel> future = new CompletableFuture<>();
JSONObject settings = new JSONObject().put("name", name).put("position", position).put("nsfw", nsfw).put("permission_overwrites", overwrites);
loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(settings), ChannelJSON.class).thenAcceptAsync(data -> {
IChannel newChannel = EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), getGuild(), false);
if (newChannel instanceof IGuildChannel)
future.complete((IGuildChannel) newChannel);
}).exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
Aggregations