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

Add missing fields to Guild #288

Merged
merged 3 commits into from
May 14, 2021
Merged
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
5 changes: 4 additions & 1 deletion common/src/main/kotlin/entity/DiscordGuild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ data class DiscordUnavailableGuild(
* @param approximateMemberCount The approximate number of members in this guild, returned from the `GET /guild/<id>` endpoint when `with_counts` is `true`.
* @param approximatePresenceCount The approximate number of non-offline members in this guild, returned from the `GET /guild/<id>` endpoint when `with_counts` is `true`.
* @param welcomeScreen The welcome screen of a Community guild, shown to new members.
* @param nsfw true if this guild is [designated as NSFW](https://support.discord.com/hc/en-us/articles/1500005389362-NSFW-Server-Designation)
*/
@Serializable
data class DiscordGuild(
Expand Down Expand Up @@ -150,7 +151,9 @@ data class DiscordGuild(
val approximateMemberCount: OptionalInt = OptionalInt.Missing,
@SerialName("approximate_presence_count")
val approximatePresenceCount: OptionalInt = OptionalInt.Missing,

@SerialName("welcome_screen")
val welcomeScreen: Optional<DiscordWelcomeScreen> = Optional.Missing(),
val nsfw: Boolean
)

/**
Expand Down
1 change: 1 addition & 0 deletions common/src/test/kotlin/json/GuildTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class GuildTest {
preferredLocale shouldBe "en-US"
rulesChannelId shouldBe "441688182833020939"
publicUpdatesChannelId shouldBe "281283303326089216"
nsfw shouldBe true
}

}
Expand Down
3 changes: 2 additions & 1 deletion common/src/test/resources/json/guild/guild.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"system_channel_flags": 0,
"preferred_locale": "en-US",
"rules_channel_id": "441688182833020939",
"public_updates_channel_id": "281283303326089216"
"public_updates_channel_id": "281283303326089216",
"nsfw": true
}
4 changes: 4 additions & 0 deletions core/src/main/kotlin/cache/data/GuildData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ data class GuildData(
val maxVideoChannelUsers: OptionalInt = OptionalInt.Missing,
val approximateMemberCount: OptionalInt = OptionalInt.Missing,
val approximatePresenceCount: OptionalInt = OptionalInt.Missing,
val welcomeScreen: Optional<WelcomeScreenData> = Optional.Missing(),
val nsfw: Boolean
) {
companion object {

Expand Down Expand Up @@ -113,6 +115,8 @@ data class GuildData(
maxVideoChannelUsers = maxVideoChannelUsers,
approximateMemberCount = approximateMemberCount,
approximatePresenceCount = approximatePresenceCount,
welcomeScreen = welcomeScreen.map { WelcomeScreenData.from(it) },
nsfw = nsfw
)
}
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/kotlin/entity/Guild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ class Guild(
*/
val maxVideoChannelUsers: Int? get() = data.maxVideoChannelUsers.value

/**
* The welcome screen of a Community guild, shown to new members, returned in an [Invite]'s guild object
*/
val welcomeScreen: WelcomeScreen? get() = data.welcomeScreen.unwrap { WelcomeScreen(it, kord) }

/**
* True if this guild is [designated as NSFW](https://support.discord.com/hc/en-us/articles/1500005389362-NSFW-Server-Designation)
*/
val nsfw: Boolean get() = data.nsfw

/**
* Requests to get the [VoiceChannel] represented by the [afkChannelId],
* returns null if the [afkChannelId] isn't present or the channel itself isn't present.
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/kotlin/performance/KordEventDropTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class KordEventDropTest {
rulesChannelId = null,
vanityUrlCode = null,
banner = null,
publicUpdatesChannelId = null
publicUpdatesChannelId = null,
nsfw = false
), 0)

val counter = AtomicInteger(0)
Expand Down