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;
}
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;
}
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);
}
}
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)
}
}
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);
}
Aggregations