use of net.dv8tion.jda.internal.JDAImpl 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.JDAImpl in project JDA by DV8FromTheWorld.
the class DirectAudioControllerImpl method connect.
@Override
public void connect(@Nonnull AudioChannel channel) {
Checks.notNull(channel, "Audio Channel");
JDAImpl jda = getJDA();
WebSocketClient client = jda.getClient();
client.queueAudioConnect(channel);
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class BaseGuildMessageChannelMixin method retrieveWebhooks.
@Nonnull
@Override
default RestAction<List<Webhook>> retrieveWebhooks() {
checkPermission(Permission.MANAGE_WEBHOOKS);
Route.CompiledRoute route = Route.Channels.GET_WEBHOOKS.compile(getId());
JDAImpl jda = (JDAImpl) getJDA();
return new RestActionImpl<>(jda, route, (response, request) -> {
DataArray array = response.getArray();
List<Webhook> webhooks = new ArrayList<>(array.length());
EntityBuilder builder = jda.getEntityBuilder();
for (int i = 0; i < array.length(); i++) {
try {
webhooks.add(builder.createWebhook(array.getObject(i)));
} catch (UncheckedIOException | NullPointerException e) {
JDAImpl.LOG.error("Error while creating websocket from json", e);
}
}
return Collections.unmodifiableList(webhooks);
});
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class GuildImpl method retrieveVanityInvite.
@Override
@Nonnull
public RestAction<VanityInvite> retrieveVanityInvite() {
checkPermission(Permission.MANAGE_SERVER);
JDAImpl api = getJDA();
Route.CompiledRoute route = Route.Guilds.GET_VANITY_URL.compile(getId());
return new RestActionImpl<>(api, route, (response, request) -> new VanityInvite(vanityCode, response.getObject().getInt("uses")));
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class GuildImpl method createEmote.
@Nonnull
@Override
public AuditableRestAction<Emote> createEmote(@Nonnull String name, @Nonnull Icon icon, @Nonnull Role... roles) {
checkPermission(Permission.MANAGE_EMOTES_AND_STICKERS);
Checks.inRange(name, 2, 32, "Emote name");
Checks.notNull(icon, "Emote icon");
Checks.notNull(roles, "Roles");
DataObject body = DataObject.empty();
body.put("name", name);
body.put("image", icon.getEncoding());
if (// making sure none of the provided roles are null before mapping them to the snowflake id
roles.length > 0)
body.put("roles", Stream.of(roles).filter(Objects::nonNull).map(ISnowflake::getId).collect(Collectors.toSet()));
JDAImpl jda = getJDA();
Route.CompiledRoute route = Route.Emotes.CREATE_EMOTE.compile(getId());
return new AuditableRestActionImpl<>(jda, route, body, (response, request) -> {
DataObject obj = response.getObject();
return jda.getEntityBuilder().createEmote(this, obj);
});
}
Aggregations