Search in sources :

Example 26 with JDAImpl

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

the class GuildImpl method retrieveMemberById.

@Nonnull
@Override
public RestAction<Member> retrieveMemberById(long id, boolean update) {
    JDAImpl jda = getJDA();
    if (id == jda.getSelfUser().getIdLong())
        return new CompletedRestAction<>(jda, getSelfMember());
    return new DeferredRestAction<>(jda, Member.class, () -> getMember(id, update, jda), () -> {
        // otherwise we need to update the member with a REST request first to get the nickname/roles
        Route.CompiledRoute route = Route.Guilds.GET_MEMBER.compile(getId(), Long.toUnsignedString(id));
        return new RestActionImpl<>(jda, route, (resp, req) -> {
            MemberImpl member = jda.getEntityBuilder().createMember(this, resp.getObject());
            jda.getEntityBuilder().updateMemberCache(member);
            return member;
        });
    });
}
Also used : JDAImpl(net.dv8tion.jda.internal.JDAImpl) Nonnull(javax.annotation.Nonnull)

Example 27 with JDAImpl

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

the class MessageReactionBulkRemoveHandler method handleInternally.

@Override
protected Long handleInternally(DataObject content) {
    final long messageId = content.getLong("message_id");
    final long channelId = content.getLong("channel_id");
    JDAImpl jda = getJDA();
    if (!content.isNull("guild_id")) {
        long guildId = content.getUnsignedLong("guild_id");
        if (api.getGuildSetupController().isLocked(guildId))
            return guildId;
    }
    // TODO-v5-unified-channel-cache
    MessageChannel channel = jda.getTextChannelById(channelId);
    if (channel == null)
        channel = jda.getNewsChannelById(channelId);
    if (channel == null)
        channel = jda.getThreadChannelById(channelId);
    if (channel == null) {
        jda.getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        EventCache.LOG.debug("Received a reaction for a channel that JDA does not currently have cached channel_id: {} message_id: {}", channelId, messageId);
        return null;
    }
    jda.handleEvent(new MessageReactionRemoveAllEvent(jda, responseNumber, messageId, channel));
    return null;
}
Also used : MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) MessageReactionRemoveAllEvent(net.dv8tion.jda.api.events.message.react.MessageReactionRemoveAllEvent) JDAImpl(net.dv8tion.jda.internal.JDAImpl)

Example 28 with JDAImpl

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

the class GuildSetupNode method completeSetup.

private void completeSetup() {
    updateStatus(GuildSetupController.Status.BUILDING);
    JDAImpl api = getController().getJDA();
    for (TLongIterator it = removedMembers.iterator(); it.hasNext(); ) members.remove(it.next());
    removedMembers.clear();
    GuildImpl guild = api.getEntityBuilder().createGuild(id, partialGuild, members, expectedMemberCount);
    updateAudioManagerReference(guild);
    switch(type) {
        case AVAILABLE:
            api.handleEvent(new GuildAvailableEvent(api, api.getResponseTotal(), guild));
            getController().remove(id);
            break;
        case JOIN:
            api.handleEvent(new GuildJoinEvent(api, api.getResponseTotal(), guild));
            if (requestedChunk)
                getController().ready(id);
            else
                getController().remove(id);
            break;
        default:
            api.handleEvent(new GuildReadyEvent(api, api.getResponseTotal(), guild));
            getController().ready(id);
            break;
    }
    updateStatus(GuildSetupController.Status.READY);
    GuildSetupController.log.debug("Finished setup for guild {} firing cached events {}", id, cachedEvents.size());
    api.getClient().handle(cachedEvents);
    api.getEventCache().playbackCache(EventCache.Type.GUILD, id);
}
Also used : GuildImpl(net.dv8tion.jda.internal.entities.GuildImpl) GuildAvailableEvent(net.dv8tion.jda.api.events.guild.GuildAvailableEvent) GuildJoinEvent(net.dv8tion.jda.api.events.guild.GuildJoinEvent) JDAImpl(net.dv8tion.jda.internal.JDAImpl) GuildReadyEvent(net.dv8tion.jda.api.events.guild.GuildReadyEvent) TLongIterator(gnu.trove.iterator.TLongIterator)

Example 29 with JDAImpl

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

the class InteractionHookImpl method retrieveOriginal.

