Skip to content

Commit

Permalink
Added news channel
Browse files Browse the repository at this point in the history
added follow Channel method to news channel

Removed channel type SERVER_STORE_CHANNEL as it was removed by discord a long time ago

ServerTextChannel now extends ServerMessageChannel and so does NewsChannel
This is because everything apart from slow mode is the same. Slowmode is in the interface ServerTextChannel
  • Loading branch information
RealYusufIsmail committed Oct 25, 2022
1 parent 175a625 commit 8423346
Show file tree
Hide file tree
Showing 51 changed files with 1,606 additions and 784 deletions.
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 @@ -78,6 +78,15 @@ default Optional<ServerTextChannel> asServerTextChannel() {
return as(ServerTextChannel.class);
}

/**
* 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 server forum 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

0 comments on commit 8423346

Please sign in to comment.