Search in sources :

Example 6 with UserImpl

use of org.javacord.core.entity.user.UserImpl in project Javacord by BtoBastian.

the class GuildBanAddHandler method handle.

@Override
public void handle(JsonNode packet) {
    api.getPossiblyUnreadyServerById(packet.get("guild_id").asLong()).map(server -> (ServerImpl) server).ifPresent(server -> {
        User user = new UserImpl(api, packet.get("user"), (MemberImpl) null, server);
        server.removeMember(user.getId());
        ServerMemberBanEvent event = new ServerMemberBanEventImpl(server, user);
        api.getEventDispatcher().dispatchServerMemberBanEvent(server, server, user, event);
    });
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerMemberBanEvent(org.javacord.api.event.server.member.ServerMemberBanEvent) User(org.javacord.api.entity.user.User) PacketHandler(org.javacord.core.util.gateway.PacketHandler) DiscordApi(org.javacord.api.DiscordApi) UserImpl(org.javacord.core.entity.user.UserImpl) ServerMemberBanEventImpl(org.javacord.core.event.server.member.ServerMemberBanEventImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) User(org.javacord.api.entity.user.User) ServerImpl(org.javacord.core.entity.server.ServerImpl) UserImpl(org.javacord.core.entity.user.UserImpl) ServerMemberBanEvent(org.javacord.api.event.server.member.ServerMemberBanEvent) ServerMemberBanEventImpl(org.javacord.core.event.server.member.ServerMemberBanEventImpl)

Example 7 with UserImpl

use of org.javacord.core.entity.user.UserImpl in project Javacord by BtoBastian.

the class GuildMemberRemoveHandler method handle.

@Override
public void handle(JsonNode packet) {
    api.getPossiblyUnreadyServerById(packet.get("guild_id").asLong()).map(server -> (ServerImpl) server).ifPresent(server -> {
        User user = new UserImpl(api, packet.get("user"), (MemberImpl) null, server);
        server.removeMember(user.getId());
        server.decrementMemberCount();
        ServerMemberLeaveEvent event = new ServerMemberLeaveEventImpl(server, user);
        api.getEventDispatcher().dispatchServerMemberLeaveEvent(server, server, user, event);
    });
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) User(org.javacord.api.entity.user.User) ServerMemberLeaveEvent(org.javacord.api.event.server.member.ServerMemberLeaveEvent) PacketHandler(org.javacord.core.util.gateway.PacketHandler) DiscordApi(org.javacord.api.DiscordApi) UserImpl(org.javacord.core.entity.user.UserImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) ServerMemberLeaveEventImpl(org.javacord.core.event.server.member.ServerMemberLeaveEventImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) User(org.javacord.api.entity.user.User) ServerMemberLeaveEvent(org.javacord.api.event.server.member.ServerMemberLeaveEvent) ServerImpl(org.javacord.core.entity.server.ServerImpl) UserImpl(org.javacord.core.entity.user.UserImpl) ServerMemberLeaveEventImpl(org.javacord.core.event.server.member.ServerMemberLeaveEventImpl)

Example 8 with UserImpl

use of org.javacord.core.entity.user.UserImpl 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);
    }
}
Also used : PrivateChannel(org.javacord.api.entity.channel.PrivateChannel) PrivateChannelCreateEventImpl(org.javacord.core.event.channel.user.PrivateChannelCreateEventImpl) UserImpl(org.javacord.core.entity.user.UserImpl) PrivateChannelCreateEvent(org.javacord.api.event.channel.user.PrivateChannelCreateEvent) PrivateChannelImpl(org.javacord.core.entity.channel.PrivateChannelImpl)

Example 9 with UserImpl

use of org.javacord.core.entity.user.UserImpl in project Javacord by BtoBastian.

the class GuildBanRemoveHandler method handle.

@Override
public void handle(JsonNode packet) {
    api.getPossiblyUnreadyServerById(packet.get("guild_id").asLong()).map(server -> (ServerImpl) server).ifPresent(server -> {
        User user = new UserImpl(api, packet.get("user"), (MemberImpl) null, server);
        ServerMemberUnbanEvent event = new ServerMemberUnbanEventImpl(server, user);
        api.getEventDispatcher().dispatchServerMemberUnbanEvent(server, server, user, event);
    });
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerMemberUnbanEventImpl(org.javacord.core.event.server.member.ServerMemberUnbanEventImpl) User(org.javacord.api.entity.user.User) PacketHandler(org.javacord.core.util.gateway.PacketHandler) DiscordApi(org.javacord.api.DiscordApi) UserImpl(org.javacord.core.entity.user.UserImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) ServerMemberUnbanEvent(org.javacord.api.event.server.member.ServerMemberUnbanEvent) ServerMemberUnbanEventImpl(org.javacord.core.event.server.member.ServerMemberUnbanEventImpl) User(org.javacord.api.entity.user.User) ServerImpl(org.javacord.core.entity.server.ServerImpl) UserImpl(org.javacord.core.entity.user.UserImpl) ServerMemberUnbanEvent(org.javacord.api.event.server.member.ServerMemberUnbanEvent)

Example 10 with UserImpl

use of org.javacord.core.entity.user.UserImpl in project Javacord by BtoBastian.

the class GuildMemberAddHandler method handle.

@Override
public void handle(JsonNode packet) {
    api.getPossiblyUnreadyServerById(packet.get("guild_id").asLong()).map(server -> (ServerImpl) server).ifPresent(server -> {
        MemberImpl member = server.addMember(packet);
        server.incrementMemberCount();
        User user = new UserImpl(api, packet.get("user"), member, server);
        ServerMemberJoinEvent event = new ServerMemberJoinEventImpl(server, user);
        api.getEventDispatcher().dispatchServerMemberJoinEvent(server, server, user, event);
    });
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerMemberJoinEventImpl(org.javacord.core.event.server.member.ServerMemberJoinEventImpl) ServerMemberJoinEvent(org.javacord.api.event.server.member.ServerMemberJoinEvent) User(org.javacord.api.entity.user.User) PacketHandler(org.javacord.core.util.gateway.PacketHandler) DiscordApi(org.javacord.api.DiscordApi) UserImpl(org.javacord.core.entity.user.UserImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) ServerMemberJoinEvent(org.javacord.api.event.server.member.ServerMemberJoinEvent) User(org.javacord.api.entity.user.User) ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerMemberJoinEventImpl(org.javacord.core.event.server.member.ServerMemberJoinEventImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) UserImpl(org.javacord.core.entity.user.UserImpl)

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