Skip to content

Commit

Permalink
Get channel definitions from existing channels
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonBailey committed Jul 1, 2024
1 parent 6640f2b commit 4798f51
Show file tree
Hide file tree
Showing 15 changed files with 562 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dev.jacksonbailey.wheel.terra.model;

import java.util.List;
import java.util.Optional;
import lombok.Builder;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.NewsChannel;

/**
* These used to be called News Channels in the Discord API and still are in JDA.
*/
@Builder(toBuilder = true)
public record AnnouncementChannelDefinition(
String name,
ChannelType type,
String topic,
Integer position,
List<Overwrite> permissionOverwrites,
String parent,
Boolean nsfw,
Integer defaultAutoArchiveDuration,
Integer defaultThreadRateLimitPerUser
) implements ChannelDefinition {

public AnnouncementChannelDefinition {
if (!ChannelType.NEWS.equals(type)) {
throw new IllegalArgumentException("Expected NEWS (Announcement), got " + type.name());
}
}

public static AnnouncementChannelDefinition from(NewsChannel newsChannel) {
return AnnouncementChannelDefinition
.builder()
.name(newsChannel.getName())
.type(newsChannel.getType())
.topic(newsChannel.getTopic())
.position(newsChannel.getPosition())
.permissionOverwrites(null) // TODO Too lazy right now
.parent(
Optional.ofNullable(newsChannel.getParentCategory())
.map(Channel::getName)
.orElse(null)
)
.nsfw(newsChannel.isNSFW())
.defaultAutoArchiveDuration(null) // TODO Where is this?
.defaultThreadRateLimitPerUser(newsChannel.getDefaultThreadSlowmode()) // TODO Right field?
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.jacksonbailey.wheel.terra.model;

import java.util.List;
import lombok.Builder;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.Category;

@Builder(toBuilder = true)
public record CategoryDefinition(
String name,
ChannelType type,
Integer position,
List<Overwrite> permissionOverwrites
) implements ChannelDefinition {

public CategoryDefinition {
if (!ChannelType.CATEGORY.equals(type)) {
throw new IllegalArgumentException("Expected CATEGORY, got " + type.name());
}
}

public static CategoryDefinition from(Category category) {
return CategoryDefinition
.builder()
.name(category.getName())
.type(category.getType())
.position(category.getPosition())
.permissionOverwrites(null) // TODO Too lazy right now
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.jacksonbailey.wheel.terra.model;

import java.util.List;
import net.dv8tion.jda.api.entities.channel.ChannelType;

public interface ChannelDefinition {

String name();

ChannelType type();

Integer position();

List<Overwrite> permissionOverwrites();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.jacksonbailey.wheel.terra.model;

import lombok.Builder;

@Builder(toBuilder = true)
public record DefaultReaction(Snowflake emojiId, String emojiName) {

public DefaultReaction {
if ((emojiId == null) == (emojiName == null)) {
throw new IllegalArgumentException("Exactly one of the fields must be null");
}
}

public DefaultReaction(Snowflake emojiId) {
this(emojiId, null);
}

public DefaultReaction(String emojiName) {
this(null, emojiName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package dev.jacksonbailey.wheel.terra.model;

import java.util.List;
import java.util.Optional;
import lombok.Builder;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.attribute.IPostContainer.SortOrder;
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel.Layout;

@Builder(toBuilder = true)
public record ForumChannelDefinition(
String name,
ChannelType type,
String topic,
Integer rateLimitPerUser,
Integer position,
List<Overwrite> permissionOverwrites,
String parent,
Boolean nsfw,
Integer defaultAutoArchiveDuration,
DefaultReaction defaultReactionEmoji,
List<Object> availableTags, // TODO Tag type
SortOrder defaultSortOrder,
Layout defaultForumLayout,
Integer defaultThreadRateLimitPerUser
) implements ChannelDefinition {

public ForumChannelDefinition {
if (!ChannelType.FORUM.equals(type)) {
throw new IllegalArgumentException("Expected FORUM, got " + type.name());
}
}

public static ForumChannelDefinition from(ForumChannel forumChannel) {
return ForumChannelDefinition
.builder()
.name(forumChannel.getName())
.type(forumChannel.getType())
.topic(forumChannel.getTopic())
.rateLimitPerUser(null) // TODO Where is this?
.position(forumChannel.getPosition())
.permissionOverwrites(null) // TODO Too lazy right now
.parent(
Optional.ofNullable(forumChannel.getParentCategory())
.map(Channel::getName)
.orElse(null)
)
.nsfw(forumChannel.isNSFW())
.defaultAutoArchiveDuration(null) // TODO Where is this?
.defaultReactionEmoji(null) // TODO Too lazy right now
.availableTags(null) // TODO Too lazy right now
.defaultSortOrder(forumChannel.getDefaultSortOrder())
.defaultForumLayout(forumChannel.getDefaultLayout())
.defaultThreadRateLimitPerUser(forumChannel.getDefaultThreadSlowmode()) // TODO Right field?
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package dev.jacksonbailey.wheel.terra.model;

import java.util.List;
import lombok.Builder;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.attribute.IPostContainer.SortOrder;
import net.dv8tion.jda.api.entities.channel.concrete.MediaChannel;

// TODO Verify this really does not have nsfw field
@Builder(toBuilder = true)
public record MediaChannelDefinition(
String name,
ChannelType type,
String topic,
Integer rateLimitPerUser,
Integer position,
List<Overwrite> permissionOverwrites,
String parent,
Integer defaultAutoArchiveDuration,
DefaultReaction defaultReactionEmoji,
List<Object> availableTags, // TODO Tag type
SortOrder defaultSortOrder,
Integer defaultThreadRateLimitPerUser
) implements ChannelDefinition {

public MediaChannelDefinition {
if (!ChannelType.MEDIA.equals(type)) {
throw new IllegalArgumentException("Expected MEDIA, got " + type.name());
}
}

public static MediaChannelDefinition from(MediaChannel mediaChannel) {
return MediaChannelDefinition
.builder()
.name(mediaChannel.getName())
.type(mediaChannel.getType())
.topic(mediaChannel.getTopic())
.rateLimitPerUser(null) // TODO Where is this?
.position(mediaChannel.getPosition())
.permissionOverwrites(null) // TODO Too lazy right now
.defaultReactionEmoji(null) // TODO Too lazy right now
.availableTags(null) // TODO Too lazy right now
.defaultSortOrder(mediaChannel.getDefaultSortOrder())
.defaultThreadRateLimitPerUser(mediaChannel.getDefaultThreadSlowmode()) // TODO Right field?
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.jacksonbailey.wheel.terra.model;


// TODO Implement
public class Overwrite {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.jacksonbailey.wheel.terra.model;

/**
* <a href="https://discord.com/developers/docs/reference#snowflakes">Discord Snowflake docs</a>.
*/
// JDA does not provide anything to merely store the Snowflake ID.
public record Snowflake(long bits) {

// TODO Consider implementing a way to get the timestamp?

public static Snowflake of(String s) {
return new Snowflake(Long.parseUnsignedLong(s));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package dev.jacksonbailey.wheel.terra.model;

import java.util.List;
import java.util.Optional;
import lombok.Builder;
import net.dv8tion.jda.api.Region;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.StageChannel;

@Builder(toBuilder = true)
public record StageChannelDefinition(
String name,
ChannelType type,
Integer bitrate,
Integer userLimit,
Integer rateLimitPerUser,
Integer position,
List<Overwrite> permissionOverwrites,
String parent,
Boolean nsfw,
Region rtcRegion,
Object videoQualityMode
) implements ChannelDefinition {

public StageChannelDefinition {
if (!ChannelType.STAGE.equals(type)) {
throw new IllegalArgumentException("Expected STAGE, got " + type.name());
}
}

public static StageChannelDefinition from(StageChannel stageChannel) {
return StageChannelDefinition
.builder()
.name(stageChannel.getName())
.type(stageChannel.getType())
.bitrate(stageChannel.getBitrate())
.userLimit(stageChannel.getUserLimit())
.rateLimitPerUser(null) // TODO Where is this?
.position(stageChannel.getPosition())
.permissionOverwrites(null) // TODO Too lazy right now
.parent(
Optional.ofNullable(stageChannel.getParentCategory())
.map(Channel::getName)
.orElse(null)
)
.nsfw(stageChannel.isNSFW())
.rtcRegion(stageChannel.getRegion())
.videoQualityMode(null) // TODO Where is this?
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package dev.jacksonbailey.wheel.terra.model;

import java.util.List;
import java.util.Optional;
import lombok.Builder;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;

@Builder(toBuilder = true)
public record TextChannelDefinition(
String name,
ChannelType type,
String topic,
Integer rateLimitPerUser,
Integer position,
List<Overwrite> permissionOverwrites,
String parent,
Boolean nsfw,
Integer defaultAutoArchiveDuration,
Integer defaultThreadRateLimitPerUser
) implements ChannelDefinition {

public TextChannelDefinition {
if (!ChannelType.TEXT.equals(type)) {
throw new IllegalArgumentException("Expected TEXT, got " + type.name());
}
}

public static TextChannelDefinition from(TextChannel textChannel) {
return TextChannelDefinition
.builder()
.name(textChannel.getName())
.type(textChannel.getType())
.topic(textChannel.getTopic())
.rateLimitPerUser(null) // TODO Where is this?
.position(textChannel.getPosition())
.permissionOverwrites(null) // TODO Too lazy right now
.parent(
Optional.ofNullable(textChannel.getParentCategory())
.map(Channel::getName)
.orElse(null)
)
.nsfw(textChannel.isNSFW())
.defaultAutoArchiveDuration(null) // TODO Where?
.defaultThreadRateLimitPerUser(textChannel.getDefaultThreadSlowmode())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dev.jacksonbailey.wheel.terra.model;

public enum VideoQualityMode {
}
Loading

0 comments on commit 4798f51

Please sign in to comment.