use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class Message method edit.
/**
* Edit's the messages content. Only possible if the {@link DiscLoader loader}
* is the message's {@link #author}
*
* @param content
* The new content of the message
* @param embed
* The new embed for the message
* @return A Future that completes with {@literal this} when sucessfull
*/
@Override
public CompletableFuture<IMessage> edit(String content, RichEmbed embed) {
CompletableFuture<IMessage> future = new CompletableFuture<>();
if (!canEdit()) {
future.completeExceptionally(new PermissionsException("Only messages author by you can be editted"));
return future;
}
SendableMessage sendable = null;
Attachment attachment = null;
File file = null;
if (embed != null) {
if ((embed.getThumbnail() != null && embed.getThumbnail().resource != null)) {
attachment = new Attachment(embed.getThumbnail().resource.getName());
}
if (embed.getThumbnail() != null && embed.getThumbnail().file != null) {
attachment = new Attachment(embed.getThumbnail().file.getName());
}
if ((embed.getImage() != null && embed.getImage().resource != null)) {
attachment = new Attachment(embed.getImage().resource.getName());
}
if (embed.getImage() != null && embed.getImage().file != null) {
attachment = new Attachment(embed.getImage().file.getName());
}
}
sendable = new SendableMessage(content, false, embed, attachment, file);
CompletableFuture<MessageJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.message(getChannel().getID(), getID()), new RESTOptions(sendable), MessageJSON.class);
cf.thenAcceptAsync(messageJSON -> {
future.complete(EntityBuilder.getChannelFactory().buildMessage(channel, messageJSON));
});
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 Message method deleteAllReactions.
@Override
public CompletableFuture<IMessage> deleteAllReactions() {
CompletableFuture<IMessage> future = new CompletableFuture<>();
if (channel instanceof IGuildChannel) {
if (!((IGuildChannel) channel).permissionsOf(guild.getCurrentMember()).hasPermission(Permissions.MANAGE_MESSAGES)) {
future.completeExceptionally(new PermissionsException());
return future;
}
}
CompletableFuture<Void> cf = loader.rest.request(Methods.DELETE, Endpoints.messageReactions(getChannel().getID(), getID()), new RESTOptions(), Void.class);
cf.thenAcceptAsync(Null -> {
future.complete(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 Reaction method getUsers.
@Override
public CompletableFuture<List<IUser>> getUsers() {
CompletableFuture<List<IUser>> future = new CompletableFuture<>();
CompletableFuture<IUser[]> cf = message.getLoader().rest.request(Methods.GET, Endpoints.messageReaction(message.getChannel().getID(), message.getID(), SnowflakeUtil.asString(emoji)), new RESTOptions(), IUser[].class);
cf.thenAcceptAsync(ius -> {
List<IUser> users = new ArrayList<>();
for (IUser usr : ius) {
users.add(usr);
}
future.complete(users);
});
return future;
// return new RESTAction<List<IUser>>(message.getLoader()) {
//
// @Override
// public CompletableFuture<List<IUser>> execute() {
// return
// super.execute(loader.rest.makeRequest(Endpoints.messageReaction(message.getChannel().getID(),
// message.getID(), SnowflakeUtil.asString(emoji)), Methods.GET, true));
// }
//
// @Override
// public void complete(String text, Throwable ex) {
// if (ex != null) {
// future.completeExceptionally(ex);
// return;
// }
// }
// }.execute();
}
use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class DLUser method getOAuth2Application.
/**
* Gets the OAuth2 application of the logged in user, if {@link User#isBot()}
* returns true
*
* @return A Future that completes with a new {@link OAuth2Application} if
* successful.
* @throws AccountTypeException
* Thrown if the account the client is logged in as is a user
* account.
*/
public CompletableFuture<OAuth2Application> getOAuth2Application() {
if (!isBot()) {
throw new AccountTypeException("Cannot fetch the OAuth2Application details of a User Account.");
}
CompletableFuture<OAuth2Application> future = new CompletableFuture<>();
CompletableFuture<OAuthApplicationJSON> cf = getLoader().rest.request(Methods.GET, Endpoints.currentOAuthApplication, new RESTOptions(), OAuthApplicationJSON.class);
cf.thenAcceptAsync(appData -> {
IUser owner = EntityRegistry.addUser(appData.owner);
future.complete(new OAuth2Application(appData, owner));
});
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 DLUser method setUsername.
/**
* Set's the currently logged in user's username.
*
* @param username
* The new username for the account
* @return A Future that completes with a {@link User} Object if successful
*/
public CompletableFuture<DLUser> setUsername(String username) {
CompletableFuture<DLUser> future = new CompletableFuture<>();
CompletableFuture<UserJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.currentUser, new RESTOptions(new JSONObject().put("username", username)), UserJSON.class);
cf.thenAcceptAsync(data -> {
setup(data);
future.complete(this);
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
Aggregations