Search in sources :

Example 1 with DeferredRestAction

use of net.dv8tion.jda.internal.requests.DeferredRestAction in project JDA by DV8FromTheWorld.

the class Guild method retrieveEmote.

/**
 * Retrieves a listed emote together with its respective creator.
 *
 * <p>Note that {@link ListedEmote#getUser()} is only available if the currently
 * logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES_AND_STICKERS Permission.MANAGE_EMOTES_AND_STICKERS}.
 *
 * <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
 * the returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} include the following:
 * <ul>
 *     <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_EMOJI UNKNOWN_EMOJI}
 *     <br>If the provided emote does not correspond to an emote in this guild anymore</li>
 * </ul>
 *
 * @param  emote
 *         The emote
 *
 * @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.ListedEmote ListedEmote}
 *
 * @since  3.8.0
 */
@Nonnull
@CheckReturnValue
default RestAction<ListedEmote> retrieveEmote(@Nonnull Emote emote) {
    Checks.notNull(emote, "Emote");
    if (emote.getGuild() != null)
        Checks.check(emote.getGuild().equals(this), "Emote must be from the same Guild!");
    JDA jda = getJDA();
    return new DeferredRestAction<>(jda, ListedEmote.class, () -> {
        if (emote instanceof ListedEmote) {
            ListedEmote listedEmote = (ListedEmote) emote;
            if (listedEmote.hasUser() || !getSelfMember().hasPermission(Permission.MANAGE_EMOTES_AND_STICKERS))
                return listedEmote;
        }
        return null;
    }, () -> retrieveEmoteById(emote.getId()));
}
Also used : JDA(net.dv8tion.jda.api.JDA) DeferredRestAction(net.dv8tion.jda.internal.requests.DeferredRestAction) CheckReturnValue(javax.annotation.CheckReturnValue) Nonnull(javax.annotation.Nonnull)

Example 2 with DeferredRestAction

use of net.dv8tion.jda.internal.requests.DeferredRestAction in project JDA by DV8FromTheWorld.

the class UserImpl method retrieveProfile.

@Nonnull
@Override
public RestAction<Profile> retrieveProfile() {
    return new DeferredRestAction<>(getJDA(), Profile.class, this::getProfile, () -> {
        Route.CompiledRoute route = Route.Users.GET_USER.compile(getId());
        return new RestActionImpl<>(getJDA(), route, (response, request) -> {
            DataObject json = response.getObject();
            String bannerId = json.getString("banner", null);
            int accentColor = json.getInt("accent_color", User.DEFAULT_ACCENT_COLOR_RAW);
            return new Profile(getIdLong(), bannerId, accentColor);
        });
    });
}
Also used : RestActionImpl(net.dv8tion.jda.internal.requests.RestActionImpl) DataObject(net.dv8tion.jda.api.utils.data.DataObject) DeferredRestAction(net.dv8tion.jda.internal.requests.DeferredRestAction) Route(net.dv8tion.jda.internal.requests.Route) Nonnull(javax.annotation.Nonnull)

Example 3 with DeferredRestAction

use of net.dv8tion.jda.internal.requests.DeferredRestAction in project JDA by DV8FromTheWorld.

the class UserImpl method openPrivateChannel.

@Nonnull
@Override
public RestAction<PrivateChannel> openPrivateChannel() {
    return new DeferredRestAction<>(getJDA(), PrivateChannel.class, this::getPrivateChannel, () -> {
        Route.CompiledRoute route = Route.Self.CREATE_PRIVATE_CHANNEL.compile();
        DataObject body = DataObject.empty().put("recipient_id", getId());
        return new RestActionImpl<>(getJDA(), route, body, (response, request) -> {
            PrivateChannel priv = api.getEntityBuilder().createPrivateChannel(response.getObject(), this);
            UserImpl.this.privateChannelId = priv.getIdLong();
            return priv;
        });
    });
}
Also used : PrivateChannel(net.dv8tion.jda.api.entities.PrivateChannel) RestActionImpl(net.dv8tion.jda.internal.requests.RestActionImpl) DataObject(net.dv8tion.jda.api.utils.data.DataObject) DeferredRestAction(net.dv8tion.jda.internal.requests.DeferredRestAction) Route(net.dv8tion.jda.internal.requests.Route) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)3 DeferredRestAction (net.dv8tion.jda.internal.requests.DeferredRestAction)3 DataObject (net.dv8tion.jda.api.utils.data.DataObject)2 RestActionImpl (net.dv8tion.jda.internal.requests.RestActionImpl)2 Route (net.dv8tion.jda.internal.requests.Route)2 CheckReturnValue (javax.annotation.CheckReturnValue)1 JDA (net.dv8tion.jda.api.JDA)1 PrivateChannel (net.dv8tion.jda.api.entities.PrivateChannel)1