use of net.dv8tion.jda.internal.entities.UserImpl in project JDA by DV8FromTheWorld.
the class CommandInteractionPayloadImpl method parseResolved.
private void parseResolved(JDAImpl jda, DataObject resolveJson) {
EntityBuilder entityBuilder = jda.getEntityBuilder();
resolveJson.optObject("users").ifPresent(users -> users.keys().forEach(userId -> {
DataObject userJson = users.getObject(userId);
UserImpl userArg = entityBuilder.createUser(userJson);
resolved.put(userArg.getIdLong(), userArg);
}));
resolveJson.optObject("attachments").ifPresent(attachments -> attachments.keys().forEach(id -> {
DataObject json = attachments.getObject(id);
Message.Attachment file = entityBuilder.createMessageAttachment(json);
resolved.put(file.getIdLong(), file);
}));
if (// Technically these can function in DMs too ...
guild != null) {
resolveJson.optObject("members").ifPresent(members -> members.keys().forEach(memberId -> {
DataObject userJson = resolveJson.getObject("users").getObject(memberId);
DataObject memberJson = members.getObject(memberId);
memberJson.put("user", userJson);
MemberImpl optionMember = entityBuilder.createMember((GuildImpl) guild, memberJson);
entityBuilder.updateMemberCache(optionMember);
// This basically upgrades user to member
resolved.put(optionMember.getIdLong(), optionMember);
}));
resolveJson.optObject("roles").ifPresent(roles -> roles.keys().stream().map(guild::getRoleById).filter(Objects::nonNull).forEach(role -> resolved.put(role.getIdLong(), role)));
resolveJson.optObject("channels").ifPresent(channels -> {
channels.keys().forEach(id -> {
ISnowflake channelObj = jda.getGuildChannelById(id);
if (channelObj != null)
resolved.put(channelObj.getIdLong(), channelObj);
});
});
}
}
use of net.dv8tion.jda.internal.entities.UserImpl in project JDA by DV8FromTheWorld.
the class JDAImpl method openPrivateChannelById.
@Nonnull
@Override
public RestAction<PrivateChannel> openPrivateChannelById(long userId) {
if (selfUser != null && userId == selfUser.getIdLong())
throw new UnsupportedOperationException("Cannot open private channel with yourself!");
return new DeferredRestAction<>(this, PrivateChannel.class, () -> {
User user = getUserById(userId);
if (user instanceof UserImpl)
return ((UserImpl) user).getPrivateChannel();
return null;
}, () -> {
Route.CompiledRoute route = Route.Self.CREATE_PRIVATE_CHANNEL.compile();
DataObject body = DataObject.empty().put("recipient_id", userId);
return new RestActionImpl<>(this, route, body, (response, request) -> getEntityBuilder().createPrivateChannel(response.getObject()));
});
}
Aggregations