Search in sources :

Example 1 with UserJSON

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));
        }
    }
}
Also used : UserJSON(io.discloader.discloader.network.json.UserJSON) IUser(io.discloader.discloader.entity.user.IUser) RoleJSON(io.discloader.discloader.network.json.RoleJSON)

Example 2 with UserJSON

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;
}
Also used : UserJSON(io.discloader.discloader.network.json.UserJSON) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) JSONObject(org.json.JSONObject)

Example 3 with UserJSON

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;
}
Also used : UserJSON(io.discloader.discloader.network.json.UserJSON) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) JSONObject(org.json.JSONObject)

Aggregations

UserJSON (io.discloader.discloader.network.json.UserJSON)3 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 JSONObject (org.json.JSONObject)2 IUser (io.discloader.discloader.entity.user.IUser)1 RoleJSON (io.discloader.discloader.network.json.RoleJSON)1