Search in sources :

Example 1 with JDAImpl

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);
            });
        });
    }
}
Also used : Message(net.dv8tion.jda.api.entities.Message) OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) DataArray(net.dv8tion.jda.api.utils.data.DataArray) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) UserImpl(net.dv8tion.jda.internal.entities.UserImpl) ISnowflake(net.dv8tion.jda.api.entities.ISnowflake) InteractionImpl(net.dv8tion.jda.internal.interactions.InteractionImpl) Command(net.dv8tion.jda.api.interactions.commands.Command) ArrayList(java.util.ArrayList) CommandInteractionPayload(net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload) Objects(java.util.Objects) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) EntityBuilder(net.dv8tion.jda.internal.entities.EntityBuilder) List(java.util.List) OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) JDAImpl(net.dv8tion.jda.internal.JDAImpl) TLongObjectMap(gnu.trove.map.TLongObjectMap) DataObject(net.dv8tion.jda.api.utils.data.DataObject) MemberImpl(net.dv8tion.jda.internal.entities.MemberImpl) Nonnull(javax.annotation.Nonnull) GuildImpl(net.dv8tion.jda.internal.entities.GuildImpl) GuildImpl(net.dv8tion.jda.internal.entities.GuildImpl) DataObject(net.dv8tion.jda.api.utils.data.DataObject) MemberImpl(net.dv8tion.jda.internal.entities.MemberImpl) UserImpl(net.dv8tion.jda.internal.entities.UserImpl) Objects(java.util.Objects) EntityBuilder(net.dv8tion.jda.internal.entities.EntityBuilder) ISnowflake(net.dv8tion.jda.api.entities.ISnowflake)

Example 2 with JDAImpl

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);
}
Also used : JDAImpl(net.dv8tion.jda.internal.JDAImpl) WebSocketClient(net.dv8tion.jda.internal.requests.WebSocketClient)

Example 3 with JDAImpl

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);
    });
}
Also used : ArrayList(java.util.ArrayList) JDAImpl(net.dv8tion.jda.internal.JDAImpl) UncheckedIOException(java.io.UncheckedIOException) EntityBuilder(net.dv8tion.jda.internal.entities.EntityBuilder) DataArray(net.dv8tion.jda.api.utils.data.DataArray) RestActionImpl(net.dv8tion.jda.internal.requests.RestActionImpl) AuditableRestActionImpl(net.dv8tion.jda.internal.requests.restaction.AuditableRestActionImpl) Webhook(net.dv8tion.jda.api.entities.Webhook) Route(net.dv8tion.jda.internal.requests.Route) Nonnull(javax.annotation.Nonnull)

Example 4 with JDAImpl

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")));
}
Also used : JDAImpl(net.dv8tion.jda.internal.JDAImpl) Nonnull(javax.annotation.Nonnull)

Example 5 with JDAImpl

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);
    });
}
Also used : DataObject(net.dv8tion.jda.api.utils.data.DataObject) JDAImpl(net.dv8tion.jda.internal.JDAImpl) 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