use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class DiscLoader method getInvite.
/**
* @param code
* @return A CompletableFuture that completes with an IInvite object if
* successful.
*/
public CompletableFuture<IInvite> getInvite(String code) {
CompletableFuture<IInvite> future = new CompletableFuture<>();
CompletableFuture<InviteJSON> cf = rest.request(Methods.GET, Endpoints.invite(code), new RESTOptions(), InviteJSON.class);
cf.thenAcceptAsync(inviteJSON -> {
future.complete(new Invite(inviteJSON, this));
});
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 TextChannel method edit.
@Override
public CompletableFuture<IGuildTextChannel> edit(String name, int position) {
if (!this.permissionsOf(guild.getCurrentMember()).hasAny(Permissions.MANAGE_CHANNELS, Permissions.ADMINISTRATOR) && !guild.isOwner()) {
throw new PermissionsException("Insufficient Permissions");
}
if (name.length() < 2 || name.length() > 100) {
throw new RuntimeException("Name.length() out of bounds [2-100]");
}
CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
JSONObject payload = new JSONObject().put("name", sanitizeChannelName(name)).put("position", position);
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;
}
use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class TextChannel method sendMessage.
@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, File file) {
Attachment attachment = file == null ? null : new Attachment(file.getName());
SendableMessage sendable = new SendableMessage(content, false, embed, attachment, file);
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 VoiceChannel method edit.
/**
* Changes the channels settings
*
* @param name
* The new name for the channel
* @param position
* The new position for the channel
* @param bitrate
* The new {@link #bitrate}
* @param userLimit
* The new {@link #userLimit}
* @return A Future that completes with a voice channel if successful
*/
public CompletableFuture<IGuildVoiceChannel> edit(String name, int position, int bitrate, int userLimit) {
CompletableFuture<IGuildVoiceChannel> future = new CompletableFuture<>();
EditChannel d = new EditChannel(name, null, position, bitrate, userLimit);
CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(d), 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 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;
}
Aggregations