use of net.dv8tion.jda.api.exceptions.ParsingException in project JDA by DV8FromTheWorld.
the class ThreadChannelPaginationActionImpl method handleSuccess.
@Override
protected void handleSuccess(Response response, Request<List<ThreadChannel>> request) {
DataObject obj = response.getObject();
DataArray selfThreadMembers = obj.getArray("members");
DataArray threads = obj.getArray("threads");
List<ThreadChannel> list = new ArrayList<>(threads.length());
EntityBuilder builder = api.getEntityBuilder();
TLongObjectMap<DataObject> selfThreadMemberMap = new TLongObjectHashMap<>();
for (int i = 0; i < selfThreadMembers.length(); i++) {
DataObject selfThreadMember = selfThreadMembers.getObject(i);
// Store the thread member based on the "id" which is the _thread's_ id, not the member's id (which would be our id)
selfThreadMemberMap.put(selfThreadMember.getLong("id"), selfThreadMember);
}
for (int i = 0; i < threads.length(); i++) {
try {
DataObject threadObj = threads.getObject(i);
DataObject selfThreadMemberObj = selfThreadMemberMap.get(threadObj.getLong("id", 0));
if (selfThreadMemberObj != null) {
// Combine the thread and self thread-member into a single object to model what we get from
// thread payloads (like from Gateway, etc)
threadObj.put("member", selfThreadMemberObj);
}
ThreadChannel thread = builder.createThreadChannel(threadObj, getGuild().getIdLong());
list.add(thread);
if (this.useCache)
this.cached.add(thread);
this.last = thread;
this.lastKey = last.getIdLong();
} catch (ParsingException | NullPointerException e) {
LOG.warn("Encountered exception in ThreadChannelPagination", e);
}
}
request.onSuccess(list);
}
use of net.dv8tion.jda.api.exceptions.ParsingException in project JDA by DV8FromTheWorld.
the class WebSocketClient method onDispatch.
protected void onDispatch(DataObject raw) {
String type = raw.getString("t");
long responseTotal = api.getResponseTotal();
if (!raw.isType("d", DataType.OBJECT)) {
// Needs special handling due to content of "d" being an array
if (type.equals("PRESENCES_REPLACE")) {
final DataArray payload = raw.getArray("d");
final List<DataObject> converted = convertPresencesReplace(responseTotal, payload);
final SocketHandler handler = getHandler("PRESENCE_UPDATE");
LOG.trace("{} -> {}", type, payload);
for (DataObject o : converted) {
handler.handle(responseTotal, o);
// Send raw event after cache has been updated - including comment
if (api.isRawEvents())
api.handleEvent(new RawGatewayEvent(api, responseTotal, o));
}
} else {
LOG.debug("Received event with unhandled body type JSON: {}", raw);
}
return;
}
DataObject content = raw.getObject("d");
LOG.trace("{} -> {}", type, content);
JDAImpl jda = (JDAImpl) getJDA();
try {
switch(type) {
// INIT types
case "READY":
reconnectTimeoutS = 2;
api.setStatus(JDA.Status.LOADING_SUBSYSTEMS);
processingReady = true;
handleIdentifyRateLimit = false;
// first handle the ready payload before applying the session id
// this prevents a possible race condition with the cache of the guild setup controller
// otherwise the audio connection requests that are currently pending might be removed in the process
handlers.get("READY").handle(responseTotal, raw);
sessionId = content.getString("session_id");
break;
case "RESUMED":
reconnectTimeoutS = 2;
sentAuthInfo = true;
if (!processingReady) {
initiating = false;
ready();
} else {
LOG.debug("Resumed while still processing initial ready");
jda.setStatus(JDA.Status.LOADING_SUBSYSTEMS);
}
break;
default:
long guildId = content.getLong("guild_id", 0L);
if (api.isUnavailable(guildId) && !type.equals("GUILD_CREATE") && !type.equals("GUILD_DELETE")) {
LOG.debug("Ignoring {} for unavailable guild with id {}. JSON: {}", type, guildId, content);
break;
}
SocketHandler handler = handlers.get(type);
if (handler != null)
handler.handle(responseTotal, raw);
else
LOG.debug("Unrecognized event:\n{}", raw);
}
// Send raw event after cache has been updated
if (api.isRawEvents())
api.handleEvent(new RawGatewayEvent(api, responseTotal, raw));
} catch (ParsingException ex) {
LOG.warn("Got an unexpected Json-parse error. Please redirect the following message to the devs:\n\tJDA {}\n\t{}\n\t{} -> {}", JDAInfo.VERSION, ex.getMessage(), type, content, ex);
} catch (Exception ex) {
LOG.error("Got an unexpected error. Please redirect the following message to the devs:\n\tJDA {}\n\t{} -> {}", JDAInfo.VERSION, type, content, ex);
}
if (responseTotal % EventCache.TIMEOUT_AMOUNT == 0)
jda.getEventCache().timeout(responseTotal);
}
Aggregations