use of net.dv8tion.jda.internal.requests.Route in project JDA by DV8FromTheWorld.
the class BaseGuildMessageChannelMixin method retrieveWebhooks.
@Nonnull
@Override
default RestAction<List<Webhook>> retrieveWebhooks() {
checkPermission(Permission.MANAGE_WEBHOOKS);
Route.CompiledRoute route = Route.Channels.GET_WEBHOOKS.compile(getId());
JDAImpl jda = (JDAImpl) getJDA();
return new RestActionImpl<>(jda, route, (response, request) -> {
DataArray array = response.getArray();
List<Webhook> webhooks = new ArrayList<>(array.length());
EntityBuilder builder = jda.getEntityBuilder();
for (int i = 0; i < array.length(); i++) {
try {
webhooks.add(builder.createWebhook(array.getObject(i)));
} catch (UncheckedIOException | NullPointerException e) {
JDAImpl.LOG.error("Error while creating websocket from json", e);
}
}
return Collections.unmodifiableList(webhooks);
});
}
use of net.dv8tion.jda.internal.requests.Route in project JDA by DV8FromTheWorld.
the class InviteImpl method expand.
@Nonnull
@Override
public RestAction<Invite> expand() {
if (this.expanded)
return new CompletedRestAction<>(getJDA(), this);
if (this.type != Invite.InviteType.GUILD)
throw new IllegalStateException("Only guild invites can be expanded");
final net.dv8tion.jda.api.entities.Guild guild = this.api.getGuildById(this.guild.getIdLong());
if (guild == null)
throw new UnsupportedOperationException("You're not in the guild this invite points to");
final Member member = guild.getSelfMember();
Route.CompiledRoute route;
// TODO-v5: There are more than Text and Voice channels now. Revisit this.
final IPermissionContainer channel = this.channel.getType() == ChannelType.TEXT ? guild.getTextChannelById(this.channel.getIdLong()) : guild.getVoiceChannelById(this.channel.getIdLong());
if (member.hasPermission(channel, Permission.MANAGE_CHANNEL)) {
route = Route.Invites.GET_CHANNEL_INVITES.compile(channel.getId());
} else if (member.hasPermission(Permission.MANAGE_SERVER)) {
route = Route.Invites.GET_GUILD_INVITES.compile(guild.getId());
} else {
throw new InsufficientPermissionException(channel, Permission.MANAGE_CHANNEL, "You don't have the permission to view the full invite info");
}
return new RestActionImpl<>(this.api, route, (response, request) -> {
final EntityBuilder entityBuilder = this.api.getEntityBuilder();
final DataArray array = response.getArray();
for (int i = 0; i < array.length(); i++) {
final DataObject object = array.getObject(i);
if (InviteImpl.this.code.equals(object.getString("code"))) {
return entityBuilder.createInvite(object);
}
}
throw new IllegalStateException("Missing the invite in the channel/guild invite list");
});
}
use of net.dv8tion.jda.internal.requests.Route 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.requests.Route in project JDA by DV8FromTheWorld.
the class NewsChannelImpl method follow.
@Nonnull
@Override
public RestAction<Webhook.WebhookReference> follow(@Nonnull String targetChannelId) {
Checks.notNull(targetChannelId, "Target Channel ID");
Route.CompiledRoute route = Route.Channels.FOLLOW_CHANNEL.compile(getId());
DataObject body = DataObject.empty().put("webhook_channel_id", targetChannelId);
return new RestActionImpl<>(getJDA(), route, body, (response, request) -> {
DataObject json = response.getObject();
return new Webhook.WebhookReference(request.getJDA(), json.getUnsignedLong("webhook_id"), json.getUnsignedLong("channel_id"));
});
}
use of net.dv8tion.jda.internal.requests.Route in project JDA by DV8FromTheWorld.
the class MessageChannelMixin method bulkDeleteMessages.
// ---- Helpers -----
default RestActionImpl<Void> bulkDeleteMessages(Collection<String> messageIds) {
DataObject body = DataObject.empty().put("messages", messageIds);
Route.CompiledRoute route = Route.Messages.DELETE_MESSAGES.compile(getId());
return new RestActionImpl<>(getJDA(), route, body);
}
Aggregations