@Nonnull
@Override
public RestAction<Message> retrieveOriginal() {
    JDAImpl jda = (JDAImpl) getJDA();
    Route.CompiledRoute route = Route.Interactions.GET_ORIGINAL.compile(jda.getSelfUser().getApplicationId(), interaction.getToken());
    return onReady(new TriggerRestAction<>(jda, route, (response, request) -> jda.getEntityBuilder().createMessageWithChannel(response.getObject(), getInteraction().getMessageChannel(), false)));
}
Also used : Message(net.dv8tion.jda.api.entities.Message) Checks(net.dv8tion.jda.internal.utils.Checks) JDA(net.dv8tion.jda.api.JDA) ReentrantLock(java.util.concurrent.locks.ReentrantLock) TimeoutException(java.util.concurrent.TimeoutException) MiscUtil(net.dv8tion.jda.api.utils.MiscUtil) Route(net.dv8tion.jda.internal.requests.Route) Function(java.util.function.Function) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Future(java.util.concurrent.Future) WebhookMessageUpdateActionImpl(net.dv8tion.jda.internal.requests.restaction.WebhookMessageUpdateActionImpl) AbstractWebhookClient(net.dv8tion.jda.internal.entities.AbstractWebhookClient) JDAImpl(net.dv8tion.jda.internal.JDAImpl) InteractionHook(net.dv8tion.jda.api.interactions.InteractionHook) DataObject(net.dv8tion.jda.api.utils.data.DataObject) JDALogger(net.dv8tion.jda.internal.utils.JDALogger) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) RestAction(net.dv8tion.jda.api.requests.RestAction) TriggerRestAction(net.dv8tion.jda.internal.requests.restaction.TriggerRestAction) WebhookMessageActionImpl(net.dv8tion.jda.internal.requests.restaction.WebhookMessageActionImpl) JDAImpl(net.dv8tion.jda.internal.JDAImpl) Route(net.dv8tion.jda.internal.requests.Route) Nonnull(javax.annotation.Nonnull)

Example 30 with JDAImpl

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

the class IInviteContainerMixin method retrieveInvites.

@Nonnull
@Override
default RestAction<List<Invite>> retrieveInvites() {
    checkPermission(Permission.MANAGE_CHANNEL);
    final Route.CompiledRoute route = Route.Invites.GET_CHANNEL_INVITES.compile(getId());
    JDAImpl jda = (JDAImpl) getJDA();
    return new RestActionImpl<>(jda, route, (response, request) -> {
        EntityBuilder entityBuilder = jda.getEntityBuilder();
        DataArray array = response.getArray();
        List<Invite> invites = new ArrayList<>(array.length());
        for (int i = 0; i < array.length(); i++) invites.add(entityBuilder.createInvite(array.getObject(i)));
        return Collections.unmodifiableList(invites);
    });
}
Also used : RestActionImpl(net.dv8tion.jda.internal.requests.RestActionImpl) ArrayList(java.util.ArrayList) JDAImpl(net.dv8tion.jda.internal.JDAImpl) EntityBuilder(net.dv8tion.jda.internal.entities.EntityBuilder) Route(net.dv8tion.jda.internal.requests.Route) DataArray(net.dv8tion.jda.api.utils.data.DataArray) Invite(net.dv8tion.jda.api.entities.Invite) Nonnull(javax.annotation.Nonnull)

Aggregations

JDAImpl (net.dv8tion.jda.internal.JDAImpl)43 Nonnull (javax.annotation.Nonnull)19 Route (net.dv8tion.jda.internal.requests.Route)12 RestActionImpl (net.dv8tion.jda.internal.requests.RestActionImpl)10 DataObject (net.dv8tion.jda.api.utils.data.DataObject)8 DataArray (net.dv8tion.jda.api.utils.data.DataArray)7 EntityBuilder (net.dv8tion.jda.internal.entities.EntityBuilder)6 CheckReturnValue (javax.annotation.CheckReturnValue)5 AuditableRestActionImpl (net.dv8tion.jda.internal.requests.restaction.AuditableRestActionImpl)5 ExceptionEvent (net.dv8tion.jda.api.events.ExceptionEvent)4 InsufficientPermissionException (net.dv8tion.jda.api.exceptions.InsufficientPermissionException)4 ArrayList (java.util.ArrayList)3 LoginException (javax.security.auth.login.LoginException)3 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)3 JDA (net.dv8tion.jda.api.JDA)3 WebSocketClient (net.dv8tion.jda.internal.requests.WebSocketClient)3 Parser (com.jagrosh.jagtag.Parser)2 ByteBuffer (java.nio.ByteBuffer)2 List (java.util.List)2 MessageConfig (me.duncte123.botcommons.messaging.MessageConfig)2