Skip to content

Commit

Permalink
Add missing properties for channel builders (#712)
Browse files Browse the repository at this point in the history
* Add missing properties for create forum channel

* api dump

* add missing fields in the other builders

* api dump

* move flags to forum threads

* apply suggestions

* Small fixes

Co-authored-by: Lukellmann <[email protected]>
  • Loading branch information
luisfbl and lukellmann authored Nov 16, 2022
1 parent 0d2cdb5 commit 329592d
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 11 deletions.
70 changes: 60 additions & 10 deletions rest/api/rest.api

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions rest/src/main/kotlin/builder/channel/EditGuildChannelBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package dev.kord.rest.builder.channel

import dev.kord.common.annotation.KordDsl
import dev.kord.common.entity.ArchiveDuration
import dev.kord.common.entity.ChannelFlags
import dev.kord.common.entity.DiscordDefaultReaction
import dev.kord.common.entity.DiscordForumTag
import dev.kord.common.entity.Overwrite
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.SortOrderType
import dev.kord.common.entity.VideoQualityMode
import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.common.entity.optional.OptionalInt
import dev.kord.common.entity.optional.OptionalSnowflake
import dev.kord.common.entity.optional.delegate.delegate
import dev.kord.common.entity.optional.optional
import dev.kord.rest.builder.AuditRequestBuilder
import dev.kord.rest.json.request.ChannelModifyPatchRequest
import kotlin.DeprecationLevel.HIDDEN
Expand Down Expand Up @@ -96,6 +101,23 @@ public class ForumChannelModifyBuilder : PermissionOverwritesModifyBuilder,
*/
public var defaultAutoArchiveDuration: ArchiveDuration? by ::_defaultAutoArchiveDuration.delegate()

private var _flags: Optional<ChannelFlags> = Optional.Missing()
public var flags: ChannelFlags? by ::_flags.delegate()

private var _defaultReactionEmoji: Optional<DiscordDefaultReaction?> = Optional.Missing()
public var defaultReactionEmoji: DiscordDefaultReaction? by ::_defaultReactionEmoji.delegate()
public var defaultReactionEmojiId: Snowflake? = null
public var defaultReactionEmojiName: String? = null

private var _availableTags: Optional<List<DiscordForumTag>> = Optional.Missing()
public var availableTags: List<DiscordForumTag>? by ::_availableTags.delegate()

private var _defaultThreadRateLimitPerUser: Optional<Duration> = Optional.Missing()
public var defaultThreadRateLimitPerUser: Duration? by ::_defaultThreadRateLimitPerUser.delegate()

private var _defaultSortOrder: Optional<SortOrderType?> = Optional.Missing()
public var defaultSortOrder: SortOrderType? by ::_defaultSortOrder.delegate()

override fun toRequest(): ChannelModifyPatchRequest = ChannelModifyPatchRequest(
name = _name,
position = _position,
Expand All @@ -105,6 +127,18 @@ public class ForumChannelModifyBuilder : PermissionOverwritesModifyBuilder,
permissionOverwrites = _permissionOverwrites,
parentId = _parentId,
defaultAutoArchiveDuration = _defaultAutoArchiveDuration,
defaultReactionEmoji = when {
defaultReactionEmojiId != null || defaultReactionEmojiName != null ->
DiscordDefaultReaction(
emojiId = defaultReactionEmojiId,
emojiName = defaultReactionEmojiName,
).optional()
else -> _defaultReactionEmoji
},
defaultThreadRateLimitPerUser = _defaultThreadRateLimitPerUser,
availableTags = _availableTags,
defaultSortOrder = _defaultSortOrder,
flags = _flags
)

}
Expand Down
29 changes: 29 additions & 0 deletions rest/src/main/kotlin/builder/channel/ForumChannelCreateBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package dev.kord.rest.builder.channel
import dev.kord.common.annotation.KordDsl
import dev.kord.common.entity.ArchiveDuration
import dev.kord.common.entity.ChannelType
import dev.kord.common.entity.DiscordDefaultReaction
import dev.kord.common.entity.DiscordForumTag
import dev.kord.common.entity.Overwrite
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.SortOrderType
import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.common.entity.optional.OptionalInt
import dev.kord.common.entity.optional.OptionalSnowflake
import dev.kord.common.entity.optional.delegate.delegate
import dev.kord.common.entity.optional.optional
import dev.kord.rest.builder.AuditRequestBuilder
import dev.kord.rest.json.request.GuildChannelCreateRequest
import kotlin.time.Duration
Expand Down Expand Up @@ -45,6 +49,20 @@ public class ForumChannelCreateBuilder(public var name: String) :

override var permissionOverwrites: MutableSet<Overwrite> = mutableSetOf()

private var _defaultReactionEmoji: Optional<DiscordDefaultReaction?> = Optional.Missing()
public var defaultReactionEmoji: DiscordDefaultReaction? by ::_defaultReactionEmoji.delegate()
public var defaultReactionEmojiId: Snowflake? = null
public var defaultReactionEmojiName: String? = null

private var _availableTags: Optional<List<DiscordForumTag>?> = Optional.Missing()
public var availableTags: List<DiscordForumTag>? by ::_availableTags.delegate()

