Search in sources :

Example 1 with PrivateChannelCreateEventImpl

use of org.javacord.core.event.channel.user.PrivateChannelCreateEventImpl in project Javacord by BtoBastian.

the class PrivateChannelImpl method dispatchPrivateChannelCreateEvent.

/**
 * This function creates and dispatches a private channel create event with the given private channel.
 *
 * @param api The discord api instance used to dispatch the event.
 * @param privateChannel The private channel.
 *
 * @return The given private channel to make things easier.
 */
public static PrivateChannelImpl dispatchPrivateChannelCreateEvent(DiscordApiImpl api, PrivateChannelImpl privateChannel) {
    // dispatch PrivateChannelCreateEvent
    PrivateChannelCreateEvent event = new PrivateChannelCreateEventImpl(privateChannel);
    api.getEventDispatcher().dispatchPrivateChannelCreateEvent(api, privateChannel.getRecipient().orElse(null), event);
    return privateChannel;
}
Also used : PrivateChannelCreateEventImpl(org.javacord.core.event.channel.user.PrivateChannelCreateEventImpl) PrivateChannelCreateEvent(org.javacord.api.event.channel.user.PrivateChannelCreateEvent)

Example 2 with PrivateChannelCreateEventImpl

use of org.javacord.core.event.channel.user.PrivateChannelCreateEventImpl in project Javacord by BtoBastian.

the class ChannelCreateHandler method handlePrivateChannel.

/**
 * Handles a private channel creation.
 *
 * @param channel The channel data.
 */
private void handlePrivateChannel(JsonNode channel) {
    // A CHANNEL_CREATE packet was sent every time a bot account receives a message, see
    // https://github.com/discord/discord-api-docs/issues/184 and
    // https://github.com/discord/discord-api-docs/issues/2248
    UserImpl recipient = new UserImpl(api, channel.get("recipients").get(0), (MemberImpl) null, null);
    if (!recipient.getPrivateChannel().isPresent()) {
        PrivateChannel privateChannel = new PrivateChannelImpl(api, channel.get("id").asText(), recipient, recipient.getId());
        PrivateChannelCreateEvent event = new PrivateChannelCreateEventImpl(privateChannel);
        api.getEventDispatcher().dispatchPrivateChannelCreateEvent(api, recipient, event);
    }
}
Also used : PrivateChannel(org.javacord.api.entity.channel.PrivateChannel) PrivateChannelCreateEventImpl(org.javacord.core.event.channel.user.PrivateChannelCreateEventImpl) UserImpl(org.javacord.core.entity.user.UserImpl) PrivateChannelCreateEvent(org.javacord.api.event.channel.user.PrivateChannelCreateEvent) PrivateChannelImpl(org.javacord.core.entity.channel.PrivateChannelImpl)

Aggregations

PrivateChannelCreateEvent (org.javacord.api.event.channel.user.PrivateChannelCreateEvent)2 PrivateChannelCreateEventImpl (org.javacord.core.event.channel.user.PrivateChannelCreateEventImpl)2 PrivateChannel (org.javacord.api.entity.channel.PrivateChannel)1 PrivateChannelImpl (org.javacord.core.entity.channel.PrivateChannelImpl)1 UserImpl (org.javacord.core.entity.user.UserImpl)1