Search in sources :

Example 1 with MemberJSON

use of io.discloader.discloader.network.json.MemberJSON in project DiscLoader by R3alCl0ud.

the class Guild method fetchMember.

public CompletableFuture<IGuildMember> fetchMember(long memberID) {
    CompletableFuture<IGuildMember> future = new CompletableFuture<IGuildMember>();
    CompletableFuture<MemberJSON> cf = loader.rest.request(Methods.GET, Endpoints.guildMember(getID(), memberID), new RESTOptions(), MemberJSON.class);
    cf.thenAcceptAsync(data -> {
        future.complete(addMember(data, true));
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) MemberJSON(io.discloader.discloader.network.json.MemberJSON)

Example 2 with MemberJSON

use of io.discloader.discloader.network.json.MemberJSON in project DiscLoader by R3alCl0ud.

the class GuildMemberAdd method handle.

@Override
public void handle(SocketPacket packet) {
    String d = this.gson.toJson(packet.d);
    MemberJSON data = this.gson.fromJson(d, MemberJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    guild.addMember(data, true);
}
Also used : IGuild(io.discloader.discloader.entity.guild.IGuild) MemberJSON(io.discloader.discloader.network.json.MemberJSON)

Example 3 with MemberJSON

use of io.discloader.discloader.network.json.MemberJSON in project DiscLoader by R3alCl0ud.

the class GuildMemberUpdate method handle.

@Override
public void handle(SocketPacket packet) {
    String d = this.gson.toJson(packet.d);
    MemberJSON data = this.gson.fromJson(d, MemberJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    IGuildMember oldMember = guild.getMember(data.user.id), member = gfac.buildMember(guild, data);
    guild.addMember(member);
    if (shouldEmit() && oldMember != null) {
        GuildMemberUpdateEvent event = new GuildMemberUpdateEvent(member, oldMember);
        loader.emit(Events.GUILD_MEMBER_UPDATE, event);
        loader.emit(event);
        if (!member.getNickname().equals(oldMember.getNickname())) {
            loader.emit(new GuildMemberNicknameUpdateEvent(member, oldMember.getNickname()));
        }
        member.getRoles().forEach(role -> {
            if (!oldMember.hasRole(role)) {
                loader.emit(new GuildMemberRoleAddEvent(oldMember, member, role));
            }
        });
        oldMember.getRoles().forEach(role -> {
            if (!member.hasRole(role)) {
                loader.emit(new GuildMemberRoleRemoveEvent(oldMember, member, role));
            }
        });
    // for (member)
    }
}
Also used : GuildMemberUpdateEvent(io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent) GuildMemberRoleAddEvent(io.discloader.discloader.common.event.guild.member.GuildMemberRoleAddEvent) GuildMemberNicknameUpdateEvent(io.discloader.discloader.common.event.guild.member.GuildMemberNicknameUpdateEvent) GuildMemberRoleRemoveEvent(io.discloader.discloader.common.event.guild.member.GuildMemberRoleRemoveEvent) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) IGuild(io.discloader.discloader.entity.guild.IGuild) MemberJSON(io.discloader.discloader.network.json.MemberJSON)

Example 4 with MemberJSON

use of io.discloader.discloader.network.json.MemberJSON in project DiscLoader by R3alCl0ud.

the class GuildMembersChunk method handle.

@Override
public void handle(SocketPacket packet) {
    String d = this.gson.toJson(packet.d);
    GuildMembersChunkJSON data = this.gson.fromJson(d, GuildMembersChunkJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    if (guild == null)
        return;
    Map<Long, IGuildMember> members = new HashMap<>();
    for (MemberJSON m : data.members) {
        IGuildMember member = EntityBuilder.getGuildFactory().buildMember(guild, EntityRegistry.addUser(m.user), new String[] {}, false, false, null);
        guild.addMember(member);
        members.put(member.getID(), member);
    }
    GuildMembersChunkEvent event = new GuildMembersChunkEvent(guild, members);
    loader.emit(event);
}
Also used : HashMap(java.util.HashMap) GuildMembersChunkEvent(io.discloader.discloader.common.event.guild.member.GuildMembersChunkEvent) GuildMembersChunkJSON(io.discloader.discloader.network.json.GuildMembersChunkJSON) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) IGuild(io.discloader.discloader.entity.guild.IGuild) MemberJSON(io.discloader.discloader.network.json.MemberJSON)

Example 5 with MemberJSON

use of io.discloader.discloader.network.json.MemberJSON in project DiscLoader by R3alCl0ud.

the class Guild method setup.

/**
 * Sets up a guild with data from the gateway
 *
 * @param data
 *            The guild's data
 */
@Override
public void setup(GuildJSON data) {
    try {
        name = data.name;
        icon = data.icon != null ? data.icon : null;
        iconURL = icon != null ? Endpoints.guildIcon(getID(), icon) : null;
        ownerID = SnowflakeUtil.parse(data.owner_id);
        memberCount = data.member_count;
        voiceRegion = new VoiceRegion(data.region);
        splashHash = data.splash;
        if (data.roles.length > 0) {
            roles.clear();
            for (RoleJSON role : data.roles) {
                IRole r = gfac.buildRole(this, role);
                roles.put(r.getID(), r);
            }
        }
        if (data.members != null && data.members.length > 0) {
            members.clear();
            for (MemberJSON member : data.members) {
                IGuildMember m = gfac.buildMember(this, member);
                members.put(m.getID(), m);
            }
        }
        if (data.channels != null && data.channels.length > 0) {
            for (ChannelJSON channelData : data.channels) {
                IGuildChannel chan = (IGuildChannel) EntityRegistry.addChannel(channelData, getLoader(), this);
                if (chan instanceof IGuildTextChannel)
                    textChannels.put(chan.getID(), (IGuildTextChannel) chan);
                else if (chan instanceof IGuildVoiceChannel)
                    voiceChannels.put(chan.getID(), (IGuildVoiceChannel) chan);
            }
        }
        if (data.presences != null && data.presences.length > 0) {
            presences.clear();
            for (PresenceJSON presence : data.presences) {
                this.setPresence(presence);
            }
        }
        if (data.emojis != null && data.emojis.length > 0) {
            this.guildEmojis.clear();
            for (EmojiJSON e : data.emojis) {
                this.guildEmojis.put(SnowflakeUtil.parse(e.id), new GuildEmoji(e, this));
            }
        }
        if (data.voice_states != null && data.voice_states.length > 0) {
            this.rawStates.clear();
            for (VoiceStateJSON v : data.voice_states) {
                this.rawStates.put(SnowflakeUtil.parse(v.user_id), new VoiceState(v, this));
            }
        }
        this.available = data.unavailable == true ? false : true;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : VoiceState(io.discloader.discloader.entity.voice.VoiceState) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException) IOException(java.io.IOException) GuildSyncException(io.discloader.discloader.common.exceptions.GuildSyncException) UnauthorizedException(io.discloader.discloader.common.exceptions.UnauthorizedException) MissmatchException(io.discloader.discloader.common.exceptions.MissmatchException) AccountTypeException(io.discloader.discloader.common.exceptions.AccountTypeException) RoleJSON(io.discloader.discloader.network.json.RoleJSON) ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) VoiceRegion(io.discloader.discloader.entity.guild.VoiceRegion) IRole(io.discloader.discloader.entity.guild.IRole) VoiceStateJSON(io.discloader.discloader.network.json.VoiceStateJSON) IGuildEmoji(io.discloader.discloader.entity.guild.IGuildEmoji) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) PresenceJSON(io.discloader.discloader.network.json.PresenceJSON) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel) MemberJSON(io.discloader.discloader.network.json.MemberJSON) EmojiJSON(io.discloader.discloader.network.json.EmojiJSON)

Aggregations

MemberJSON (io.discloader.discloader.network.json.MemberJSON)6 IGuild (io.discloader.discloader.entity.guild.IGuild)4 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)4 PresenceJSON (io.discloader.discloader.network.json.PresenceJSON)2 GuildMemberNicknameUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberNicknameUpdateEvent)1 GuildMemberRoleAddEvent (io.discloader.discloader.common.event.guild.member.GuildMemberRoleAddEvent)1 GuildMemberRoleRemoveEvent (io.discloader.discloader.common.event.guild.member.GuildMemberRoleRemoveEvent)1 GuildMemberUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent)1 GuildMembersChunkEvent (io.discloader.discloader.common.event.guild.member.GuildMembersChunkEvent)1 AccountTypeException (io.discloader.discloader.common.exceptions.AccountTypeException)1 GuildSyncException (io.discloader.discloader.common.exceptions.GuildSyncException)1 MissmatchException (io.discloader.discloader.common.exceptions.MissmatchException)1 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)1 UnauthorizedException (io.discloader.discloader.common.exceptions.UnauthorizedException)1 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)1 IGuildTextChannel (io.discloader.discloader.entity.channel.IGuildTextChannel)1 IGuildVoiceChannel (io.discloader.discloader.entity.channel.IGuildVoiceChannel)1 IGuildEmoji (io.discloader.discloader.entity.guild.IGuildEmoji)1 IRole (io.discloader.discloader.entity.guild.IRole)1 VoiceRegion (io.discloader.discloader.entity.guild.VoiceRegion)1