use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class InviteImpl method resolve.
public static RestAction<Invite> resolve(final JDA api, final String code, final boolean withCounts) {
Checks.notNull(code, "code");
Checks.notNull(api, "api");
Route.CompiledRoute route = Route.Invites.GET_INVITE.compile(code);
if (withCounts)
route = route.withQueryParams("with_counts", "true");
JDAImpl jda = (JDAImpl) api;
return new RestActionImpl<>(api, route, (response, request) -> jda.getEntityBuilder().createInvite(response.getObject()));
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class GuildSetupNode method handleCreate.
void handleCreate(DataObject obj) {
if (partialGuild == null) {
partialGuild = obj;
} else {
for (String key : obj.keys()) {
partialGuild.put(key, obj.opt(key).orElse(null));
}
}
boolean unavailable = partialGuild.getBoolean("unavailable");
boolean wasMarkedUnavailable = this.markedUnavailable;
this.markedUnavailable = unavailable;
if (unavailable) {
if (!firedUnavailableJoin && isJoin()) {
firedUnavailableJoin = true;
JDAImpl api = getController().getJDA();
api.handleEvent(new UnavailableGuildJoinedEvent(api, api.getResponseTotal(), id));
}
return;
}
ensureMembers();
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class GuildSetupNode method updateAudioManagerReference.
private void updateAudioManagerReference(GuildImpl guild) {
JDAImpl api = getController().getJDA();
AbstractCacheView<AudioManager> managerView = api.getAudioManagersView();
try (UnlockHook hook = managerView.writeLock()) {
TLongObjectMap<AudioManager> audioManagerMap = managerView.getMap();
AudioManagerImpl mng = (AudioManagerImpl) audioManagerMap.get(id);
if (mng == null)
return;
ConnectionListener listener = mng.getConnectionListener();
final AudioManagerImpl newMng = new AudioManagerImpl(guild);
newMng.setSelfMuted(mng.isSelfMuted());
newMng.setSelfDeafened(mng.isSelfDeafened());
newMng.setQueueTimeout(mng.getConnectTimeout());
newMng.setSendingHandler(mng.getSendingHandler());
newMng.setReceivingHandler(mng.getReceivingHandler());
newMng.setConnectionListener(listener);
newMng.setAutoReconnect(mng.isAutoReconnect());
if (mng.isConnected()) {
final long channelId = mng.getConnectedChannel().getIdLong();
final VoiceChannel channel = api.getVoiceChannelById(channelId);
if (channel != null) {
if (mng.isConnected())
mng.closeAudioConnection(ConnectionStatus.ERROR_CANNOT_RESUME);
} else {
// The voice channel is not cached. It was probably deleted.
api.getClient().removeAudioConnection(id);
if (listener != null)
listener.onStatusChange(ConnectionStatus.DISCONNECTED_CHANNEL_DELETED);
}
}
audioManagerMap.put(id, newMng);
}
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class MessageCreateHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
MessageType type = MessageType.fromId(content.getInt("type"));
if (type == MessageType.UNKNOWN) {
WebSocketClient.LOG.debug("JDA received a message of unknown type. Type: {} JSON: {}", type, content);
return null;
}
// Drop ephemeral messages since they are broken due to missing guild_id
if ((content.getInt("flags", 0) & 64) != 0)
return null;
JDAImpl jda = getJDA();
Guild guild = null;
if (!content.isNull("guild_id")) {
long guildId = content.getLong("guild_id");
if (jda.getGuildSetupController().isLocked(guildId))
return guildId;
guild = api.getGuildById(guildId);
if (guild == null) {
api.getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
EventCache.LOG.debug("Received message for a guild that JDA does not currently have cached");
return null;
}
}
Message message;
try {
message = jda.getEntityBuilder().createMessageWithLookup(content, guild, true);
} catch (IllegalArgumentException e) {
switch(e.getMessage()) {
case EntityBuilder.MISSING_CHANNEL:
{
final long channelId = content.getLong("channel_id");
jda.getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
EventCache.LOG.debug("Received a message for a channel that JDA does not currently have cached");
return null;
}
case EntityBuilder.MISSING_USER:
{
final long authorId = content.getObject("author").getLong("id");
jda.getEventCache().cache(EventCache.Type.USER, authorId, responseNumber, allContent, this::handle);
EventCache.LOG.debug("Received a message for a user that JDA does not currently have cached");
return null;
}
case EntityBuilder.UNKNOWN_MESSAGE_TYPE:
{
WebSocketClient.LOG.debug("Ignoring message with unknown type: {}", content);
return null;
}
default:
throw e;
}
}
MessageChannel channel = message.getChannel();
ChannelType channelType = channel.getType();
// Update the variable that tracks the latest message received in the channel
((MessageChannelMixin<?>) channel).setLatestMessageIdLong(message.getIdLong());
if (channelType.isGuild()) {
if (channelType.isThread()) {
ThreadChannelImpl gThread = (ThreadChannelImpl) channel;
// Discord will only ever allow this property to show up to 50,
// so we don't want to update it to be over 50 because we don't want users to use it incorrectly.
int newMessageCount = Math.min(gThread.getMessageCount() + 1, 50);
gThread.setMessageCount(newMessageCount);
}
} else {
api.usedPrivateChannel(channel.getIdLong());
}
jda.handleEvent(new MessageReceivedEvent(jda, responseNumber, message));
return null;
}
use of net.dv8tion.jda.internal.JDAImpl in project JDA by DV8FromTheWorld.
the class ChannelCreateHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
ChannelType type = ChannelType.fromId(content.getInt("type"));
long guildId = 0;
JDAImpl jda = getJDA();
if (type.isGuild()) {
guildId = content.getLong("guild_id");
if (jda.getGuildSetupController().isLocked(guildId))
return guildId;
}
Channel channel = buildChannel(type, content, guildId);
if (channel == null) {
WebSocketClient.LOG.debug("Discord provided an CREATE_CHANNEL event with an unknown channel type! JSON: {}", content);
return null;
}
jda.handleEvent(new ChannelCreateEvent(jda, responseNumber, channel));
return null;
}
Aggregations