Search in sources :

Example 1 with UserObject

use of sx.blah.discord.api.internal.json.objects.UserObject in project Discord4J by Discord4J.

the class Reaction method getUsers.

@Override
public List<IUser> getUsers() {
    List<IUser> users = new ArrayList<>();
    String emoji = getEmoji().isUnicode() ? getEmoji().getName() : getEmoji().getName() + ":" + getEmoji().getStringID();
    String endpoint = String.format(DiscordEndpoints.REACTIONS_USER_LIST, getMessage().getChannel().getStringID(), getMessage().getStringID(), emoji);
    String after = "0";
    while (users.size() < count) {
        UserObject[] json = ((DiscordClientImpl) getClient()).REQUESTS.GET.makeRequest(endpoint + "?after=" + after + "&limit=100", UserObject[].class);
        for (UserObject obj : json) {
            users.add(getMessage().getShard().getUserByID(Long.parseUnsignedLong(obj.id)));
        }
        // Temporary measure so a refactor can be applied later.
        if (json.length == 0)
            break;
        after = json[json.length - 1].id;
    }
    return users;
}
Also used : ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser) UserObject(sx.blah.discord.api.internal.json.objects.UserObject) DiscordClientImpl(sx.blah.discord.api.internal.DiscordClientImpl)

Aggregations

ArrayList (java.util.ArrayList)1 DiscordClientImpl (sx.blah.discord.api.internal.DiscordClientImpl)1 UserObject (sx.blah.discord.api.internal.json.objects.UserObject)1 IUser (sx.blah.discord.handle.obj.IUser)1