use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class PrivateChannel 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 TextChannel method startTyping.
@Override
public CompletableFuture<Map<Long, IUser>> startTyping() {
CompletableFuture<Map<Long, IUser>> future = new CompletableFuture<>();
CompletableFuture<Void> cf = loader.rest.request(Methods.POST, Endpoints.channelTyping(getID()), new RESTOptions(), Void.class);
cf.thenAcceptAsync(n -> {
typing.put(loader.user.getID(), loader.user);
future.complete(typing);
});
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, String topic) {
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]");
}
if (topic.length() > 1024) {
throw new RuntimeException("Topic.length() out of bounds [" + topic.length() + " > 1024]");
}
CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
JSONObject payload = new JSONObject().put("name", sanitizeChannelName(name)).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;
}
use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class TextChannel method setNSFW.
@Override
public CompletableFuture<IGuildTextChannel> setNSFW(boolean nsfw) {
if (!this.permissionsOf(guild.getCurrentMember()).hasAny(Permissions.MANAGE_CHANNELS, Permissions.ADMINISTRATOR) && !guild.isOwner()) {
throw new PermissionsException("Insufficient Permissions");
}
CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
JSONObject payload = new JSONObject().put("nsfw", nsfw);
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 Guild method beginPrune.
@Override
public CompletableFuture<Integer> beginPrune(int days) {
if (!getCurrentMember().getPermissions().hasPermission(Permissions.KICK_MEMBERS))
throw new PermissionsException("Pruning members requires the 'KICK_MEMBERS' permission");
CompletableFuture<Integer> future = new CompletableFuture<>();
loader.rest.request(Methods.POST, Endpoints.guildPrune(getID()), new RESTOptions(), Integer.class).thenAcceptAsync(pruned -> {
future.complete(pruned);
});
return future;
}
Aggregations