-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get channel definitions from existing channels
- Loading branch information
1 parent
6640f2b
commit 4798f51
Showing
15 changed files
with
562 additions
and
1 deletion.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/AnnouncementChannelDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/CategoryDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/ChannelDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/DefaultReaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/ForumChannelDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/MediaChannelDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/Overwrite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/Snowflake.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/StageChannelDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/TextChannelDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
terra/src/main/java/dev/jacksonbailey/wheel/terra/model/VideoQualityMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package dev.jacksonbailey.wheel.terra.model; | ||
|
||
public enum VideoQualityMode { | ||
} |
Oops, something went wrong.