Search in sources :

Example 1 with GroupChannelImpl

use of org.javacord.core.entity.channel.GroupChannelImpl in project Javacord by BtoBastian.

the class ReadyHandler method handle.

@Override
public void handle(JsonNode packet) {
    // Purge the cache first
    api.purgeCache();
    JsonNode guilds = packet.get("guilds");
    for (JsonNode guildJson : guilds) {
        if (guildJson.has("unavailable") && guildJson.get("unavailable").asBoolean()) {
            api.addUnavailableServerToCache(guildJson.get("id").asLong());
            continue;
        }
        new ServerImpl(api, guildJson);
    }
    // https://github.com/hammerandchisel/discord-api-docs/issues/184
    if (packet.has("private_channels")) {
        JsonNode privateChannels = packet.get("private_channels");
        for (JsonNode channelJson : privateChannels) {
            switch(ChannelType.fromId(channelJson.get("type").asInt())) {
                case PRIVATE_CHANNEL:
                    new PrivateChannelImpl(api, channelJson);
                    break;
                case GROUP_CHANNEL:
                    new GroupChannelImpl(api, channelJson);
                    break;
                default:
                    logger.warn("Unknown or unexpected channel type. Your Javacord version might be out of date!");
            }
        }
    }
    api.setYourself(new UserImpl(api, packet.get("user"), (MemberImpl) null, null));
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) UserImpl(org.javacord.core.entity.user.UserImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) PrivateChannelImpl(org.javacord.core.entity.channel.PrivateChannelImpl) GroupChannelImpl(org.javacord.core.entity.channel.GroupChannelImpl)

Example 2 with GroupChannelImpl

use of org.javacord.core.entity.channel.GroupChannelImpl in project Javacord by BtoBastian.

the class ChannelCreateHandler method handleGroupChannel.

/**
 * Handles a group channel creation.
 *
 * @param channel The channel data.
 */
private void handleGroupChannel(JsonNode channel) {
    long channelId = channel.get("id").asLong();
    if (!api.getGroupChannelById(channelId).isPresent()) {
        GroupChannel groupChannel = new GroupChannelImpl(api, channel);
        GroupChannelCreateEvent event = new GroupChannelCreateEventImpl(groupChannel);
        api.getEventDispatcher().dispatchGroupChannelCreateEvent(api, groupChannel.getMembers(), event);
    }
}
Also used : GroupChannelCreateEventImpl(org.javacord.core.event.channel.group.GroupChannelCreateEventImpl) GroupChannel(org.javacord.api.entity.channel.GroupChannel) GroupChannelCreateEvent(org.javacord.api.event.channel.group.GroupChannelCreateEvent) GroupChannelImpl(org.javacord.core.entity.channel.GroupChannelImpl)

Aggregations

GroupChannelImpl (org.javacord.core.entity.channel.GroupChannelImpl)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 GroupChannel (org.javacord.api.entity.channel.GroupChannel)1 GroupChannelCreateEvent (org.javacord.api.event.channel.group.GroupChannelCreateEvent)1 PrivateChannelImpl (org.javacord.core.entity.channel.PrivateChannelImpl)1 ServerImpl (org.javacord.core.entity.server.ServerImpl)1 MemberImpl (org.javacord.core.entity.user.MemberImpl)1 UserImpl (org.javacord.core.entity.user.UserImpl)1 GroupChannelCreateEventImpl (org.javacord.core.event.channel.group.GroupChannelCreateEventImpl)1