Search in sources :

Example 1 with IGuildMember

use of io.discloader.discloader.entity.guild.IGuildMember in project DiscLoader by R3alCl0ud.

the class Guild method kick.

@Override
public CompletableFuture<IGuildMember> kick(IGuildMember member, String reason) {
    if (!isOwner() && getCurrentMember().getPermissions().hasPermission(Permissions.KICK_MEMBERS))
        throw new PermissionsException("Insufficient Permissions");
    CompletableFuture<IGuildMember> future = new CompletableFuture<>();
    CompletableFuture<Void> kickFuture = loader.rest.request(Methods.DELETE, Endpoints.guildMember(getID(), member.getID()), new RESTOptions(reason), Void.class);
    kickFuture.thenAcceptAsync(n -> {
        future.complete(member);
    });
    kickFuture.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

Example 2 with IGuildMember

use of io.discloader.discloader.entity.guild.IGuildMember 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 3 with IGuildMember

use of io.discloader.discloader.entity.guild.IGuildMember in project DiscLoader by R3alCl0ud.

the class GuildMemberRemove method handle.

@Override
public void handle(SocketPacket packet) {
    String d = this.gson.toJson(packet.d);
    GuildMemberRemoveJSON data = this.gson.fromJson(d, GuildMemberRemoveJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    IGuildMember member = guild.getMember(data.user.id);
    if (member == null)
        member = EntityBuilder.getGuildFactory().buildMember(guild, EntityRegistry.addUser(data.user), new String[] {}, false, false, null);
    guild.removeMember(member);
    if (shouldEmit()) {
        GuildMemberRemoveEvent event = new GuildMemberRemoveEvent(member);
        loader.emit(event);
    }
}
Also used : GuildMemberRemoveJSON(io.discloader.discloader.network.json.GuildMemberRemoveJSON) GuildMemberRemoveEvent(io.discloader.discloader.common.event.guild.member.GuildMemberRemoveEvent) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) IGuild(io.discloader.discloader.entity.guild.IGuild)

Example 4 with IGuildMember

use of io.discloader.discloader.entity.guild.IGuildMember 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 5 with IGuildMember

use of io.discloader.discloader.entity.guild.IGuildMember 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)

Aggregations

IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)13 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)7 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 GuildMemberUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent)4 IGuild (io.discloader.discloader.entity.guild.IGuild)4 MemberJSON (io.discloader.discloader.network.json.MemberJSON)4 EventListenerAdapter (io.discloader.discloader.common.event.EventListenerAdapter)3 IRole (io.discloader.discloader.entity.guild.IRole)3 JSONObject (org.json.JSONObject)3 IEventListener (io.discloader.discloader.common.event.IEventListener)2 PresenceJSON (io.discloader.discloader.network.json.PresenceJSON)2 UserUpdateEvent (io.discloader.discloader.common.event.UserUpdateEvent)1 GuildMemberAddEvent (io.discloader.discloader.common.event.guild.member.GuildMemberAddEvent)1 NicknameUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberEvent.NicknameUpdateEvent)1 GuildMemberNicknameUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberNicknameUpdateEvent)1 GuildMemberRemoveEvent (io.discloader.discloader.common.event.guild.member.GuildMemberRemoveEvent)1 GuildMemberRoleAddEvent (io.discloader.discloader.common.event.guild.member.GuildMemberRoleAddEvent)1 GuildMemberRoleRemoveEvent (io.discloader.discloader.common.event.guild.member.GuildMemberRoleRemoveEvent)1 GuildMembersChunkEvent (io.discloader.discloader.common.event.guild.member.GuildMembersChunkEvent)1