use of org.javacord.api.event.channel.user.PrivateChannelCreateEvent 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;
}
use of org.javacord.api.event.channel.user.PrivateChannelCreateEvent 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);
}
}
Aggregations