Search in sources :

Example 11 with UserImpl

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);
}
Also used : UserChangeActivityEvent(org.javacord.api.event.user.UserChangeActivityEvent) UserImpl(org.javacord.core.entity.user.UserImpl) UserChangeActivityEventImpl(org.javacord.core.event.user.UserChangeActivityEventImpl)

Example 12 with UserImpl

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);
    }
}
Also used : ServerTextChannel(org.javacord.api.entity.channel.ServerTextChannel) ServerTextChannel(org.javacord.api.entity.channel.ServerTextChannel) TextChannel(org.javacord.api.entity.channel.TextChannel) ServerThreadChannel(org.javacord.api.entity.channel.ServerThreadChannel) UserImpl(org.javacord.core.entity.user.UserImpl) PrivateChannelImpl(org.javacord.core.entity.channel.PrivateChannelImpl)

Aggregations

UserImpl (org.javacord.core.entity.user.UserImpl)12 ServerImpl (org.javacord.core.entity.server.ServerImpl)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 MemberImpl (org.javacord.core.entity.user.MemberImpl)6 DiscordApi (org.javacord.api.DiscordApi)5 User (org.javacord.api.entity.user.User)5 PacketHandler (org.javacord.core.util.gateway.PacketHandler)5 PrivateChannel (org.javacord.api.entity.channel.PrivateChannel)2 ServerTextChannel (org.javacord.api.entity.channel.ServerTextChannel)2 TextChannel (org.javacord.api.entity.channel.TextChannel)2 PrivateChannelImpl (org.javacord.core.entity.channel.PrivateChannelImpl)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Logger (org.apache.logging.log4j.Logger)1