Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* This file is part of Discord4J.
*
* Discord4J is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Discord4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Discord4J. If not, see .
*/
package discord4j.rest.entity;
import discord4j.common.util.Snowflake;
import discord4j.discordjson.json.*;
import discord4j.rest.RestClient;
import discord4j.rest.util.PaginationUtil;
import discord4j.rest.util.Permission;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.annotation.Nullable;
import java.util.*;
import java.util.function.Function;
/**
* Represents a guild entity in Discord. Guilds in Discord represent an isolated collection of users and channels,
* and are often referred to as "servers" in the UI.
*/
public class RestGuild {
private final RestClient restClient;
private final long id;
private RestGuild(RestClient restClient, long id) {
this.restClient = restClient;
this.id = id;
}
/**
* Create a {@link RestGuild} for a given ID. This method does not perform any API request.
*
* @param restClient the client to make API requests
* @param id the ID of this entity
* @return a {@code RestGuild} represented by this {@code id}.
*/
public static RestGuild create(RestClient restClient, Snowflake id) {
return new RestGuild(restClient, id.asLong());
}
static RestGuild create(RestClient restClient, long id) {
return new RestGuild(restClient, id);
}
/**
* Returns the ID of this guild.
*
* @return The ID of this guild
*/
public Snowflake getId() {
return Snowflake.of(id);
}
/**
* Retrieve this guild's data upon subscription.
*
* @param withCounts when true, will return approximate member and presence counts for the guild too.
* otherwise approximate member and presence counts will be null in {@link GuildUpdateData}.
* @return a {@link Mono} where, upon successful completion, emits the {@link GuildUpdateData} belonging to this
* entity. If an error is received, it is emitted through the {@code Mono}.
*/
public Mono getData(@Nullable Boolean withCounts) {
Map queryParams = new HashMap<>();
Optional.ofNullable(withCounts).ifPresent(value -> queryParams.put("with_counts", value));
return restClient.getGuildService().getGuild(id, queryParams);
}
/**
* Retrieve this guild's data upon subscription.
*
* @return a {@link Mono} where, upon successful completion, emits the {@link GuildUpdateData} belonging to this
* entity. If an error is received, it is emitted through the {@code Mono}.
*/
public Mono getData() {
return getData(true);
}
/**
* Return a {@link RestEmoji} representation under this guild. This method does not perform any API request.
*
* @param emojiId the entity ID
* @return a {@code RestEmoji} with the given ID, under this guild
*/
public RestEmoji emoji(Snowflake emojiId) {
return RestEmoji.create(restClient, id, emojiId.asLong());
}
/**
* Return a {@link RestMember} representation under this guild. This method does not perform any API request.
*
* @param memberId the entity ID
* @return a {@code RestMember} with the given ID, under this guild
*/
public RestMember member(Snowflake memberId) {
return RestMember.create(restClient, id, memberId.asLong());
}
/**
* Return a {@link RestRole} representation under this guild. This method does not perform any API request.
*
* @param roleId the entity ID
* @return a {@code RestRole} with the given ID, under this guild
*/
public RestRole role(Snowflake roleId) {
return RestRole.create(restClient, id, roleId.asLong());
}
/**
* Returns a {@link RestScheduledEvent} representation under this guild.
* This method does not perform any API request.
*
* @param eventId The entity ID
* @return a {@code RestGuildScheduledEvent} with the given ID, under this guild
*/
public RestScheduledEvent scheduledEvent(Snowflake eventId) {
return RestScheduledEvent.create(restClient, id, eventId.asLong());
}
/**
* Modify a guild's settings. Requires the {@link Permission#MANAGE_GUILD} permission. Returns the updated guild
* object on success.
*
* @param request the modify request body
* @param reason an optional reason for the audit log
* @return a {@link Mono} where, upon subscription, emits the updated {@link GuildUpdateData} on success. If an
* error is received, it is emitted through the {@code Mono}.
*/
public Mono modify(GuildModifyRequest request, @Nullable String reason) {
return restClient.getGuildService().modifyGuild(id, request, reason);
}
/**
* Delete a guild permanently. Requires the {@link Permission#MANAGE_GUILD} permission. Returns empty on success.
*
* @return a {@link Mono} where, upon subscription, emits a complete signal on success. If an error is received, it
* is emitted through the {@code Mono}.
*/
public Mono delete() {
return restClient.getGuildService().deleteGuild(id);
}
/**
* Return a {@link Flux} of guild channels.
*
* @return a sequence of this guild channels
*/
public Flux getChannels() {
return restClient.getGuildService().getGuildChannels(id);
}
/**
* Create a new channel object for the guild. Requires the {@link Permission#MANAGE_CHANNELS} permission. Returns
* the new channel object on success.
*
* @param request the request body
* @param reason an optional reason for the audit log
* @return a {@link Mono} where, upon subscription, emits the created {@link ChannelData} on success. If an error
* is received, it is emitted through the {@code Mono}.
*/
public Mono createChannel(ChannelCreateRequest request, @Nullable String reason) {
return restClient.getGuildService().createGuildChannel(id, request, reason);
}
public Flux modifyChannelPositions(List requests) {
return restClient.getGuildService()
.modifyGuildChannelPositions(id, requests.toArray(new PositionModifyRequest[0]));
}
public Mono getMember(Snowflake userId) {
return restClient.getGuildService().getGuildMember(id, userId.asLong());
}
public Mono getSelfMember() {
return restClient.getSelf()
.map(UserData::id)
.map(Snowflake::of)
.flatMap(this::getMember);
}
public Flux getMembers() {
Function