use of net.dv8tion.jda.internal.entities.EntityBuilder in project JDA by DV8FromTheWorld.
the class ReadyHandler method handleReady.
public void handleReady(DataObject content) {
EntityBuilder builder = getJDA().getEntityBuilder();
DataArray privateChannels = content.getArray("private_channels");
for (int i = 0; i < privateChannels.length(); i++) {
DataObject chan = privateChannels.getObject(i);
ChannelType type = ChannelType.fromId(chan.getInt("type"));
// noinspection SwitchStatementWithTooFewBranches
switch(type) {
case PRIVATE:
builder.createPrivateChannel(chan);
break;
default:
WebSocketClient.LOG.warn("Received a Channel in the private_channels array in READY of an unknown type! Type: {}", type);
}
}
}
use of net.dv8tion.jda.internal.entities.EntityBuilder in project JDA by DV8FromTheWorld.
the class JDAImpl method retrieveWebhookById.
@Nonnull
@Override
public RestAction<Webhook> retrieveWebhookById(@Nonnull String webhookId) {
Checks.isSnowflake(webhookId, "Webhook ID");
Route.CompiledRoute route = Route.Webhooks.GET_WEBHOOK.compile(webhookId);
return new RestActionImpl<>(this, route, (response, request) -> {
DataObject object = response.getObject();
EntityBuilder builder = getEntityBuilder();
return builder.createWebhook(object);
});
}
use of net.dv8tion.jda.internal.entities.EntityBuilder in project JDA by DV8FromTheWorld.
the class MessagePaginationActionImpl method handleSuccess.
@Override
protected void handleSuccess(Response response, Request<List<Message>> request) {
DataArray array = response.getArray();
List<Message> messages = new ArrayList<>(array.length());
EntityBuilder builder = api.getEntityBuilder();
for (int i = 0; i < array.length(); i++) {
try {
Message msg = builder.createMessageWithChannel(array.getObject(i), channel, false);
messages.add(msg);
} catch (ParsingException | NullPointerException e) {
LOG.warn("Encountered an exception in MessagePagination", e);
} catch (IllegalArgumentException e) {
if (EntityBuilder.UNKNOWN_MESSAGE_TYPE.equals(e.getMessage()))
LOG.warn("Skipping unknown message type during pagination", e);
else
LOG.warn("Unexpected issue trying to parse message during pagination", e);
}
}
if (order == PaginationOrder.FORWARD)
Collections.reverse(messages);
if (useCache)
cached.addAll(messages);
if (!messages.isEmpty()) {
last = messages.get(messages.size() - 1);
lastKey = last.getIdLong();
}
request.onSuccess(messages);
}
use of net.dv8tion.jda.internal.entities.EntityBuilder in project JDA by DV8FromTheWorld.
the class ReactionPaginationActionImpl method handleSuccess.
@Override
protected void handleSuccess(Response response, Request<List<User>> request) {
final EntityBuilder builder = api.getEntityBuilder();
final DataArray array = response.getArray();
final List<User> users = new LinkedList<>();
for (int i = 0; i < array.length(); i++) {
try {
final User user = builder.createUser(array.getObject(i));
users.add(user);
if (useCache)
cached.add(user);
last = user;
lastKey = last.getIdLong();
} catch (ParsingException | NullPointerException e) {
LOG.warn("Encountered exception in ReactionPagination", e);
}
}
request.onSuccess(users);
}
use of net.dv8tion.jda.internal.entities.EntityBuilder in project JDA by DV8FromTheWorld.
the class AuditLogPaginationActionImpl method handleSuccess.
@Override
protected void handleSuccess(Response response, Request<List<AuditLogEntry>> request) {
DataObject obj = response.getObject();
DataArray users = obj.getArray("users");
DataArray webhooks = obj.getArray("webhooks");
DataArray entries = obj.getArray("audit_log_entries");
List<AuditLogEntry> list = new ArrayList<>(entries.length());
EntityBuilder builder = api.getEntityBuilder();
TLongObjectMap<DataObject> userMap = new TLongObjectHashMap<>();
for (int i = 0; i < users.length(); i++) {
DataObject user = users.getObject(i);
userMap.put(user.getLong("id"), user);
}
TLongObjectMap<DataObject> webhookMap = new TLongObjectHashMap<>();
for (int i = 0; i < webhooks.length(); i++) {
DataObject webhook = webhooks.getObject(i);
webhookMap.put(webhook.getLong("id"), webhook);
}
for (int i = 0; i < entries.length(); i++) {
try {
DataObject entry = entries.getObject(i);
DataObject user = userMap.get(entry.getLong("user_id", 0));
DataObject webhook = webhookMap.get(entry.getLong("target_id", 0));
AuditLogEntry result = builder.createAuditLogEntry((GuildImpl) guild, entry, user, webhook);
list.add(result);
if (this.useCache)
this.cached.add(result);
this.last = result;
this.lastKey = last.getIdLong();
} catch (ParsingException | NullPointerException e) {
LOG.warn("Encountered exception in AuditLogPagination", e);
}
}
request.onSuccess(list);
}
Aggregations