use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class EntityBuilder method updateUser.
public void updateUser(UserImpl userObj, DataObject user) {
String oldName = userObj.getName();
String newName = user.getString("username");
String oldDiscriminator = userObj.getDiscriminator();
String newDiscriminator = user.get("discriminator").toString();
String oldAvatar = userObj.getAvatarId();
String newAvatar = user.getString("avatar", null);
int oldFlags = userObj.getFlagsRaw();
int newFlags = user.getInt("public_flags", 0);
JDAImpl jda = getJDA();
long responseNumber = jda.getResponseTotal();
if (!oldName.equals(newName)) {
userObj.setName(newName);
jda.handleEvent(new UserUpdateNameEvent(jda, responseNumber, userObj, oldName));
}
if (!oldDiscriminator.equals(newDiscriminator)) {
userObj.setDiscriminator(newDiscriminator);
jda.handleEvent(new UserUpdateDiscriminatorEvent(jda, responseNumber, userObj, oldDiscriminator));
}
if (!Objects.equals(oldAvatar, newAvatar)) {
userObj.setAvatarId(newAvatar);
jda.handleEvent(new UserUpdateAvatarEvent(jda, responseNumber, userObj, oldAvatar));
}
if (oldFlags != newFlags) {
userObj.setFlags(newFlags);
jda.handleEvent(new UserUpdateFlagsEvent(jda, responseNumber, userObj, User.UserFlag.getFlags(oldFlags)));
}
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class ReceivedMessage method suppressEmbeds.
@Nonnull
@Override
public AuditableRestAction<Void> suppressEmbeds(boolean suppressed) {
if (isEphemeral())
throw new IllegalStateException("Cannot suppress embeds on ephemeral messages.");
if (!getJDA().getSelfUser().equals(getAuthor())) {
if (isFromType(ChannelType.PRIVATE))
throw new PermissionException("Cannot suppress embeds of others in a PrivateChannel.");
GuildMessageChannel gChan = getGuildChannel();
if (!getGuild().getSelfMember().hasPermission(gChan, Permission.MESSAGE_MANAGE))
throw new InsufficientPermissionException(gChan, Permission.MESSAGE_MANAGE);
}
JDAImpl jda = (JDAImpl) getJDA();
Route.CompiledRoute route = Route.Messages.EDIT_MESSAGE.compile(getChannel().getId(), getId());
int newFlags = flags;
int suppressionValue = MessageFlag.EMBEDS_SUPPRESSED.getValue();
if (suppressed)
newFlags |= suppressionValue;
else
newFlags &= ~suppressionValue;
return new AuditableRestActionImpl<>(jda, route, DataObject.empty().put("flags", newFlags));
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class AudioWebSocket method close.
protected void close(final ConnectionStatus closeStatus) {
// Makes sure we don't run this method again after the socket.close(1000) call fires onDisconnect
if (shutdown)
return;
locked((manager) -> {
if (shutdown)
return;
ConnectionStatus status = closeStatus;
ready = false;
shutdown = true;
stopKeepAlive();
if (audioConnection.udpSocket != null)
audioConnection.udpSocket.close();
if (socket != null)
socket.sendClose();
audioConnection.shutdown();
AudioChannel disconnectedChannel = manager.getConnectedChannel();
manager.setAudioConnection(null);
// Verify that it is actually a lost of connection and not due the connected channel being deleted.
JDAImpl api = getJDA();
if (status == ConnectionStatus.DISCONNECTED_KICKED_FROM_CHANNEL && (!api.getClient().isSession() || !api.getClient().isConnected())) {
LOG.debug("Connection was closed due to session invalidate!");
status = ConnectionStatus.ERROR_CANNOT_RESUME;
} else if (status == ConnectionStatus.ERROR_LOST_CONNECTION || status == ConnectionStatus.DISCONNECTED_KICKED_FROM_CHANNEL) {
// Get guild from JDA, don't use [guild] field to make sure that we don't have
// a problem of an out of date guild stored in [guild] during a possible mWS invalidate.
Guild connGuild = api.getGuildById(guild.getIdLong());
if (connGuild != null) {
AudioChannel channel = (AudioChannel) connGuild.getGuildChannelById(audioConnection.getChannel().getIdLong());
if (channel == null)
status = ConnectionStatus.DISCONNECTED_CHANNEL_DELETED;
}
}
changeStatus(status);
// decide if we reconnect.
if (shouldReconnect && // indicated that the connection was purposely closed. don't reconnect.
status.shouldReconnect() && // Already handled.
status != ConnectionStatus.AUDIO_REGION_CHANGE) {
if (disconnectedChannel == null) {
LOG.debug("Cannot reconnect due to null audio channel");
return;
}
api.getDirectAudioController().reconnect(disconnectedChannel);
} else if (status == ConnectionStatus.DISCONNECTED_REMOVED_FROM_GUILD) {
// Remove audio manager as we are no longer in the guild
api.getAudioManagersView().remove(guild.getIdLong());
} else if (status != ConnectionStatus.AUDIO_REGION_CHANGE && status != ConnectionStatus.DISCONNECTED_KICKED_FROM_CHANNEL) {
api.getDirectAudioController().disconnect(guild);
}
});
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class GuildImpl method modifyNickname.
@Nonnull
@Override
public AuditableRestAction<Void> modifyNickname(@Nonnull Member member, String nickname) {
Checks.notNull(member, "Member");
checkGuild(member.getGuild(), "Member");
if (member.equals(getSelfMember())) {
if (!member.hasPermission(Permission.NICKNAME_CHANGE) && !member.hasPermission(Permission.NICKNAME_MANAGE))
throw new InsufficientPermissionException(this, Permission.NICKNAME_CHANGE, "You neither have NICKNAME_CHANGE nor NICKNAME_MANAGE permission!");
} else {
checkPermission(Permission.NICKNAME_MANAGE);
checkPosition(member);
}
JDAImpl jda = getJDA();
return new DeferredRestAction<>(jda, () -> {
DataObject body = DataObject.empty().put("nick", nickname == null ? "" : nickname);
Route.CompiledRoute route;
if (member.equals(getSelfMember()))
route = Route.Guilds.MODIFY_SELF.compile(getId());
else
route = Route.Guilds.MODIFY_MEMBER.compile(getId(), member.getUser().getId());
return new AuditableRestActionImpl<Void>(jda, route, body);
}).setCacheCheck(() -> !Objects.equals(nickname, member.getNickname()));
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class GuildImpl method retrieveEmoteById.
@Nonnull
@Override
public RestAction<ListedEmote> retrieveEmoteById(@Nonnull String id) {
Checks.isSnowflake(id, "Emote ID");
JDAImpl jda = getJDA();
return new DeferredRestAction<>(jda, ListedEmote.class, () -> {
Emote emote = getEmoteById(id);
if (emote != null) {
ListedEmote listedEmote = (ListedEmote) emote;
if (listedEmote.hasUser() || !getSelfMember().hasPermission(Permission.MANAGE_EMOTES_AND_STICKERS))
return listedEmote;
}
return null;
}, () -> {
Route.CompiledRoute route = Route.Emotes.GET_EMOTE.compile(getId(), id);
return new AuditableRestActionImpl<>(jda, route, (response, request) -> {
EntityBuilder builder = GuildImpl.this.getJDA().getEntityBuilder();
return builder.createEmote(GuildImpl.this, response.getObject());
});
});
}
Aggregations