Search in sources :

Example 11 with RestActionImpl

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

the class StageChannelImpl method requestToSpeak.

@Nonnull
@Override
public RestAction<Void> requestToSpeak() {
    Guild guild = getGuild();
    Route.CompiledRoute route = Route.Guilds.UPDATE_VOICE_STATE.compile(guild.getId(), "@me");
    DataObject body = DataObject.empty().put("channel_id", getId());
    // Stage moderators can bypass the request queue by just unsuppressing
    if (guild.getSelfMember().hasPermission(this, Permission.VOICE_MUTE_OTHERS))
        body.putNull("request_to_speak_timestamp").put("suppress", false);
    else
        body.put("request_to_speak_timestamp", OffsetDateTime.now().toString());
    if (!this.equals(guild.getSelfMember().getVoiceState().getChannel()))
        throw new IllegalStateException("Cannot request to speak without being connected to the stage channel!");
    return new RestActionImpl<>(getJDA(), route, body);
}
Also used : RestActionImpl(net.dv8tion.jda.internal.requests.RestActionImpl) DataObject(net.dv8tion.jda.api.utils.data.DataObject) Route(net.dv8tion.jda.internal.requests.Route) Nonnull(javax.annotation.Nonnull)

Example 12 with RestActionImpl

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

the class StageChannelImpl method cancelRequestToSpeak.

@Nonnull
@Override
public RestAction<Void> cancelRequestToSpeak() {
    Guild guild = getGuild();
    Route.CompiledRoute route = Route.Guilds.UPDATE_VOICE_STATE.compile(guild.getId(), "@me");
    DataObject body = DataObject.empty().putNull("request_to_speak_timestamp").put("suppress", true).put("channel_id", getId());
    if (!this.equals(guild.getSelfMember().getVoiceState().getChannel()))
        throw new IllegalStateException("Cannot cancel request to speak without being connected to the stage channel!");
    return new RestActionImpl<>(getJDA(), route, body);
}
Also used : RestActionImpl(net.dv8tion.jda.internal.requests.RestActionImpl) DataObject(net.dv8tion.jda.api.utils.data.DataObject) Route(net.dv8tion.jda.internal.requests.Route) Nonnull(javax.annotation.Nonnull)

Example 13 with RestActionImpl

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

the class GuildVoiceStateImpl method update.

private RestAction<Void> update(boolean suppress) {
    if (requestToSpeak == 0L || !(connectedChannel instanceof StageChannel))
        return new CompletedRestAction<>(api, null);
    Member selfMember = getGuild().getSelfMember();
    boolean isSelf = selfMember.equals(member);
    if (!isSelf && !selfMember.hasPermission(connectedChannel, Permission.VOICE_MUTE_OTHERS))
        throw new InsufficientPermissionException(connectedChannel, Permission.VOICE_MUTE_OTHERS);
    Route.CompiledRoute route = Route.Guilds.UPDATE_VOICE_STATE.compile(guild.getId(), isSelf ? "@me" : getId());
    DataObject body = DataObject.empty().put("channel_id", connectedChannel.getId()).put("suppress", suppress);
    return new RestActionImpl<>(getJDA(), route, body);
}
Also used : RestActionImpl(net.dv8tion.jda.internal.requests.RestActionImpl) DataObject(net.dv8tion.jda.api.utils.data.DataObject) InsufficientPermissionException(net.dv8tion.jda.api.exceptions.InsufficientPermissionException) Route(net.dv8tion.jda.internal.requests.Route)

Example 14 with RestActionImpl

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

the class GuildVoiceStateImpl method inviteSpeaker.

@Nonnull
@Override
public RestAction<Void> inviteSpeaker() {
    if (!(connectedChannel instanceof StageChannel))
        return new CompletedRestAction<>(api, null);
    if (!getGuild().getSelfMember().hasPermission(connectedChannel, Permission.VOICE_MUTE_OTHERS))
        throw new InsufficientPermissionException(connectedChannel, Permission.VOICE_MUTE_OTHERS);
    Route.CompiledRoute route = Route.Guilds.UPDATE_VOICE_STATE.compile(guild.getId(), getId());
    DataObject body = DataObject.empty().put("channel_id", connectedChannel.getId()).put("suppress", false).put("request_to_speak_timestamp", OffsetDateTime.now().toString());
    return new RestActionImpl<>(getJDA(), route, body);
}
Also used : RestActionImpl(net.dv8tion.jda.internal.requests.RestActionImpl) DataObject(net.dv8tion.jda.api.utils.data.DataObject) InsufficientPermissionException(net.dv8tion.jda.api.exceptions.InsufficientPermissionException) Route(net.dv8tion.jda.internal.requests.Route) Nonnull(javax.annotation.Nonnull)

Example 15 with RestActionImpl

use of net.dv8tion.jda.internal.requests.RestActionImpl 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)

Aggregations

RestActionImpl (net.dv8tion.jda.internal.requests.RestActionImpl)25 Route (net.dv8tion.jda.internal.requests.Route)24 Nonnull (javax.annotation.Nonnull)20 DataObject (net.dv8tion.jda.api.utils.data.DataObject)11 JDAImpl (net.dv8tion.jda.internal.JDAImpl)10 CheckReturnValue (javax.annotation.CheckReturnValue)7 DataArray (net.dv8tion.jda.api.utils.data.DataArray)7 InsufficientPermissionException (net.dv8tion.jda.api.exceptions.InsufficientPermissionException)6 EntityBuilder (net.dv8tion.jda.internal.entities.EntityBuilder)5 AuditableRestActionImpl (net.dv8tion.jda.internal.requests.restaction.AuditableRestActionImpl)5 MissingAccessException (net.dv8tion.jda.api.exceptions.MissingAccessException)3 ArrayList (java.util.ArrayList)2 net.dv8tion.jda.api.entities (net.dv8tion.jda.api.entities)2 DeferredRestAction (net.dv8tion.jda.internal.requests.DeferredRestAction)2 WebhookEmbed (club.minnced.discord.webhook.send.WebhookEmbed)1 WebhookEmbedBuilder (club.minnced.discord.webhook.send.WebhookEmbedBuilder)1 WebhookMessage (club.minnced.discord.webhook.send.WebhookMessage)1 WebhookMessageBuilder (club.minnced.discord.webhook.send.WebhookMessageBuilder)1 ErrorCategory (com.mongodb.ErrorCategory)1 MongoWriteException (com.mongodb.MongoWriteException)1