use of net.dv8tion.jda.internal.entities.EntityBuilder in project JDA by DV8FromTheWorld.
the class ThreadChannelPaginationActionImpl method handleSuccess.
@Override
protected void handleSuccess(Response response, Request<List<ThreadChannel>> request) {
DataObject obj = response.getObject();
DataArray selfThreadMembers = obj.getArray("members");
DataArray threads = obj.getArray("threads");
List<ThreadChannel> list = new ArrayList<>(threads.length());
EntityBuilder builder = api.getEntityBuilder();
TLongObjectMap<DataObject> selfThreadMemberMap = new TLongObjectHashMap<>();
for (int i = 0; i < selfThreadMembers.length(); i++) {
DataObject selfThreadMember = selfThreadMembers.getObject(i);
// Store the thread member based on the "id" which is the _thread's_ id, not the member's id (which would be our id)
selfThreadMemberMap.put(selfThreadMember.getLong("id"), selfThreadMember);
}
for (int i = 0; i < threads.length(); i++) {
try {
DataObject threadObj = threads.getObject(i);
DataObject selfThreadMemberObj = selfThreadMemberMap.get(threadObj.getLong("id", 0));
if (selfThreadMemberObj != null) {
// Combine the thread and self thread-member into a single object to model what we get from
// thread payloads (like from Gateway, etc)
threadObj.put("member", selfThreadMemberObj);
}
ThreadChannel thread = builder.createThreadChannel(threadObj, getGuild().getIdLong());
list.add(thread);
if (this.useCache)
this.cached.add(thread);
this.last = thread;
this.lastKey = last.getIdLong();
} catch (ParsingException | NullPointerException e) {
LOG.warn("Encountered exception in ThreadChannelPagination", e);
}
}
request.onSuccess(list);
}
use of net.dv8tion.jda.internal.entities.EntityBuilder in project JDA by DV8FromTheWorld.
the class GuildMembersChunkHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
final long guildId = content.getLong("guild_id");
DataArray members = content.getArray("members");
GuildImpl guild = (GuildImpl) getJDA().getGuildById(guildId);
if (guild != null) {
if (api.getClient().getChunkManager().handleChunk(guildId, content))
return null;
WebSocketClient.LOG.debug("Received member chunk for guild that is already in cache. GuildId: {} Count: {} Index: {}/{}", guildId, members.length(), content.getInt("chunk_index"), content.getInt("chunk_count"));
// Chunk handling
EntityBuilder builder = getJDA().getEntityBuilder();
TLongObjectMap<DataObject> presences = content.optArray("presences").map(it -> builder.convertToUserMap(o -> o.getObject("user").getUnsignedLong("id"), it)).orElseGet(TLongObjectHashMap::new);
for (int i = 0; i < members.length(); i++) {
DataObject object = members.getObject(i);
long userId = object.getObject("user").getUnsignedLong("id");
DataObject presence = presences.get(userId);
MemberImpl member = builder.createMember(guild, object, null, presence);
builder.updateMemberCache(member);
}
return null;
}
getJDA().getGuildSetupController().onMemberChunk(guildId, content);
return null;
}
use of net.dv8tion.jda.internal.entities.EntityBuilder in project JDA by DV8FromTheWorld.
the class MessageUpdateHandler method handleMessageEmbed.
private Long handleMessageEmbed(DataObject content) {
EntityBuilder builder = getJDA().getEntityBuilder();
final long messageId = content.getLong("id");
final long channelId = content.getLong("channel_id");
LinkedList<MessageEmbed> embeds = new LinkedList<>();
// TODO-v5-unified-channel-cache
// TODO-v5: handle for threads.
MessageChannel channel = getJDA().getTextChannelsView().get(channelId);
if (channel == null)
channel = getJDA().getNewsChannelById(channelId);
if (channel == null)
channel = getJDA().getPrivateChannelsView().get(channelId);
if (channel == null) {
getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
EventCache.LOG.debug("Received message update for embeds for a channel/group that JDA does not have cached yet.");
return null;
}
DataArray embedsJson = content.getArray("embeds");
for (int i = 0; i < embedsJson.length(); i++) embeds.add(builder.createMessageEmbed(embedsJson.getObject(i)));
getJDA().handleEvent(new MessageEmbedEvent(getJDA(), responseNumber, messageId, channel, embeds));
return null;
}
use of net.dv8tion.jda.internal.entities.EntityBuilder in project JDA by DV8FromTheWorld.
the class ReadyHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
EntityBuilder builder = getJDA().getEntityBuilder();
DataArray guilds = content.getArray("guilds");
// Make sure we don't have any duplicates here!
TLongObjectMap<DataObject> distinctGuilds = new TLongObjectHashMap<>();
for (int i = 0; i < guilds.length(); i++) {
DataObject guild = guilds.getObject(i);
long id = guild.getUnsignedLong("id");
DataObject previous = distinctGuilds.put(id, guild);
if (previous != null)
WebSocketClient.LOG.warn("Found duplicate guild for id {} in ready payload", id);
}
DataObject selfJson = content.getObject("user");
// Used to update SelfUser#getApplicationId
selfJson.put(// Used to update SelfUser#getApplicationId
"application_id", content.optObject("application").map(obj -> obj.getUnsignedLong("id")).orElse(selfJson.getUnsignedLong("id")));
builder.createSelfUser(selfJson);
if (getJDA().getGuildSetupController().setIncompleteCount(distinctGuilds.size())) {
distinctGuilds.forEachEntry((id, guild) -> {
getJDA().getGuildSetupController().onReady(id, guild);
return true;
});
}
handleReady(content);
return null;
}
use of net.dv8tion.jda.internal.entities.EntityBuilder 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);
});
}
Aggregations