use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class TextChannel method setTopic.
public CompletableFuture<IGuildTextChannel> setTopic(String topic) {
if (!this.permissionsOf(guild.getCurrentMember()).hasAny(Permissions.MANAGE_CHANNELS, Permissions.ADMINISTRATOR) && !guild.isOwner()) {
throw new PermissionsException("Insufficient Permissions");
}
if (topic.length() > 1024) {
throw new RuntimeException("topic length [" + topic.length() + "] > 1024");
}
CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
JSONObject payload = new JSONObject().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 DiscLoader method login.
/**
* Connects the current instance of the {@link DiscLoader loader} into Discord's
* gateway servers
*
* @param token
* your API token
* @return A CompletableFuture that completes with {@code this} if successful.
*/
public CompletableFuture<DiscLoader> login(String token) {
if (rf != null && rf.isCompletedExceptionally())
return rf;
LOG.info("Attempting to login");
rf = new CompletableFuture<>();
Command.registerCommands();
this.token = token;
CompletableFuture<GatewayJSON> cf = rest.request(Methods.GET, Endpoints.gateway, new RESTOptions(), GatewayJSON.class);
cf.thenAcceptAsync(gateway -> {
try {
socket.connectSocket(gateway.url + DLUtil.GatewaySuffix);
} catch (Exception e) {
rf.completeExceptionally(e);
}
});
cf.exceptionally(e -> {
rf.completeExceptionally(e);
return null;
});
return rf;
}
Aggregations