use of io.discloader.discloader.entity.guild.IGuildMember in project DiscLoader by R3alCl0ud.
the class Guild method addMember.
/**
* Method used internally by DiscLoader to make a new {@link GuildMember} object
* when a member's data is recieved
*
* @param data
* The member's data
* @param shouldEmit
* if a {@code GuildMemberAddEvent} should be fired by the client
* @return The {@link GuildMember} that was instantiated.
*/
public IGuildMember addMember(MemberJSON data, boolean shouldEmit) {
boolean exists = members.containsKey(SnowflakeUtil.parse(data.user.id));
IGuildMember member = new GuildMember(this, data);
members.put(member.getID(), member);
if (!exists && shouldEmit) {
memberCount++;
GuildMemberAddEvent event = new GuildMemberAddEvent(member);
// loader.emit(DLUtil.Events.GUILD_MEMBER_ADD, event);
loader.emit(event);
}
return member;
}
use of io.discloader.discloader.entity.guild.IGuildMember in project DiscLoader by R3alCl0ud.
the class Guild method ban.
@Override
public CompletableFuture<IGuildMember> ban(IGuildMember member, String reason) throws PermissionsException {
if (!hasPermission(Permissions.BAN_MEMBERS))
throw new PermissionsException("");
CompletableFuture<IGuildMember> future = new CompletableFuture<>();
loader.rest.request(Methods.PUT, Endpoints.guildBanMember(getID(), member.getID()), new RESTOptions(reason), Void.class).thenAcceptAsync(action -> {
future.complete(member);
});
return future;
}
use of io.discloader.discloader.entity.guild.IGuildMember in project DiscLoader by R3alCl0ud.
the class Guild method ban.
@Override
public CompletableFuture<IGuildMember> ban(IGuildMember member) {
if (!hasPermission(Permissions.BAN_MEMBERS))
throw new PermissionsException("");
CompletableFuture<IGuildMember> future = new CompletableFuture<>();
loader.rest.request(Methods.PUT, Endpoints.guildBanMember(getID(), member.getID()), new RESTOptions(), Void.class).thenAcceptAsync(action -> {
future.complete(member);
});
return future;
}
use of io.discloader.discloader.entity.guild.IGuildMember 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();
}
}
use of io.discloader.discloader.entity.guild.IGuildMember in project DiscLoader by R3alCl0ud.
the class GuildMember method giveRole.
/**
* Gives a member a new role
*
* @param roles
* The roles to give to the member
* @return A CompletableFuture that completes with {@code this} if successful
* @throws PermissionsException
* thrown if a role with a higher position than the current user's
* highest role is attempted to be given to the member. Also thrown
* if the current user doesn't have the MANAGE_ROLE permission.
*/
@Override
public CompletableFuture<IGuildMember> giveRole(IRole... roles) {
CompletableFuture<IGuildMember> future = new CompletableFuture<>();
if (!guild.hasPermission(Permissions.MANAGE_ROLES)) {
future.completeExceptionally(new PermissionsException("Insufficient Permissions"));
return future;
}
for (IRole role : roles) {
if (role == null)
continue;
if (!guild.isOwner() && role.getPosition() >= guild.getCurrentMember().getHighestRole().getPosition()) {
future.completeExceptionally(new PermissionsException("Can not assign higher role"));
return future;
// throw ;
}
}
List<IRole> rls = mergeRoles(roles);
String[] ids = new String[rls.size()];
for (int i = 0; i < ids.length; i++) {
ids[i] = SnowflakeUtil.asString(rls.get(i));
}
JSONObject payload = new JSONObject().put("roles", ids);
System.out.println(payload);
CompletableFuture<Void> vcf = getLoader().rest.request(Methods.PATCH, Endpoints.guildMember(getGuild().getID(), getID()), new RESTOptions(payload), Void.class);
vcf.thenAcceptAsync(v -> {
getLoader().addEventListener(new EventListenerAdapter() {
public void GuildMemberUpdate(GuildMemberUpdateEvent e) {
future.complete(e.getMember());
getLoader().removeEventListener(this);
}
});
});
vcf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
// }
return future;
}
Aggregations