use of net.dv8tion.jda.internal.requests.RestActionImpl in project JDA by DV8FromTheWorld.
the class ThreadChannelImpl method retrieveThreadMembers.
@Override
public RestAction<List<ThreadMember>> retrieveThreadMembers() {
// TODO-threads: This interacts with GUILD_MEMBERS in some way. Need to test and document how.
Route.CompiledRoute route = Route.Channels.LIST_THREAD_MEMBERS.compile(getId());
return new RestActionImpl<>(getJDA(), route, (response, request) -> {
EntityBuilder builder = api.getEntityBuilder();
List<ThreadMember> threadMembers = new LinkedList<>();
DataArray memberArr = response.getArray();
for (int i = 0; i < memberArr.length(); i++) {
final DataObject object = memberArr.getObject(i);
// Very possible this is gonna break because we don't get user/member info with threadmembers
// TODO revisit the @Nonnull annotations in ThreadMember due to the lack of user/member info. Might be a time to introduce RestX entities?
threadMembers.add(builder.createThreadMember((GuildImpl) this.getGuild(), this, object));
}
return Collections.unmodifiableList(threadMembers);
});
}
use of net.dv8tion.jda.internal.requests.RestActionImpl in project JDA by DV8FromTheWorld.
the class MessageReaction method removeReaction.
/**
* Removes this Reaction from the Message.
* <br>This will remove the reaction of the {@link net.dv8tion.jda.api.entities.User User}
* provided.
*
* <p>If the provided User did not react with this Reaction this does nothing.
*
* <p>Possible ErrorResponses include:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>If the message this reaction was attached to got deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>If the channel this reaction was used in got deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>If we were removed from the channel/guild</li>
* </ul>
*
* @param user
* The User of which to remove the reaction
*
* @throws java.lang.IllegalArgumentException
* If the provided {@code user} is null.
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the provided User is not us and we do not have permission to
* {@link net.dv8tion.jda.api.Permission#MESSAGE_MANAGE manage messages}
* in the channel this reaction was used in
* @throws net.dv8tion.jda.api.exceptions.PermissionException
* If the message is from another user in a {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel}
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction}
* Nothing is returned on success
*/
@Nonnull
@CheckReturnValue
public RestAction<Void> removeReaction(@Nonnull User user) {
Checks.notNull(user, "User");
boolean self = user.equals(getJDA().getSelfUser());
if (!self) {
if (!channel.getType().isGuild()) {
throw new PermissionException("Unable to remove Reaction of other user in non-guild channels!");
}
IPermissionContainer permChannel = (IPermissionContainer) this.channel;
if (!permChannel.getGuild().getSelfMember().hasPermission(permChannel, Permission.MESSAGE_MANAGE))
throw new InsufficientPermissionException(permChannel, Permission.MESSAGE_MANAGE);
}
String code = getReactionCode();
String target = self ? "@me" : user.getId();
Route.CompiledRoute route = Route.Messages.REMOVE_REACTION.compile(channel.getId(), getMessageId(), code, target);
return new RestActionImpl<>(getJDA(), route);
}
use of net.dv8tion.jda.internal.requests.RestActionImpl in project JDA by DV8FromTheWorld.
the class NewsChannel method crosspostMessageById.
/**
* Attempts to crosspost the provided message.
*
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#ALREADY_CROSSPOSTED ALREADY_CROSSPOSTED}
* <br>The target message has already been crossposted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>The request was attempted after the account lost access to the
* {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed, or after {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL}
* was revoked in the {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The request was attempted after the account lost
* {@link net.dv8tion.jda.api.Permission#MESSAGE_MANAGE Permission.MESSAGE_MANAGE} in the TextChannel.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or
* the message it referred to has already been deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>The request was attempted after the channel was deleted.</li>
* </ul>
*
* @param messageId
* The messageId to crosspost
*
* @throws java.lang.IllegalArgumentException
* If provided {@code messageId} is {@code null} or empty.
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have
* {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} in this channel.
*
* @return {@link net.dv8tion.jda.api.requests.RestAction} - Type: {@link Message}
*
* @since 4.2.1
*/
@Nonnull
@CheckReturnValue
default RestAction<Message> crosspostMessageById(@Nonnull String messageId) {
Checks.isSnowflake(messageId);
if (!getGuild().getSelfMember().hasAccess(this))
throw new MissingAccessException(this, Permission.VIEW_CHANNEL);
Route.CompiledRoute route = Route.Messages.CROSSPOST_MESSAGE.compile(getId(), messageId);
return new RestActionImpl<>(getJDA(), route, (response, request) -> request.getJDA().getEntityBuilder().createMessageWithChannel(response.getObject(), this, false));
}
use of net.dv8tion.jda.internal.requests.RestActionImpl in project JDA by DV8FromTheWorld.
the class ShardManager method retrieveUserById.
/**
* Attempts to retrieve a {@link net.dv8tion.jda.api.entities.User User} object based on the provided id.
* <br>This first calls {@link #getUserById(long)}, and if the return is {@code null} then a request
* is made to the Discord servers.
*
* <p>The returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} can encounter the following Discord errors:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_USER ErrorResponse.UNKNOWN_USER}
* <br>Occurs when the provided id does not refer to a {@link net.dv8tion.jda.api.entities.User User}
* known by Discord. Typically occurs when developers provide an incomplete id (cut short).</li>
* </ul>
*
* @param id
* The id of the requested {@link net.dv8tion.jda.api.entities.User User}.
*
* @throws java.lang.IllegalStateException
* If there isn't any active shards.
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.User User}
* <br>On request, gets the User with id matching provided id from Discord.
*/
@Nonnull
@CheckReturnValue
default RestAction<User> retrieveUserById(long id) {
JDA api = null;
for (JDA shard : getShardCache()) {
api = shard;
EnumSet<GatewayIntent> intents = shard.getGatewayIntents();
User user = shard.getUserById(id);
boolean isUpdated = intents.contains(GatewayIntent.GUILD_PRESENCES) || intents.contains(GatewayIntent.GUILD_MEMBERS);
if (user != null && isUpdated)
return new CompletedRestAction<>(shard, user);
}
if (api == null)
throw new IllegalStateException("no shards active");
JDAImpl jda = (JDAImpl) api;
Route.CompiledRoute route = Route.Users.GET_USER.compile(Long.toUnsignedString(id));
return new RestActionImpl<>(jda, route, (response, request) -> jda.getEntityBuilder().createUser(response.getObject()));
}
use of net.dv8tion.jda.internal.requests.RestActionImpl in project JDA by DV8FromTheWorld.
the class JDA method getRestPing.
/**
* The time in milliseconds that discord took to respond to a REST request.
* <br>This will request the current user from the API and calculate the time the response took.
*
* <h4>Example</h4>
* <pre><code>
* jda.getRestPing().queue( (time) {@literal ->}
* channel.sendMessageFormat("Ping: %d ms", time).queue()
* );
* </code></pre>
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: long
*
* @since 4.0.0
*
* @see #getGatewayPing()
*/
@Nonnull
default RestAction<Long> getRestPing() {
AtomicLong time = new AtomicLong();
Route.CompiledRoute route = Route.Self.GET_SELF.compile();
RestActionImpl<Long> action = new RestActionImpl<>(this, route, (response, request) -> System.currentTimeMillis() - time.get());
action.setCheck(() -> {
time.set(System.currentTimeMillis());
return true;
});
return action;
}
Aggregations