Search in sources :

Example 1 with UserStartTypingEventImpl

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

the class TypingStartHandler method handle.

@Override
public void handle(JsonNode packet) {
    long userId = packet.get("user_id").asLong();
    long channelId = packet.get("channel_id").asLong();
    TextChannel channel = api.getTextChannelById(channelId).orElse(null);
    ServerImpl server = null;
    if (packet.hasNonNull("guild_id")) {
        long serverId = packet.get("guild_id").asLong();
        server = (ServerImpl) api.getPossiblyUnreadyServerById(serverId).orElseThrow(AssertionError::new);
    }
    MemberImpl member = null;
    if (packet.hasNonNull("member") && server != null) {
        member = new MemberImpl(api, server, packet.get("member"), null);
    }
    if (channel != null) {
        UserStartTypingEvent event = new UserStartTypingEventImpl(channel, userId, member);
        api.getEventDispatcher().dispatchUserStartTypingEvent(server != null ? server : api, server, channel, userId, event);
    }
}
Also used : UserStartTypingEventImpl(org.javacord.core.event.user.UserStartTypingEventImpl) TextChannel(org.javacord.api.entity.channel.TextChannel) ServerImpl(org.javacord.core.entity.server.ServerImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) UserStartTypingEvent(org.javacord.api.event.user.UserStartTypingEvent)

Aggregations

TextChannel (org.javacord.api.entity.channel.TextChannel)1 UserStartTypingEvent (org.javacord.api.event.user.UserStartTypingEvent)1 ServerImpl (org.javacord.core.entity.server.ServerImpl)1 MemberImpl (org.javacord.core.entity.user.MemberImpl)1 UserStartTypingEventImpl (org.javacord.core.event.user.UserStartTypingEventImpl)1