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 support for news channel #1162

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
60 changes: 60 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 @@ -11,6 +11,7 @@
import org.javacord.api.entity.channel.RegularServerChannel;
import org.javacord.api.entity.channel.ServerChannel;
import org.javacord.api.entity.channel.ServerForumChannel;
import org.javacord.api.entity.channel.ServerNewsChannel;
import org.javacord.api.entity.channel.ServerStageVoiceChannel;
import org.javacord.api.entity.channel.ServerTextChannel;
import org.javacord.api.entity.channel.ServerThreadChannel;
Expand Down Expand Up @@ -1553,6 +1554,13 @@ default Set<Role> getRolesByNameIgnoreCase(String name) {
*/
Set<ServerTextChannel> getServerTextChannels();

/**
* Gets all server news channels of the bot.
*
* @return All server news channels of the bot.
*/
Set<ServerNewsChannel> getServerNewsChannels();

/**
* Gets all server forum channels of the bot.
*
Expand Down Expand Up @@ -1953,6 +1961,58 @@ default Set<ServerTextChannel> getServerTextChannelsByNameIgnoreCase(String name
.collect(Collectors.toSet()));
}

/**
* Gets a server news channel by its id.
*
* @param id The id of the server news channel.
* @return The server news channel with the given id.
*/
default Optional<ServerNewsChannel> getServerNewsChannelById(long id) {
return getChannelById(id).flatMap(Channel::asServerNewsChannel);
}

/**
* Gets a server news channel by its id.
*
* @param id The id of the server news channel.
* @return The server news channel with the given id.
*/
default Optional<ServerNewsChannel> getServerNewsChannelById(String id) {
try {
return getServerNewsChannelById(Long.parseLong(id));
} catch (NumberFormatException e) {
return Optional.empty();
}
}

/**
* Gets all server news channels with the given name.
* This method is case-sensitive!
*
* @param name The name of the server news channels.
* @return All server news channels with the given name.
*/
default Set<ServerNewsChannel> getServerNewsChannelsByName(String name) {
return Collections.unmodifiableSet(
getServerNewsChannels().stream()
.filter(channel -> channel.getName().equals(name))
.collect(Collectors.toSet()));
}

/**
* Gets all server news channels with the given name.
* This method is case-insensitive!
*
* @param name The name of the server news channels.
* @return All server news channels with the given name.
*/
default Set<ServerNewsChannel> getServerNewsChannelsByNameIgnoreCase(String name) {
return Collections.unmodifiableSet(
getServerNewsChannels().stream()
.filter(channel -> channel.getName().equalsIgnoreCase(name))
.collect(Collectors.toSet()));
}

/**
* Gets a server forum channel by its id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ default Optional<ServerTextChannel> asServerTextChannel() {
}

/**
* Gets the channel as server news channel.
*
* @return The channel as server news channel.
*/
default Optional<ServerNewsChannel> asServerNewsChannel() {
return as(ServerNewsChannel.class);
}

* Gets the channel as textable regular server channel.
*
* @return The channel as textable regular server channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public enum ChannelType {
GROUP_CHANNEL(3, true, true, false, false),
CHANNEL_CATEGORY(4, false, false, true, true),
SERVER_NEWS_CHANNEL(5, true, false, true, true),
SERVER_STORE_CHANNEL(6, true, false, true, true),
SERVER_NEWS_THREAD(10, true, false, true, false),
SERVER_PUBLIC_THREAD(11, true, false, true, false),
SERVER_PRIVATE_THREAD(12, true, false, true, false),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.javacord.api.entity.channel;

public interface FollowedChannel {
/**
* Gets the channel id of the channel.
*
* @return The channel id of the channel.
*/
long getChannelId();

/**
* Gets the channel id of the channel as string.
*
* @return The channel id of the channel as string.
*/
default String getChannelIdAsString() {
try {
return Long.toUnsignedString(getChannelId());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("The given channel id is not a valid long value!", e);
}
}

/**
* Gets the targeted webhook id of the channel.
*
* @return The targeted webhook id of the channel.
*/
long getTargetedWebhookId();

/**
* Gets the targeted webhook id of the channel as string.
*
* @return The targeted webhook id of the channel as string.
*/
default String getTargetedWebhookIdAsString() {
try {
return Long.toUnsignedString(getTargetedWebhookId());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("The given channel id is not a valid long value!", e);
}
}
}
Loading