use of io.discloader.discloader.network.json.UserJSON in project DiscLoader by R3alCl0ud.
the class Mentions method patch.
public void patch(UserJSON[] mentions, RoleJSON[] mention_roles, boolean mention_everyone) {
everyone = mention_everyone;
users.clear();
roles.clear();
for (UserJSON data : mentions) {
IUser user = EntityRegistry.getUserByID(data.id);
if (user == null)
user = EntityRegistry.addUser(data);
users.put(SnowflakeUtil.parse(data.id), user);
}
if (guild != null) {
for (RoleJSON data : mention_roles) {
long id = SnowflakeUtil.parse(data.id);
roles.put(id, guild.getRoles().get(id));
}
}
}
use of io.discloader.discloader.network.json.UserJSON 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;
}
use of io.discloader.discloader.network.json.UserJSON in project DiscLoader by R3alCl0ud.
the class DLUser method setAvatar.
/**
* Sets the currently logged in user's avatar
*
* @param avatarLocation
* The location on disk of the new avatar image
* @return A CompletableFuture that completes with {@code this} if successfull,
* or the error response if failed. Returns null if
* {@code this.id != this.loader.user.id}
*/
public CompletableFuture<DLUser> setAvatar(String avatarLocation) throws IOException {
CompletableFuture<DLUser> future = new CompletableFuture<>();
String base64 = "data:image/jpg;base64," + Base64.encodeBase64String(Files.readAllBytes(Paths.get(avatarLocation)));
CompletableFuture<UserJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.currentUser, new RESTOptions(new JSONObject().put("avatar", base64)), UserJSON.class);
cf.thenAcceptAsync(data -> {
setup(data);
future.complete(this);
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
Aggregations