use of org.javacord.core.entity.user.UserImpl in project Javacord by BtoBastian.
the class PresenceUpdateHandler method dispatchUserActivityChangeEvent.
private void dispatchUserActivityChangeEvent(long userId, Set<Activity> newActivities, Set<Activity> oldActivities) {
UserImpl user = api.getCachedUserById(userId).map(UserImpl.class::cast).orElse(null);
UserChangeActivityEvent event = new UserChangeActivityEventImpl(api, userId, newActivities, oldActivities);
api.getEventDispatcher().dispatchUserChangeActivityEvent(api, user == null ? Collections.emptySet() : user.getMutualServers(), user == null ? Collections.emptySet() : Collections.singleton(user), event);
}
use of org.javacord.core.entity.user.UserImpl in project Javacord by BtoBastian.
the class MessageCreateHandler method handle.
@Override
public void handle(JsonNode packet) {
long channelId = packet.get("channel_id").asLong();
// See https://github.com/discord/discord-api-docs/issues/2248
if (!packet.hasNonNull("guild_id")) {
// Check for EPHEMERAL messages as they do NOT include a guild_id when the EPHEMERAL flag is set.
if (packet.hasNonNull("flags") && (packet.get("flags").asInt() & MessageFlag.EPHEMERAL.getId()) > 0) {
Optional<ServerTextChannel> serverTextChannel = api.getServerTextChannelById(channelId);
if (serverTextChannel.isPresent()) {
handle(serverTextChannel.get(), packet);
return;
}
Optional<ServerThreadChannel> serverThreadChannel = api.getServerThreadChannelById(channelId);
if (serverThreadChannel.isPresent()) {
handle(serverThreadChannel.get(), packet);
return;
}
}
UserImpl author = new UserImpl(api, packet.get("author"), (MemberImpl) null, null);
PrivateChannelImpl privateChannel = PrivateChannelImpl.getOrCreatePrivateChannel(api, channelId, author.getId(), author);
handle(privateChannel, packet);
return;
}
Optional<TextChannel> optionalChannel = api.getTextChannelById(channelId);
if (optionalChannel.isPresent()) {
handle(optionalChannel.get(), packet);
} else {
LoggerUtil.logMissingChannel(logger, channelId);
}
}
Aggregations