private var _defaultThreadRateLimitPerUser: Optional<Duration> = Optional.Missing()
public var defaultThreadRateLimitPerUser: Duration? by ::_defaultThreadRateLimitPerUser.delegate()

private var _defaultSortOrder: Optional<SortOrderType?> = Optional.Missing()
public var defaultSortOrder: SortOrderType? by ::_defaultSortOrder.delegate()

override fun toRequest(): GuildChannelCreateRequest = GuildChannelCreateRequest(
name = name,
type = ChannelType.GuildForum,
Expand All @@ -55,5 +73,16 @@ public class ForumChannelCreateBuilder(public var name: String) :
nsfw = _nsfw,
permissionOverwrite = Optional.missingOnEmpty(permissionOverwrites),
defaultAutoArchiveDuration = _defaultAutoArchiveDuration,
defaultReactionEmoji = when {
defaultReactionEmojiId != null || defaultReactionEmojiName != null ->
DiscordDefaultReaction(
emojiId = defaultReactionEmojiId,
emojiName = defaultReactionEmojiName,
).optional()
else -> _defaultReactionEmoji
},
defaultThreadRateLimitPerUser = _defaultThreadRateLimitPerUser,
availableTags = _availableTags,
defaultSortOrder = _defaultSortOrder,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class TextChannelCreateBuilder(public var name: String) :

override var permissionOverwrites: MutableSet<Overwrite> = mutableSetOf()

private var _defaultThreadRateLimitPerUser: Optional<Duration> = Optional.Missing()
public var defaultThreadRateLimitPerUser: Duration? by ::_defaultThreadRateLimitPerUser.delegate()

override fun toRequest(): GuildChannelCreateRequest = GuildChannelCreateRequest(
name = name,
type = ChannelType.GuildText,
Expand All @@ -55,5 +58,6 @@ public class TextChannelCreateBuilder(public var name: String) :
nsfw = _nsfw,
permissionOverwrite = Optional.missingOnEmpty(permissionOverwrites),
defaultAutoArchiveDuration = _defaultAutoArchiveDuration,
defaultThreadRateLimitPerUser = _defaultThreadRateLimitPerUser
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.kord.rest.builder.channel.thread

import dev.kord.common.entity.ArchiveDuration
import dev.kord.common.entity.ChannelFlags
import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.common.entity.optional.delegate.delegate
Expand Down Expand Up @@ -28,14 +29,18 @@ public class ThreadModifyBuilder : AuditRequestBuilder<ChannelModifyPatchRequest
private var _invitable: OptionalBoolean = OptionalBoolean.Missing
public var invitable: Boolean? by ::_invitable.delegate()

private var _flags: Optional<ChannelFlags> = Optional.Missing()
public var flags: ChannelFlags? by ::_flags.delegate()

override fun toRequest(): ChannelModifyPatchRequest {
return ChannelModifyPatchRequest(
name = _name,
locked = _locked,
archived = _archived,
autoArchiveDuration = _autoArchiveDuration,
rateLimitPerUser = _rateLimitPerUser,
invitable = _invitable
invitable = _invitable,
flags = _flags
)
}

Expand Down
9 changes: 9 additions & 0 deletions rest/src/main/kotlin/json/request/ChannelRequests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public data class ChannelModifyPatchRequest(
val videoQualityMode: Optional<VideoQualityMode?> = Optional.Missing(),
@SerialName("default_auto_archive_duration")
val defaultAutoArchiveDuration: Optional<ArchiveDuration?> = Optional.Missing(),
@SerialName("default_reaction_emoji")
val defaultReactionEmoji: Optional<DiscordDefaultReaction?> = Optional.Missing(),
@SerialName("default_thread_rate_limit_per_user")
val defaultThreadRateLimitPerUser: Optional<DurationInSeconds> = Optional.Missing(),
val flags: Optional<ChannelFlags> = Optional.Missing(),
@SerialName("available_tags")
val availableTags: Optional<List<DiscordForumTag>> = Optional.Missing(),
@SerialName("default_sort_order")
val defaultSortOrder: Optional<SortOrderType?> = Optional.Missing(),
)

@Serializable
Expand Down
9 changes: 9 additions & 0 deletions rest/src/main/kotlin/json/request/GuildRequests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public data class GuildChannelCreateRequest(
val id: OptionalSnowflake = OptionalSnowflake.Missing,
@SerialName("default_auto_archive_duration")
val defaultAutoArchiveDuration: Optional<ArchiveDuration> = Optional.Missing(),
@SerialName("default_reaction_emoji")
val defaultReactionEmoji: Optional<DiscordDefaultReaction?> = Optional.Missing(),
@SerialName("default_thread_rate_limit_per_user")
val defaultThreadRateLimitPerUser: Optional<DurationInSeconds> = Optional.Missing(),
val flags: Optional<ChannelFlags> = Optional.Missing(),
@SerialName("available_tags")
val availableTags: Optional<List<DiscordForumTag>?> = Optional.Missing(),
@SerialName("default_sort_order")
val defaultSortOrder: Optional<SortOrderType?> = Optional.Missing(),
)

@Serializable
Expand Down

0 comments on commit 329592d

Please sign in to comment.