-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9ec786
commit b998829
Showing
12 changed files
with
380 additions
and
26 deletions.
There are no files selected for viewing
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
89 changes: 89 additions & 0 deletions
89
...n/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/OnboardingMode.kt
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,89 @@ | ||
// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! | ||
@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", | ||
"ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) | ||
|
||
package dev.kord.common.entity | ||
|
||
import kotlin.Any | ||
import kotlin.Boolean | ||
import kotlin.Int | ||
import kotlin.LazyThreadSafetyMode.PUBLICATION | ||
import kotlin.String | ||
import kotlin.Suppress | ||
import kotlin.collections.List | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
/** | ||
* Defines the criteria used to satisfy Onboarding constraints that are required for enabling. | ||
* | ||
* See [OnboardingMode]s in the | ||
* [Discord Developer Documentation](https://discord.com/developers/docs/resources/guild#guild-onboarding-object-onboarding-mode). | ||
*/ | ||
@Serializable(with = OnboardingMode.Serializer::class) | ||
public sealed class OnboardingMode( | ||
/** | ||
* The raw value used by Discord. | ||
*/ | ||
public val `value`: Int, | ||
) { | ||
public final override fun equals(other: Any?): Boolean = this === other || | ||
(other is OnboardingMode && this.value == other.value) | ||
|
||
public final override fun hashCode(): Int = value.hashCode() | ||
|
||
public final override fun toString(): String = | ||
"OnboardingMode.${this::class.simpleName}(value=$value)" | ||
|
||
/** | ||
* An unknown [OnboardingMode]. | ||
* | ||
* This is used as a fallback for [OnboardingMode]s that haven't been added to Kord yet. | ||
*/ | ||
public class Unknown( | ||
`value`: Int, | ||
) : OnboardingMode(value) | ||
|
||
/** | ||
* Counts only Default Channels towards constraints. | ||
*/ | ||
public object Default : OnboardingMode(0) | ||
|
||
/** | ||
* Counts Default Channels and Questions towards constraints. | ||
*/ | ||
public object Advanced : OnboardingMode(1) | ||
|
||
internal object Serializer : KSerializer<OnboardingMode> { | ||
public override val descriptor: SerialDescriptor = | ||
PrimitiveSerialDescriptor("dev.kord.common.entity.OnboardingMode", | ||
PrimitiveKind.INT) | ||
|
||
public override fun serialize(encoder: Encoder, `value`: OnboardingMode) = | ||
encoder.encodeInt(value.value) | ||
|
||
public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { | ||
0 -> Default | ||
1 -> Advanced | ||
else -> Unknown(value) | ||
} | ||
} | ||
|
||
public companion object { | ||
/** | ||
* A [List] of all known [OnboardingMode]s. | ||
*/ | ||
public val entries: List<OnboardingMode> by lazy(mode = PUBLICATION) { | ||
listOf( | ||
Default, | ||
Advanced, | ||
) | ||
} | ||
|
||
} | ||
} |
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
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
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
70 changes: 70 additions & 0 deletions
70
core/src/commonMain/kotlin/behavior/GuildOnboardingBehavior.kt
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,70 @@ | ||
package dev.kord.core.behavior | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.common.exception.RequestException | ||
import dev.kord.core.Kord | ||
import dev.kord.core.KordObject | ||
import dev.kord.core.entity.Guild | ||
import dev.kord.core.entity.GuildOnboarding | ||
import dev.kord.core.entity.Strategizable | ||
import dev.kord.core.exception.EntityNotFoundException | ||
import dev.kord.core.supplier.EntitySupplier | ||
import dev.kord.core.supplier.EntitySupplyStrategy | ||
import dev.kord.core.supplier.EntitySupplyStrategy.Companion.rest | ||
import dev.kord.rest.builder.guild.GuildOnboardingModifyBuilder | ||
import kotlin.contracts.InvocationKind | ||
import kotlin.contracts.contract | ||
|
||
public interface GuildOnboardingBehavior : KordObject, Strategizable { | ||
|
||
/** The ID of the [Guild] this onboarding is part of. */ | ||
public val guildId: Snowflake | ||
|
||
/** The behavior of the [Guild] this onboarding is part of. */ | ||
public val guild: GuildBehavior get() = GuildBehavior(guildId, kord) | ||
|
||
// todo docs | ||
public suspend fun asGuildOnboarding(): GuildOnboarding = kord.with(rest).getGuildOnboarding(guildId) | ||
|
||
// todo docs | ||
public suspend fun asGuildOnboardingOrNull(): GuildOnboarding? = kord.with(rest).getGuildOnboardingOrNull(guildId) | ||
|
||
/** | ||
* Requests the [Guild] this onboarding is part of. | ||
* | ||
* @throws RequestException if something went wrong while retrieving the guild. | ||
* @throws EntityNotFoundException if the guild is null. | ||
*/ | ||
public suspend fun getGuild(): Guild = supplier.getGuild(guildId) | ||
|
||
/** | ||
* Requests the [Guild] this onboarding is part of, returns `null` when the guild isn't present. | ||
* | ||
* @throws RequestException if something went wrong while retrieving the guild. | ||
*/ | ||
public suspend fun getGuildOrNull(): Guild? = supplier.getGuildOrNull(guildId) | ||
|
||
override fun withStrategy(strategy: EntitySupplyStrategy<*>): GuildOnboardingBehavior | ||
|
||
override fun toString(): String | ||
} | ||
|
||
// todo docs | ||
public suspend inline fun GuildOnboardingBehavior.edit( | ||
builder: GuildOnboardingModifyBuilder.() -> Unit, | ||
): GuildOnboarding { | ||
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } | ||
val onboarding = kord.rest.guild.modifyGuildOnboarding(guildId, builder) | ||
return GuildOnboarding(onboarding, kord) | ||
} | ||
|
||
internal class GuildOnboardingBehaviorImpl( | ||
override val guildId: Snowflake, | ||
override val kord: Kord, | ||
override val supplier: EntitySupplier = kord.defaultSupplier, | ||
) : GuildOnboardingBehavior { | ||
override fun withStrategy(strategy: EntitySupplyStrategy<*>) = | ||
GuildOnboardingBehaviorImpl(guildId, kord, strategy.supply(kord)) | ||
|
||
override fun toString() = "GuildOnboardingBehavior(guildId=$guildId, kord=$kord, supplier=$supplier)" | ||
} |
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
Oops, something went wrong.