use of net.dv8tion.jda.api.events.user.UserTypingEvent in project JDA by DV8FromTheWorld.
the class TypingStartHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
GuildImpl guild = null;
if (!content.isNull("guild_id")) {
long guildId = content.getUnsignedLong("guild_id");
guild = (GuildImpl) getJDA().getGuildById(guildId);
if (getJDA().getGuildSetupController().isLocked(guildId))
return guildId;
else if (guild == null)
// Don't cache typing events
return null;
}
final long channelId = content.getLong("channel_id");
// TODO-v5-unified-channel-cache
MessageChannel channel = getJDA().getTextChannelsView().get(channelId);
if (channel == null)
channel = getJDA().getNewsChannelView().get(channelId);
if (channel == null)
channel = getJDA().getPrivateChannelsView().get(channelId);
if (channel == null)
// We don't have the channel cached yet. We chose not to cache this event
return null;
// because that happen very often and could easily fill up the EventCache if
// we, for some reason, never get the channel. Especially in an active channel.
final long userId = content.getLong("user_id");
User user;
MemberImpl member = null;
if (channel instanceof PrivateChannel)
user = ((PrivateChannel) channel).getUser();
else
user = getJDA().getUsersView().get(userId);
if (!content.isNull("member")) {
// Try to load member for the typing event
EntityBuilder entityBuilder = getJDA().getEntityBuilder();
member = entityBuilder.createMember(guild, content.getObject("member"));
entityBuilder.updateMemberCache(member);
user = member.getUser();
}
if (user == null)
// Just like in the comment above, if for some reason we don't have the user
return null;
// then we will just throw the event away.
OffsetDateTime timestamp = Instant.ofEpochSecond(content.getInt("timestamp")).atOffset(ZoneOffset.UTC);
getJDA().handleEvent(new UserTypingEvent(getJDA(), responseNumber, user, channel, timestamp, member));
return null;
}
Aggregations