use of net.dv8tion.jda.api.utils.data.DataArray in project JDA by DV8FromTheWorld.
the class GuildImpl method retrieveRegions.
@Nonnull
@Override
public RestAction<EnumSet<Region>> retrieveRegions(boolean includeDeprecated) {
Route.CompiledRoute route = Route.Guilds.GET_VOICE_REGIONS.compile(getId());
return new RestActionImpl<>(getJDA(), route, (response, request) -> {
EnumSet<Region> set = EnumSet.noneOf(Region.class);
DataArray arr = response.getArray();
for (int i = 0; i < arr.length(); i++) {
DataObject obj = arr.getObject(i);
if (!includeDeprecated && obj.getBoolean("deprecated"))
continue;
String id = obj.getString("id", "");
Region region = Region.fromKey(id);
if (region != Region.UNKNOWN)
set.add(region);
}
return set;
});
}
use of net.dv8tion.jda.api.utils.data.DataArray in project JDA by DV8FromTheWorld.
the class GuildImpl method updateCommandPrivilegesById.
@Nonnull
@Override
public RestAction<List<CommandPrivilege>> updateCommandPrivilegesById(@Nonnull String id, @Nonnull Collection<? extends CommandPrivilege> privileges) {
Checks.isSnowflake(id, "ID");
Checks.noneNull(privileges, "Privileges");
Checks.check(privileges.size() <= 10, "Cannot have more than 10 privileges for a command!");
Route.CompiledRoute route = Route.Interactions.EDIT_COMMAND_PERMISSIONS.compile(getJDA().getSelfUser().getApplicationId(), getId(), id);
DataArray array = DataArray.fromCollection(privileges);
return new RestActionImpl<>(getJDA(), route, DataObject.empty().put("permissions", array), (response, request) -> parsePrivilegesList(response.getObject()));
}
use of net.dv8tion.jda.api.utils.data.DataArray in project JDA by DV8FromTheWorld.
the class GuildImpl method retrieveWebhooks.
@Nonnull
@Override
public RestAction<List<Webhook>> retrieveWebhooks() {
if (!getSelfMember().hasPermission(Permission.MANAGE_WEBHOOKS))
throw new InsufficientPermissionException(this, Permission.MANAGE_WEBHOOKS);
Route.CompiledRoute route = Route.Guilds.GET_WEBHOOKS.compile(getId());
return new RestActionImpl<>(getJDA(), route, (response, request) -> {
DataArray array = response.getArray();
List<Webhook> webhooks = new ArrayList<>(array.length());
EntityBuilder builder = api.getEntityBuilder();
for (int i = 0; i < array.length(); i++) {
try {
webhooks.add(builder.createWebhook(array.getObject(i)));
} catch (Exception e) {
JDAImpl.LOG.error("Error creating webhook from json", e);
}
}
return Collections.unmodifiableList(webhooks);
});
}
use of net.dv8tion.jda.api.utils.data.DataArray in project JDA by DV8FromTheWorld.
the class GuildImpl method retrieveActiveThreads.
@Nonnull
@Override
public RestAction<List<ThreadChannel>> retrieveActiveThreads() {
Route.CompiledRoute route = Route.Guilds.LIST_ACTIVE_THREADS.compile(getId());
return new RestActionImpl<>(api, route, (response, 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++) {
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, this.getIdLong());
list.add(thread);
}
return Collections.unmodifiableList(list);
});
}
use of net.dv8tion.jda.api.utils.data.DataArray in project JDA by DV8FromTheWorld.
the class GuildImpl method retrieveTemplates.
@Nonnull
@Override
public RestAction<List<Template>> retrieveTemplates() {
if (!this.getSelfMember().hasPermission(Permission.MANAGE_SERVER))
throw new InsufficientPermissionException(this, Permission.MANAGE_SERVER);
final Route.CompiledRoute route = Route.Templates.GET_GUILD_TEMPLATES.compile(getId());
return new RestActionImpl<>(getJDA(), route, (response, request) -> {
EntityBuilder entityBuilder = api.getEntityBuilder();
DataArray array = response.getArray();
List<Template> templates = new ArrayList<>(array.length());
for (int i = 0; i < array.length(); i++) {
try {
templates.add(entityBuilder.createTemplate(array.getObject(i)));
} catch (Exception e) {
JDAImpl.LOG.error("Error creating template from json", e);
}
}
return Collections.unmodifiableList(templates);
});
}
Aggregations