Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CompletableFutures for Channels, Guilds, etc #1158

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions javacord-api/src/main/java/org/javacord/api/DiscordApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2180,4 +2180,28 @@ default Optional<PrivateChannel> getPrivateChannelById(String id) {
return Optional.empty();
}
}

/**
* Used to request a server.
*
* @param id The id of the server.
* @return A server request.
*/
CompletableFuture<Server> requestServerById(long id);

/**
* Used to request a server.
*
* @param id The id of the server.
* @return A server request.
*/
default CompletableFuture<Server> requestServerById(String id) {
try {
return requestServerById(Long.parseLong(id));
} catch (NumberFormatException e) {
CompletableFuture<Server> future = new CompletableFuture<>();
future.completeExceptionally(e);
return future;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.javacord.api.entity.channel;

public enum ChannelFlag {
/**
* This thread is pinned to the top of its parent GUILD_FORUM channel.
*/
PINNED(1 << 1),
/**
* Whether a tag is required to be specified when creating a thread
* in a GUILD_FORUM channel.
* Tags are specified in the applied_tags field.
*/
REQUIRE_TAG(1 << 2),
/**
* This flag in unknown.
*/
UNKNOWN(-1);

private final int flag;

/**
* Class constructor.
*
* @param flag The bitmask of the flag.
*/
ChannelFlag(int flag) {
this.flag = flag;
}

/**
* Gets the integer value of the flag.
*
* @return The integer value of the flag.
*/
public int asInt() {
return flag;
}

/**
* Gets the flag from the given integer.
*
* @param flag The integer to get the flag from.
* @return The flag.
*/
public static ChannelFlag getByValue(int flag) {
for (ChannelFlag channelFlag : values()) {
if (channelFlag.asInt() == flag) {
return channelFlag;
}
}
return UNKNOWN;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,119 @@
package org.javacord.api.entity.channel;

import org.javacord.api.entity.Mentionable;
import org.javacord.api.entity.channel.forum.DefaultReaction;
import org.javacord.api.entity.channel.forum.ForumTag;
import org.javacord.api.entity.channel.forum.PermissionOverwrite;
import org.javacord.api.entity.channel.forum.SortOrderType;
import org.javacord.api.entity.channel.thread.ThreadMetadata;
import org.javacord.api.listener.channel.server.forum.ServerForumChannelAttachableListenerManager;

import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

/**
* This class represents a server forum channel.
*/
public interface ServerForumChannel extends RegularServerChannel, Mentionable, Categorizable,
ServerForumChannelAttachableListenerManager {

/**
* Gets the topic of the forum channel.
*
* @return The topic of the forum channel.
*/
String getTopic();

/**
* Gets the amount of seconds a user has to wait before sending another message (0-21600).
*
* @return The amount of seconds a user has to wait before sending another message.
*/
int getRateLimitPerUser();

/**
* Gets the position of the forum channel.
*
* @return The position of the forum channel.
*/
int getPosition();

/**
* Gets the permission overwrites of the forum channel.
*
* @return The permission overwrites of the forum channel.
*/
List<PermissionOverwrite> getPermissionOverwrites();

/**
* Gets whether the forum channel is nsfw.
*
* @return Whether the forum channel is nsfw.
*/
boolean isNsfw();

/**
* Gets the last message id of the forum channel.
*
* @return The last message id of the forum channel.
*/
Optional<Long> getLastMessageId();

/**
* Gets the last message id of the forum channel as a string.
*
* @return The last message id of the forum channel as a string.
*/
default Optional<String> getLastMessageIdAsString() {
return getLastMessageId().map(Long::toUnsignedString);
}

/**
* Gets the default rate limit per user of the forum channel.
*
* @return The default rate limit per user of the forum channel.
*/
int getDefaultRateLimitPerUser();

/**
* Gets the forum channel's flags.
*
* @return The forum channel's flags.
*/
EnumSet<ChannelFlag> getFlags();

/**
* Used to get the set of tags that can be used in the forum channel.
*
* @return The set of tags that can be used in the forum channel.
*/
List<ForumTag> getAvailableTags();

/**
* Used to get the template for the forum channel.
*
* @return The template for the forum channel.
*/
Optional<String> getTemplate();

/**
* Gets the default sort type used to order the posts in the forum channel.
*
* @return The default sort type used to order the posts in the forum channel.
*/
Optional<SortOrderType> getDefaultSortType();

/**
* Gets the default emoji shown in the add reaction button.
*
* @return The default emoji shown in the add reaction button.
*/
Optional<DefaultReaction> getDefaultReaction();

/**
* Creates an updater for this channel.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.javacord.api.entity.channel;

import org.javacord.api.entity.channel.forum.PermissionOverwrite;
import org.javacord.api.entity.channel.internal.ServerForumChannelUpdaterDelegate;
import org.javacord.api.util.internal.DelegateFactory;

import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
Expand Down Expand Up @@ -35,6 +38,61 @@ public ServerForumChannelUpdater setCategory(ChannelCategory category) {
return this;
}

/**
* Queues the topic to be updated.
*
* @param topic The new topic of the channel.
* @return The current instance in order to chain call methods.
*/
public ServerForumChannelUpdater setTopic(String topic) {
delegate.setTopic(topic);
return this;
}

/**
* Queues the rate limit per user to be updated.
*
* @param rateLimitPerUser The new rate limit per user of the channel.
* @return The current instance in order to chain call methods.
*/
public ServerForumChannelUpdater setRateLimitPerUser(int rateLimitPerUser) {
delegate.setRateLimitPerUser(rateLimitPerUser);
return this;
}

/**
* Queues the position to be updated.
*
* @param position The new position of the channel.
* @return The current instance in order to chain call methods.
*/
public ServerForumChannelUpdater setPosition(int position) {
delegate.setPosition(position);
return this;
}

/**
* Queues the permission overwrites to be updated.
*
* @param permissionOverwrites The new permission overwrites of the channel.
* @return The current instance in order to chain call methods.
*/
public ServerForumChannelUpdater setPermissionOverwrites(List<PermissionOverwrite> permissionOverwrites) {
delegate.setPermissionOverwrites(permissionOverwrites);
return this;
}

/**
* Queues the nsfw flag to be updated.
*
* @param nsfw The new nsfw flag of the channel.
* @return The current instance in order to chain call methods.
*/
public ServerForumChannelUpdater setNsfw(boolean nsfw) {
delegate.setNsfw(nsfw);
return this;
}

/**
* Queues the category to be removed.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.javacord.api.entity.channel.forum;

import java.util.Optional;

/**
* This class represents a default reaction.
*/
public interface DefaultReaction {
/**
* Gets the id of a guild's custom emoji.
*
* @return The id of a guild's custom emoji.
*/
long getEmojiId();

/**
* Gets the id of a guild's custom emoji as a string.
*
* @return The id of a guild's custom emoji as a string.
*/
default String getEmojiIdAsString() {
return Long.toUnsignedString(getEmojiId());
}

/**
* Gets the name of a guild's custom emoji.
*
* @return The name of a guild's custom emoji.
*/
Optional<String> getEmojiName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.javacord.api.entity.channel.forum;

import org.javacord.api.entity.DiscordEntity;
import org.javacord.api.entity.Nameable;

/**
* This class represents a forum tag.
*/
public interface ForumTag extends DiscordEntity, Nameable {
/**
* Gets whether this tag can only be added to or removed from a thread by a moderator.
*
* @return Whether this tag is locked to MANAGE_THREADS members
*/
boolean isModerated();

/**
* Gets the id of a guild's custom emoji.
*
* @return The id of a guild's custom emoji.
*/
long getEmojiId();

/**
* Gets the id of a guild's custom emoji as a string.
*
* @return The id of a guild's custom emoji as a string.
*/
default String getEmojiIdAsString() {
return Long.toUnsignedString(getEmojiId());
}

/**
* Gets the name of a guild's custom emoji.
*
* @return The name of a guild's custom emoji.
*/
String getEmojiName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.javacord.api.entity.channel.forum;

import org.javacord.api.entity.DiscordEntity;

public interface PermissionOverwrite extends DiscordEntity {
/**
* Gets the type of the permission overwrite.
* Either 0 (role) or 1 (member).
*
* @return The type of the permission overwrite.
*/
int getType();

/**
* Gets the allowed permissions bit set.
*
* @return The allowed permissions bit set.
*/
int getAllowed();

/**
* Gets the denied permissions bit set.
*
* @return The denied permissions bit set.
*/
int getDenied();
}
Loading